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

(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-41 / +25 lines)
Lines 596-602 function _dt_default_ajax (params){ Link Here
596
}
596
}
597
597
598
function _dt_buttons(params){
598
function _dt_buttons(params){
599
    let included_ids = params.included_ids || [];
600
    let settings = params.settings || {};
599
    let settings = params.settings || {};
601
    let table_settings = params.table_settings;
600
    let table_settings = params.table_settings;
602
601
Lines 665-676 function _dt_buttons(params){ Link Here
665
        }
664
        }
666
    );
665
    );
667
666
668
    if( included_ids.length > 0 ){
667
    let included_columns = table_settings.columns.filter(c => !c.cannot_be_toggled);
668
    if( included_columns.length > 0 ){
669
        buttons.push(
669
        buttons.push(
670
            {
670
            {
671
                extend: 'colvis',
671
                extend: 'colvis',
672
                fade: 100,
672
                fade: 100,
673
                columns: included_ids,
673
                columns: included_columns.map(c => "[data-colname='%s']".format(c.columnname)).join(','),
674
                className: "columns_controls",
674
                className: "columns_controls",
675
                titleAttr: __("Columns settings"),
675
                titleAttr: __("Columns settings"),
676
                text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + __("Columns") + '</span>',
676
                text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + __("Columns") + '</span>',
Lines 738-774 function _dt_buttons(params){ Link Here
738
    return buttons;
738
    return buttons;
739
}
739
}
740
740
741
function _dt_visibility(table_settings, settings, node){
741
function _dt_visibility(table_settings, table_dt){
742
    var counter = 0;
743
    let hidden_ids = [];
742
    let hidden_ids = [];
744
    let included_ids = [];
745
    if ( table_settings ) {
743
    if ( table_settings ) {
746
        var columns_settings = table_settings['columns'];
744
        var columns_settings = table_settings.columns;
747
        $(columns_settings).each( function() {
745
        let i = 0;
748
            let used_id = counter;
746
        let use_names = $(table_dt.table().node()).data('bKohaColumnsUseNames');
749
            let use_names = $(node).data('bKohaColumnsUseNames');
747
        if ( use_names ) {
750
            if ( use_names ) {
748
            let hidden_columns = table_settings.columns.filter(c => c.is_hidden);
751
                if (!node){
749
            table_dt.columns(hidden_columns.map(c => "[data-colname='%s']".format(c.columnname)).join(',')).every(function(){
752
                    console.err("bKohaColumnsUseNames is set but node not passed");
750
                hidden_ids.push(this.index());
753
                    return;
751
            });
752
        } else {
753
            $(columns_settings).each( function(i, c) {
754
                if ( c.is_hidden == '1' ) {
755
                    hidden_ids.push(i);
754
                }
756
                }
755
                let selector = '#' + node.attr('id');
757
            });
756
                var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( selector + ' th' );
758
        }
757
                used_id = named_id;
758
            }
759
760
            if ( used_id == -1 ) return;
761
762
            if ( this['is_hidden'] == "1" ) {
763
                hidden_ids.push( used_id );
764
            }
765
            if ( this['cannot_be_toggled'] == "0" ) {
766
                included_ids.push( used_id );
767
            }
768
            counter++;
769
        });
770
    }
759
    }
771
    return [hidden_ids, included_ids];
760
    return hidden_ids;
772
}
761
}
773
762
774
function _dt_on_visibility(add_filters, table_node, table_dt){
763
function _dt_on_visibility(add_filters, table_node, table_dt){
Lines 894-903 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
894
        localStorage.setItem( table_key, JSON.stringify(data) )
883
        localStorage.setItem( table_key, JSON.stringify(data) )
895
    }
884
    }
896
885
897
    function set_default(table_settings, settings){
886
    function set_default(table_settings, table_dt){
898
        let columns = new Array(table_settings.columns.length).fill({visible: true});
887
        let columns = new Array(table_dt.columns()[0].length).fill({visible: true});
899
        let hidden_ids, included_ids;
888
        let hidden_ids = _dt_visibility(table_settings, table_dt);
900
        [hidden_ids, included_ids] = _dt_visibility(table_settings, settings, $("#"+settings.nTable.id));
901
        hidden_ids.forEach((id, i) => { columns[id] = { visible: false } } );
889
        hidden_ids.forEach((id, i) => { columns[id] = { visible: false } } );
902
        // State is not loaded if time is not passed
890
        // State is not loaded if time is not passed
903
        return { columns, time: new Date() };
891
        return { columns, time: new Date() };
Lines 911-920 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
911
            return JSON.parse(atob(state_from_url));
899
            return JSON.parse(atob(state_from_url));
912
        }
900
        }
913
901
914
        if (!default_save_state) return set_default(table_settings, settings);
902
        if (!default_save_state) return set_default(table_settings, this.api());
915
903
916
        let state = localStorage.getItem(table_key);
904
        let state = localStorage.getItem(table_key);
917
        if (!state) return set_default(table_settings, settings);
905
        if (!state) return set_default(table_settings, this.api());
918
906
919
        state = JSON.parse(state);
907
        state = JSON.parse(state);
920
908
Lines 1039-1048 function _dt_save_restore_state(table_settings, external_filter_nodes={}){ Link Here
1039
                    }, options);
1027
                    }, options);
1040
        }
1028
        }
1041
1029
1042
        let hidden_ids, included_ids;
1030
        settings["buttons"] = _dt_buttons({settings, table_settings});
1043
        [hidden_ids, included_ids] = _dt_visibility(table_settings, settings, this)
1044
1045
        settings["buttons"] = _dt_buttons({included_ids, settings, table_settings});
1046
1031
1047
        if ( add_filters ) {
1032
        if ( add_filters ) {
1048
            settings['orderCellsTop'] = true;
1033
            settings['orderCellsTop'] = true;
1049
- 

Return to bug 38436