From c1e5ee1fe5ce5ec6081686309a8f1db161fe9c21 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 3 Oct 2024 15:02:58 +0200 Subject: [PATCH] Bug 33484: (Bug 27467) Ability to share a link Signed-off-by: Pedro Amorim Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 790f66e9b9..3186a7bf03 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -56,12 +56,13 @@ var dataTablesDefaults = { "pageLength": 20, "fixedHeader": true, initComplete: function( settings ) { - var tableId = settings.nTable.id - var state = settings.oLoadedState; + var tableId = settings.nTable.id; + let table_node = $("#" + tableId); + + state = settings.oLoadedState; state && state.search && toggledClearFilter(state.search.search, tableId); if (settings.ajax) { - let table_node = $("#" + tableId); if ( typeof this.api === 'function' ) { _dt_add_delay(this.api(), table_node); } else { @@ -757,6 +758,28 @@ function _dt_buttons(params){ } ); + buttons.push( + { + autoClose: true, + fade: 100, + className: "copyConditions_controls", + titleAttr: __("Copy conditions"), + text: ' ' + __("Copy conditions") + '', + action: function (e, dt, node, config) { + let state = JSON.stringify(dt.state()); + delete state.time; + let searchParams = new URLSearchParams(window.location.search); + let table_id = dt.table().node().id; + searchParams.set(table_id + '_state', btoa(state)); + let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash; + if( navigator.clipboard && navigator.clipboard.writeText){ + navigator.clipboard.writeText( url ); + // TODO Add tooltip "State copied to the clipboard" + } + }, + } + ); + if ( table_settings && CAN_user_parameters_manage_column_config ) { buttons.push( { @@ -952,6 +975,14 @@ function _dt_save_restore_state(table_settings){ localStorage.setItem( table_key, JSON.stringify(data) ) } let stateLoadCallback = function(settings) { + + // Load state from URL + const url = new URL(window.location.href); + let state_from_url = url.searchParams.get( settings.nTable.id + '_state'); + if ( state_from_url ) { + return JSON.parse(atob(state_from_url)); + } + if (!default_save_state) return {}; let state = localStorage.getItem(table_key); -- 2.39.5