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

(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-6 / +35 lines)
Lines 961-967 function _dt_add_delay(table_dt, table_node, delay_ms) { Link Here
961
    });
961
    });
962
}
962
}
963
963
964
function _dt_save_restore_state(table_settings){
964
function _dt_save_restore_state(table_settings, external_filter_nodes={}){
965
965
966
    let table_key = 'DataTables_%s_%s_%s'.format(
966
    let table_key = 'DataTables_%s_%s_%s'.format(
967
        table_settings.module,
967
        table_settings.module,
Lines 984-990 function _dt_save_restore_state(table_settings){ Link Here
984
        return { columns, time: new Date() };
984
        return { columns, time: new Date() };
985
    }
985
    }
986
    let stateLoadCallback = function(settings) {
986
    let stateLoadCallback = function(settings) {
987
988
        // Load state from URL
987
        // Load state from URL
989
        const url = new URL(window.location.href);
988
        const url = new URL(window.location.href);
990
        let state_from_url = url.searchParams.get( table_key + '_state');
989
        let state_from_url = url.searchParams.get( table_key + '_state');
Lines 1008-1014 function _dt_save_restore_state(table_settings){ Link Here
1008
        return state;
1007
        return state;
1009
    }
1008
    }
1010
1009
1011
    return {stateSave: true, stateSaveCallback, stateLoadCallback};
1010
    let stateSaveParams = function (settings, data) {
1011
        // FIXME Selector in on the whole DOM, we don't know where the filters are
1012
        // If others exist on the same page this will lead to unexpected behaviours
1013
        // Should be safe so far as: patron search use the same code for the different searches
1014
        // but only the main one has the table settings (and so the state saved)
1015
        data.external_filters = Object.keys(external_filter_nodes).reduce(
1016
            (r, k) => {
1017
                r[k] = $(external_filter_nodes[k]).val();
1018
                return r;
1019
            },
1020
            {}
1021
        );
1022
    };
1023
    let stateLoadParams = function (settings, data) {
1024
        if (!settings.loaded_from_state) return;
1025
1026
        if (data.external_filters) {
1027
            Object.keys(external_filter_nodes).forEach((k, i) => {
1028
                if (data.external_filters.hasOwnProperty(k)) {
1029
                    $(external_filter_nodes[k]).val(data.external_filters[k]);
1030
                }
1031
            });
1032
        }
1033
    };
1034
1035
    return {
1036
        stateSave: true,
1037
        stateSaveCallback,
1038
        stateLoadCallback,
1039
        stateSaveParams,
1040
        stateLoadParams,
1041
    };
1012
}
1042
}
1013
1043
1014
(function($) {
1044
(function($) {
Lines 1028-1034 function _dt_save_restore_state(table_settings){ Link Here
1028
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1058
    * @param  {Object}  default_filters              Add a set of default search filters to apply at table initialisation
1029
    * @return {Object}                               The dataTables instance
1059
    * @return {Object}                               The dataTables instance
1030
    */
1060
    */
1031
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options) {
1061
    $.fn.kohaTable = function(options, table_settings, add_filters, default_filters, filters_options, external_filter_nodes) {
1032
        var settings = null;
1062
        var settings = null;
1033
1063
1034
        if(options) {
1064
        if(options) {
Lines 1066-1072 function _dt_save_restore_state(table_settings){ Link Here
1066
        }
1096
        }
1067
1097
1068
        if ( table_settings ) {
1098
        if ( table_settings ) {
1069
            let state_settings = _dt_save_restore_state(table_settings);
1099
            let state_settings = _dt_save_restore_state(table_settings, external_filter_nodes);
1070
            settings = {...settings, ...state_settings};
1100
            settings = {...settings, ...state_settings};
1071
1101
1072
            if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) {
1102
            if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) {
1073
- 

Return to bug 33484