Bugzilla – Attachment 173476 Details for
Bug 33484
Ability to remember user's selected table configuration and search filters for tables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33484: Store external filters into state
Bug-33484-Store-external-filters-into-state.patch (text/plain), 3.82 KB, created by
Jonathan Druart
on 2024-10-28 09:46:19 UTC
(
hide
)
Description:
Bug 33484: Store external filters into state
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-10-28 09:46:19 UTC
Size:
3.82 KB
patch
obsolete
>From 3760f80b645efb77d9e8f78b061e5946fd72fb87 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 17 Oct 2024 12:59:58 +0200 >Subject: [PATCH] Bug 33484: Store external filters into state > >Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > koha-tmpl/intranet-tmpl/prog/js/datatables.js | 40 ++++++++++++++++--- > 1 file changed, 35 insertions(+), 5 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >index 5a791a0fc93..8cfb3567390 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js >@@ -961,7 +961,7 @@ function _dt_add_delay(table_dt, table_node, delay_ms) { > }); > } > >-function _dt_save_restore_state(table_settings){ >+function _dt_save_restore_state(table_settings, external_filter_nodes={}){ > > let table_key = 'DataTables_%s_%s_%s'.format( > table_settings.module, >@@ -984,7 +984,6 @@ function _dt_save_restore_state(table_settings){ > return { columns, time: new Date() }; > } > let stateLoadCallback = function(settings) { >- > // Load state from URL > const url = new URL(window.location.href); > let state_from_url = url.searchParams.get( table_key + '_state'); >@@ -1008,7 +1007,38 @@ function _dt_save_restore_state(table_settings){ > return state; > } > >- return {stateSave: true, stateSaveCallback, stateLoadCallback}; >+ let stateSaveParams = function (settings, data) { >+ // FIXME Selector in on the whole DOM, we don't know where the filters are >+ // If others exist on the same page this will lead to unexpected behaviours >+ // Should be safe so far as: patron search use the same code for the different searches >+ // but only the main one has the table settings (and so the state saved) >+ data.external_filters = Object.keys(external_filter_nodes).reduce( >+ (r, k) => { >+ r[k] = $(external_filter_nodes[k]).val(); >+ return r; >+ }, >+ {} >+ ); >+ }; >+ let stateLoadParams = function (settings, data) { >+ if (!settings.loaded_from_state) return; >+ >+ if (data.external_filters) { >+ Object.keys(external_filter_nodes).forEach((k, i) => { >+ if (data.external_filters.hasOwnProperty(k)) { >+ $(external_filter_nodes[k]).val(data.external_filters[k]); >+ } >+ }); >+ } >+ }; >+ >+ return { >+ stateSave: true, >+ stateSaveCallback, >+ stateLoadCallback, >+ stateSaveParams, >+ stateLoadParams, >+ }; > } > > (function($) { >@@ -1028,7 +1058,7 @@ function _dt_save_restore_state(table_settings){ > * @param {Object} default_filters Add a set of default search filters to apply at table initialisation > * @return {Object} The dataTables instance > */ >- $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options) { >+ $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, external_filter_nodes) { > var settings = null; > > if(options) { >@@ -1066,7 +1096,7 @@ function _dt_save_restore_state(table_settings){ > } > > if ( table_settings ) { >- let state_settings = _dt_save_restore_state(table_settings); >+ let state_settings = _dt_save_restore_state(table_settings, external_filter_nodes); > settings = {...settings, ...state_settings}; > > if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) { >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33484
:
149444
|
149445
|
149447
|
149448
|
149449
|
149925
|
149926
|
149927
|
149928
|
149929
|
149930
|
149974
|
149975
|
149976
|
149977
|
149978
|
149979
|
173443
|
173444
|
173445
|
173446
|
173447
|
173448
|
173449
|
173450
|
173451
|
173452
|
173453
|
173454
|
173455
|
173456
|
173457
|
173458
|
173459
|
173460
|
173461
|
173462
|
173463
|
173464
|
173465
|
173466
|
173467
|
173468
|
173469
|
173470
|
173471
|
173472
|
173473
|
173474
|
173475
| 173476 |
173477
|
173478
|
173479
|
173480
|
173481
|
173482
|
173483
|
173484
|
173485
|
173486
|
173546
|
173606
|
173607
|
173985
|
174219