From 6f26b59db17b4618c537e62c84f91cf5f17f93bf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 Mar 2021 16:44:06 +0100 Subject: [PATCH] Bug 5697: Consolidate nodes construction and fix translation issue The way the buttons were created was not nice as it was a full HTML node built with a JS string, on a single line. I first tried to split the line and then realized but could put in a function and reuse. Then noticed that the button's text was not translatable. I ended up with this patch. I don't know if it's more readable, but at least it seems a bit more robust and maintainable in the long term. --- .../modules/reports/guided_reports_start.tt | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index edae45d55a..a014088dc8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -1869,6 +1869,58 @@ $("#limitselect").submit(); }); + function build_record_links(data, column_type){ + var node = $(''); + $(node).append('' + data + ' '); + var ul = $(''); + + var buttons = []; + if ( column_type == 'biblionumber' ) { + buttons.push({ href: '/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + data, + type:'view', + text: _("View record") }); + buttons.push({ href: '/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=' + data, + type: 'edit', + text: _("Edit record") }); + } else if ( column_type == 'itemnumber' ) { + buttons.push({ href: '/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=' + data, + type: 'view', + text: _("View item") }); + buttons.push({ href: '/cgi-bin/koha/cataloguing/additem.pl?op=edititem&itemnumber=' + data + '#edititem', + type: 'edit', + text: _("Edit item") }); + } else if ( column_type == 'borrowernumber' ) { + buttons.push({ href: '/cgi-bin/koha/members/moremember.pl?borrowernumber=' + data, + type: 'view', + text: _("View patron") }); + buttons.push({ href: '/cgi-bin/koha/members/memberentry.pl?borrowernumber=' + data, + type: 'edit', + text: _("Edit patron") }); + buttons.push({ href: '/cgi-bin/koha/circ/circulation.pl?borrowernumber=' + data, + type: 'checkout', + text: _("Check out") }); + } else if ( column_type == 'cardnumber' ) { + buttons.push({ href: '/cgi-bin/koha/circ/circulation.pl?borrowernumber=' + data, + type: 'checkout', + text: _("Check out") }); + } + var need_sep = 0; + while ( (b = buttons.pop()) != null ) { + if ( need_sep ) { + $(ul).append(''); + } + var icon; + if (b['type'] == 'view') icon = 'fa fa-window-restore'; + else if (b['type'] == 'edit') icon = 'fa fa-pencil'; + else if (b['type'] == 'checkout') icon = 'fa fa-window-restore'; + $(ul).append('
  • ' + b['text'] + '
  • ') + need_sep = 1; + } + + $(node).append(ul); + return $(node)[0].outerHTML; + } + if( $("#report_results").length > 0 ){ $("#report_results").dataTable($.extend(true, {}, dataTablesDefaults, { "dom": 't', @@ -1878,25 +1930,25 @@ { targets: "biblionumber", render: function ( data ) { - return '' + data + ''; + return '' + data + '' + build_record_links(data, 'biblionumber'); } }, { targets: "itemnumber", render: function ( data ) { - return '' + data + ''; + return '' + data + '' + build_record_links(data, 'itemnumber'); } }, { targets: "borrowernumber", render: function ( data ) { - return '' + data + ''; + return '' + data + '' + build_record_links(data, 'borrowernumber'); } }, { targets: "cardnumber", render: function ( data ) { - return '' + data + ''; + return '' + data + '' + build_record_links(data, 'cardnumber'); } }, ] -- 2.20.1