View | Details | Raw Unified | Return to bug 33484
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc (-2 / +47 lines)
Lines 26-36 function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { Link Here
26
        dt_parameters.stateSaveCallback = function( settings, data ) {
26
        dt_parameters.stateSaveCallback = function( settings, data ) {
27
            localStorage.setItem( table_key, JSON.stringify(data) )
27
            localStorage.setItem( table_key, JSON.stringify(data) )
28
        }
28
        }
29
30
        function set_default(table_settings, settings){
31
            let columns = new Array(table_settings.columns.length).fill({visible: true});
32
            let hidden_ids, included_ids;
33
            [hidden_ids, included_ids] = _dt_visibility(table_settings, settings, $("#"+settings.nTable.id));
34
            hidden_ids.forEach((id, i) => { columns[id] = { visible: false } } );
35
            // State is not loaded if time is not passed
36
            return { columns, time: new Date() };
37
        }
29
        dt_parameters.stateLoadCallback = function(settings) {
38
        dt_parameters.stateLoadCallback = function(settings) {
30
            if (!default_save_state) return {};
39
40
            // Load state from URL
41
            const url = new URL(window.location.href);
42
            let state_from_url = url.searchParams.get( settings.nTable.id + '_state');
43
            if ( state_from_url ) {
44
                settings.loaded_from_state = true;
45
                return JSON.parse(atob(state_from_url));
46
            }
47
48
            if (!default_save_state) return set_default(table_settings, settings);
31
49
32
            let state = localStorage.getItem(table_key);
50
            let state = localStorage.getItem(table_key);
33
            if (!state) return {};
51
            if (!state) return set_default(table_settings, settings);
34
52
35
            state = JSON.parse(state);
53
            state = JSON.parse(state);
36
54
Lines 38-43 function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { Link Here
38
                delete state.search;
56
                delete state.search;
39
                state.columns.forEach(c => delete c.search );
57
                state.columns.forEach(c => delete c.search );
40
            }
58
            }
59
            settings.loaded_from_state = true;
41
            return state;
60
            return state;
42
        }
61
        }
43
62
Lines 193-198 function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { Link Here
193
        }
212
        }
194
    );
213
    );
195
214
215
    if ( table_settings ) {
216
        dt_parameters["buttons"].push(
217
            {
218
                autoClose: true,
219
                fade: 100,
220
                className: "copyConditions_controls",
221
                titleAttr: __("Copy conditions"),
222
                text: '<i class="fa fa-lg fa-copy"></i> <span class="dt-button-text">' + __("Copy conditions") + '</span>',
223
                action: function (e, dt, node, config) {
224
                    let state = JSON.stringify(dt.state());
225
                    delete state.time;
226
                    let searchParams = new URLSearchParams(window.location.search);
227
                    let table_id = dt.table().node().id;
228
                    searchParams.set(table_id + '_state', btoa(state));
229
                    let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash;
230
                    if( navigator.clipboard && navigator.clipboard.writeText){
231
                        navigator.clipboard.writeText( url );
232
                        // TODO Add tooltip "State copied to the clipboard"
233
                    }
234
                },
235
            }
236
        );
237
    }
238
196
    if ( table_settings && CAN_user_parameters_manage_column_config ) {
239
    if ( table_settings && CAN_user_parameters_manage_column_config ) {
197
        dt_parameters[ "buttons" ].push(
240
        dt_parameters[ "buttons" ].push(
198
            {
241
            {
Lines 233-238 function KohaTable(id_selector, dt_parameters, table_settings, add_filters) { Link Here
233
        });
276
        });
234
    }
277
    }
235
278
279
    new_parameters["loaded_from_state"] = false;
280
236
    if ( table_settings ) {
281
    if ( table_settings ) {
237
        if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) {
282
        if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) {
238
            // pageLength needs to be a number, not a string, or it can cause issues with DataTable's next button.
283
            // pageLength needs to be a number, not a string, or it can cause issues with DataTable's next button.
(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-22 / +23 lines)
Lines 758-784 function _dt_buttons(params){ Link Here
758
        }
758
        }
759
    );
759
    );
760
760
761
    buttons.push(
761
    if ( table_settings ) {
762
        {
762
        buttons.push(
763
            autoClose: true,
763
            {
764
            fade: 100,
764
                autoClose: true,
765
            className: "copyConditions_controls",
765
                fade: 100,
766
            titleAttr: __("Copy conditions"),
766
                className: "copyConditions_controls",
767
            text: '<i class="fa fa-lg fa-copy"></i> <span class="dt-button-text">' + __("Copy conditions") + '</span>',
767
                titleAttr: __("Copy conditions"),
768
            action: function (e, dt, node, config) {
768
                text: '<i class="fa fa-lg fa-copy"></i> <span class="dt-button-text">' + __("Copy conditions") + '</span>',
769
                let state = JSON.stringify(dt.state());
769
                action: function (e, dt, node, config) {
770
                delete state.time;
770
                    let state = JSON.stringify(dt.state());
771
                let searchParams = new URLSearchParams(window.location.search);
771
                    delete state.time;
772
                let table_id = dt.table().node().id;
772
                    let searchParams = new URLSearchParams(window.location.search);
773
                searchParams.set(table_id + '_state', btoa(state));
773
                    let table_id = dt.table().node().id;
774
                let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash;
774
                    searchParams.set(table_id + '_state', btoa(state));
775
                if( navigator.clipboard && navigator.clipboard.writeText){
775
                    let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash;
776
                    navigator.clipboard.writeText( url );
776
                    if( navigator.clipboard && navigator.clipboard.writeText){
777
                    // TODO Add tooltip "State copied to the clipboard"
777
                        navigator.clipboard.writeText( url );
778
                }
778
                        // TODO Add tooltip "State copied to the clipboard"
779
            },
779
                    }
780
        }
780
                },
781
    );
781
            }
782
        );
783
    }
782
784
783
    if ( table_settings && CAN_user_parameters_manage_column_config ) {
785
    if ( table_settings && CAN_user_parameters_manage_column_config ) {
784
        buttons.push(
786
        buttons.push(
785
- 

Return to bug 33484