gnucash stable: [new-owner-report] Scope script to its table, use keyboard toggle
Christopher Lam
clam at code.gnucash.org
Tue Sep 15 17:45:56 EDT 2026
Updated via https://github.com/Gnucash/gnucash/commit/38754227 (commit)
from https://github.com/Gnucash/gnucash/commit/038f90a7 (commit)
commit 38754227f356c4c303f6d215d47e0c5deb6bb45e
Author: Claude <noreply at anthropic.com>
Date: Sat Sep 12 00:08:26 2026 +0000
[new-owner-report] Scope script to its table, use keyboard toggle
Wrap in IIFE to prevent script variables interfering with other owner
reports in multi-report scenarios. Target current report table, marked
with gensym.
Add keyboard support: Space on a focused cell (e.g. link to invoice or
register) toggles the highlight. Enter on a focused cell still opens
the invoice or register.
Wrap the script in //<![CDATA[ ... //]]> avoiding need for escaping
&&.
Assisted-By: Claude Sonnet 5 <noreply at anthropic.com>
Signed-Off: Christopher Lam
diff --git a/gnucash/report/reports/standard/new-owner-report.scm b/gnucash/report/reports/standard/new-owner-report.scm
index 420ea2bee7..48cd0bcf45 100644
--- a/gnucash/report/reports/standard/new-owner-report.scm
+++ b/gnucash/report/reports/standard/new-owner-report.scm
@@ -60,27 +60,48 @@
(define doclink-header (N_ "Document Links"))
(define linked-txns-header (N_ "Transaction Links"))
-(define javascript "
+(define (make-javascript table-id)
+ (string-append "
<script>
- function getID(cell) { return cell.getAttribute('link-id'); }
-
- function clicky() {
- var id = getID(this);
- var ishighlighted = this.classList.contains('highlight');
- TDs.forEach (function (item, idx) {
- item.classList.remove('highlight')});
- if (ishighlighted) return;
- TDs.forEach (function (item, idx) {
- if (getID(item) == id)
- item.classList.add('highlight')})}
-
- var TDs = document.getElementsByTagName('td');
- TDs = Array.prototype.slice.call (TDs);
- TDs = TDs.filter (getID);
- TDs.forEach(function (item, idx) {
- item.addEventListener('click', clicky)});
+//<![CDATA[
+(function () {
+ var table = document.getElementById('" table-id "');
+ if (!table) return;
+
+ var linkedCells = Array.prototype.filter.call(table.getElementsByTagName('td'),
+ function (cell) { return cell.hasAttribute('link-id'); });
+
+ function toggleHighlight(cell)
+ {
+ var id = cell.getAttribute('link-id');
+ var noHighlight = !cell.classList.contains('highlight');
+ linkedCells.forEach(function (item)
+ {
+ if (noHighlight && item.getAttribute('link-id') === id)
+ item.classList.add('highlight');
+ else
+ item.classList.remove('highlight');
+ });
+ }
+
+ table.addEventListener('click', function (event)
+ {
+ var cell = event.target.closest('td[link-id]');
+ if (cell && table.contains(cell)) toggleHighlight(cell);
+ });
+
+ table.addEventListener('keydown', function (event)
+ {
+ if (event.key !== ' ') return;
+ var cell = event.target.closest('td[link-id]');
+ if (!cell || !table.contains(cell)) return;
+ event.preventDefault();
+ toggleHighlight(cell);
+ });
+})();
+//]]>
</script>
-")
+"))
;; Depending on the report type we want to set up some lists/cases
;; with strings to ease overview and translation
@@ -464,7 +485,7 @@
(link-data->cols (car link-rows))))
(lp (cdr link-rows) #f))))
-(define (add-owner-table table splits acc start-date end-date date-type
+(define (add-owner-table table table-id splits acc start-date end-date date-type
used-columns payable? link-option)
(define (AP-negate num)
(if payable? (- num) num))
@@ -748,6 +769,7 @@ and do not match the transaction."))))))))
(print-totals total debit credit tax sale invalid-splits)
(gnc:html-table-set-style!
table "table"
+ 'attribute (list "id" table-id)
'attribute (list "border" 1)
'attribute (list "cellspacing" 0)
'attribute (list "cellpadding" 4))
@@ -1045,6 +1067,7 @@ and do not match the transaction."))))))))
(query (qof-query-create-for-splits))
(document (gnc:make-html-document))
(table (gnc:make-html-table))
+ (table-id (symbol->string (gensym "owner-report-table-")))
(section-headings (make-section-heading-list used-columns owner-descr))
(headings (make-heading-list used-columns link-option))
(report-title (string-append (G_ owner-descr) " " (G_ "Report"))))
@@ -1117,7 +1140,7 @@ and do not match the transaction."))))))))
(string-append (G_ "Account") ": "
(xaccAccountGetName account)))))))
- (add-owner-table table splits account start-date end-date
+ (add-owner-table table table-id splits account start-date end-date
date-type used-columns payable? link-option)))
accounts-and-splits))
@@ -1160,7 +1183,7 @@ and do not match the transaction."))))))))
(gnc:html-document-add-object! document table)
- (gnc:html-document-add-object! document javascript))))))
+ (gnc:html-document-add-object! document (make-javascript table-id)))))))
document))
Summary of changes:
.../report/reports/standard/new-owner-report.scm | 67 +++++++++++++++-------
1 file changed, 45 insertions(+), 22 deletions(-)
More information about the gnucash-changes
mailing list