From d4771f4340866023c017c06bd7860b8c6d77cbd9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 24 Apr 2025 10:02:58 -0300 Subject: [PATCH] Bug 39600: Adapt template and use kohaTable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch makes changes to the table introduced in the original patch: * It gets rendered using `kohaTable` instead of manually crafting the datatable * Embeds are parameters for `kohaTable` thus no need to build the headers manually * A default render method is introduced, which HTML-escapes the data for safety, and also deals with `null` values which could cause problems. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Tadeusz „tadzik” Sośnierz Signed-off-by: Martin Renvoize --- .../bootstrap/en/modules/opac-illrequests.tt | 66 +++++-------------- 1 file changed, 18 insertions(+), 48 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt index 0c0c2b906de..6067cb2e2f3 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt @@ -372,14 +372,24 @@ return status_label; } - $("#illrequestlist").dataTable($.extend(true, {}, dataTablesDefaults, { + $("#illrequestlist").kohaTable({ + order: [[ 0, "desc" ]], + dom: '<"dt-info"i><"top pager"<"table_entries"lp>>tr<"bottom pager"ip>', + paging: true, + embed: ['+strings','extended_attributes'], + ajax: { url: '/api/v1/public/patrons/[% logged_in_user.borrowernumber | uri %]/ill/requests' }, + columnDefs: [ { + render: function (data, type, row, meta) { + if ( data && type == 'display' ) { + return data.escapeHtml(); + } + return data; + } + } ], columns: [ { data: 'ill_request_id', - sortable: true, - render: (data, type, row, meta) => { - return data; - }, + sortable: true }, { data: 'author', @@ -397,10 +407,7 @@ }, { data: 'ill_backend_id', - sortable: true, - render: (data, type, row, meta) => { - return escape_str(data); - }, + sortable: true }, { data: 'type', @@ -437,45 +444,8 @@ return `View`; }, } - ], - "order": [[ 0, "desc" ]], - "dom": '<"dt-info"i><"top pager"<"table_entries"lp>>tr<"bottom pager"ip>', - "paging": true, - "serverSide": true, - "ajax": { - "cache": true, - "url": '/api/v1/patrons/[% logged_in_user.borrowernumber | html %]/ill/requests', - 'beforeSend': function (xhr, settings) { - this._xhr = xhr; - xhr.setRequestHeader('x-koha-embed', '+strings,extended_attributes'); - }, - "data": (data, settings) => { - const order = data.order[0]; - const order_by = (order.dir == 'asc' ? '+' : '-') + 'me.' + data.columns[order.column].data; - const page = Math.floor(data.start / data.length) + 1; - return { - _page: page, - _per_page: data.length, - _order_by: order_by, - }; - }, - 'dataFilter': function (data, type) { - const json = {data: JSON.parse(data)}; - if (total = this._xhr.getResponseHeader('x-total-count')) { - json.recordsTotal = total; - json.recordsFiltered = total; - } - if (total = this._xhr.getResponseHeader('x-base-total-count')) { - json.recordsTotal = total; - } - if (draw = this._xhr.getResponseHeader('x-koha-request-id')) { - json.draw = draw; - } - - return JSON.stringify(json); - }, - }, - })); + ] + }); $("#backend-dropdown-options").removeClass("nojs"); [% IF services_json.length > 0 %] var services = [% services_json | $raw %]; -- 2.49.0