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

(-)a/koha-tmpl/intranet-tmpl/prog/js/datatables.js (-1 / +130 lines)
Lines 509-515 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
509
509
510
(function($) {
510
(function($) {
511
511
512
    $.fn.api = function(options) {
512
    $.fn.api = function(options, columns_settings, add_filters) {
513
        var settings = null;
513
        var settings = null;
514
        if(options) {
514
        if(options) {
515
            if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains';
515
            if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains';
Lines 520-525 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
520
                        'serverSide': true,
520
                        'serverSide': true,
521
                        'searching': true,
521
                        'searching': true,
522
                        'pagingType': 'full_numbers',
522
                        'pagingType': 'full_numbers',
523
                        'processing': true,
524
                        'language': {
525
                            'emptyTable': (options.emptyTable) ? options.emptyTable : _("No data available in table")
526
                        },
523
                        'ajax': {
527
                        'ajax': {
524
                            'type': 'GET',
528
                            'type': 'GET',
525
                            'cache': true,
529
                            'cache': true,
Lines 592-597 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
592
                        }
596
                        }
593
                    }, options);
597
                    }, options);
594
        }
598
        }
599
600
        var counter = 0;
601
        var hidden_ids = [];
602
        var included_ids = [];
603
604
        $(columns_settings).each( function() {
605
            var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' );
606
            var used_id = settings.bKohaColumnsUseNames ? named_id : counter;
607
            if ( used_id == -1 ) return;
608
609
            if ( this['is_hidden'] == "1" ) {
610
                hidden_ids.push( used_id );
611
            }
612
            if ( this['cannot_be_toggled'] == "0" ) {
613
                included_ids.push( used_id );
614
            }
615
            counter++;
616
        });
617
618
        var exportColumns = ":visible:not(.noExport)";
619
        if( settings.hasOwnProperty("exportColumns") ){
620
            // A custom buttons configuration has been passed from the page
621
            exportColumns = settings["exportColumns"];
622
        }
623
624
        var export_format = {
625
            body: function ( data, row, column, node ) {
626
                var newnode = $(node);
627
628
                if ( newnode.find(".noExport").length > 0 ) {
629
                    newnode = newnode.clone();
630
                    newnode.find(".noExport").remove();
631
                }
632
633
                return newnode.text().replace( /\n/g, ' ' ).trim();
634
            }
635
        }
636
637
        var export_buttons = [
638
            {
639
                extend: 'excelHtml5',
640
                text: _("Excel"),
641
                exportOptions: {
642
                    columns: exportColumns,
643
                    format:  export_format
644
                },
645
            },
646
            {
647
                extend: 'csvHtml5',
648
                text: _("CSV"),
649
                exportOptions: {
650
                    columns: exportColumns,
651
                    format:  export_format
652
                },
653
            },
654
            {
655
                extend: 'copyHtml5',
656
                text: _("Copy"),
657
                exportOptions: {
658
                    columns: exportColumns,
659
                    format:  export_format
660
                },
661
            },
662
            {
663
                extend: 'print',
664
                text: _("Print"),
665
                exportOptions: {
666
                    columns: exportColumns,
667
                    format:  export_format
668
                },
669
            }
670
        ];
671
672
        settings[ "buttons" ] = [
673
            {
674
                fade: 100,
675
                className: "dt_button_clear_filter",
676
                titleAttr: _("Clear filter"),
677
                enabled: false,
678
                text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
679
                action: function ( e, dt, node, config ) {
680
                    dt.search( "" ).draw("page");
681
                    node.addClass("disabled");
682
                }
683
            }
684
        ];
685
686
        if( included_ids.length > 0 ){
687
            settings[ "buttons" ].push(
688
                {
689
                    extend: 'colvis',
690
                    fade: 100,
691
                    columns: included_ids,
692
                    className: "columns_controls",
693
                    titleAttr: _("Columns settings"),
694
                    text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
695
                    exportOptions: {
696
                        columns: exportColumns
697
                    }
698
                }
699
            );
700
        }
701
702
        settings[ "buttons" ].push(
703
            {
704
                extend: 'collection',
705
                autoClose: true,
706
                fade: 100,
707
                className: "export_controls",
708
                titleAttr: _("Export or print"),
709
                text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>',
710
                buttons: export_buttons
711
            }
712
        );
713
714
        if ( add_filters ) {
715
            // Duplicate the table header row for columnFilter
716
            thead_row = this.find('thead tr');
717
            clone = thead_row.clone().addClass('filters_row');
718
            clone.find("th.NoSort").html('');
719
            thead_row.before(clone);
720
        }
721
722
        $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
723
595
        return $(this).dataTable(settings);
724
        return $(this).dataTable(settings);
596
    };
725
    };
597
726
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js (-41 / +548 lines)
Lines 1-49 Link Here
1
// These default options are for translation but can be used
1
// These default options are for translation but can be used
2
// for any other datatables settings
2
// for any other datatables settings
3
// MSG_DT_* variables comes from datatables.inc
4
// To use it, write:
3
// To use it, write:
5
//  $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, {
4
//  $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, {
6
//      // other settings
5
//      // other settings
7
//  } ) );
6
//  } ) );
8
var dataTablesDefaults = {
7
var dataTablesDefaults = {
9
    "language": {
8
    "oLanguage": {
10
        "paginate": {
9
        "oPaginate": {
11
            "first"    : window.MSG_DT_FIRST || "First",
10
            "sFirst"    : __('First'),
12
            "last"     : window.MSG_DT_LAST || "Last",
11
            "sLast"     : __('Last'),
13
            "next"     : window.MSG_DT_NEXT || "Next",
12
            "sNext"     : __('Next'),
14
            "previous" : window.MSG_DT_PREVIOUS || "Previous"
13
            "sPrevious" : __('Previous'),
15
        },
14
        },
16
        "emptyTable"       : window.MSG_DT_EMPTY_TABLE || "No data available in table",
15
        "sEmptyTable"       : __('No data available in table'),
17
        "info"             : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries",
16
        "sInfo"             : __('Showing _START_ to _END_ of _TOTAL_ entries'),
18
        "infoEmpty"        : window.MSG_DT_INFO_EMPTY || "No entries to show",
17
        "sInfoEmpty"        : __('No entries to show'),
19
        "infoFiltered"     : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)",
18
        "sInfoFiltered"     : __('(filtered from _MAX_ total entries)'),
20
        "lengthMenu"       : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries",
19
        "sLengthMenu"       : __('Show _MENU_ entries'),
21
        "loadingRecords"   : window.MSG_DT_LOADING_RECORDS || "Loading...",
20
        "sLoadingRecords"   : __('Loading...'),
22
        "processing"       : window.MSG_DT_PROCESSING || "Processing...",
21
        "sProcessing"       : __('Processing...'),
23
        "search"           : window.MSG_DT_SEARCH || "Search:",
22
        "sSearch"           : __('Search:'),
24
        "zeroRecords"      : window.MSG_DT_ZERO_RECORDS || "No matching records found"
23
        "sZeroRecords"      : __('No matching records found'),
24
        buttons: {
25
            "copyTitle"     : __('Copy to clipboard'),
26
            "copyKeys"      : __('Press <i>ctrl</i> or <i>⌘</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>To cancel, click this message or press escape.'),
27
            "copySuccess": {
28
                _: __('Copied %d rows to clipboard'),
29
                1: __('Copied one row to clipboard'),
30
            }
31
        }
25
    },
32
    },
26
    // "sorting": [$(" - select row position of th -")],
33
    "dom": '<"top pager"<"table_entries"ilp><"table_controls"fB>>tr<"bottom pager"ip>',
27
    "dom": 't',
34
    "buttons": [{
28
    "paginate": false,
35
        fade: 100,
29
    // "fnHeaderCallback": function() {
36
        className: "dt_button_clear_filter",
30
    //     return $('th.sorting.nosort,th.sorting_desc.nosort,th.sorting_asc.nosort').removeClass("sorting sorting_desc sorting_asc").unbind("click");
37
        titleAttr: __('Clear filter'),
31
    // }
38
        enabled: false,
39
        text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + __('Clear filter') + '</span>',
40
        available: function ( dt ) {
41
            // The "clear filter" button is made available if this test returns true
42
            if( dt.settings()[0].aanFeatures.f ){ // aanFeatures.f is null if there is no search form
43
                return true;
44
            }
45
        },
46
        action: function ( e, dt, node ) {
47
            dt.search( "" ).draw("page");
48
            node.addClass("disabled");
49
        }
50
    }],
51
    "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, __('All')]],
52
    "iDisplayLength": 20,
53
    initComplete: function( settings) {
54
        var tableId = settings.nTable.id
55
        // When the DataTables search function is triggered,
56
        // enable or disable the "Clear filter" button based on
57
        // the presence of a search string
58
        $("#" + tableId ).on( 'search.dt', function ( e, settings ) {
59
            if( settings.oPreviousSearch.sSearch == "" ){
60
                $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").addClass("disabled");
61
            } else {
62
                $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").removeClass("disabled");
63
            }
64
        });
65
    }
32
};
66
};
33
67
68
69
// Return an array of string containing the values of a particular column
70
$.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
71
    // check that we have a column id
72
    if ( typeof iColumn == "undefined" ) return new Array();
73
    // by default we only wany unique data
74
    if ( typeof bUnique == "undefined" ) bUnique = true;
75
    // by default we do want to only look at filtered data
76
    if ( typeof bFiltered == "undefined" ) bFiltered = true;
77
    // by default we do not wany to include empty values
78
    if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
79
    // list of rows which we're going to loop through
80
    var aiRows;
81
    // use only filtered rows
82
    if (bFiltered == true) aiRows = oSettings.aiDisplay;
83
    // use all rows
84
    else aiRows = oSettings.aiDisplayMaster; // all row numbers
85
86
    // set up data array
87
    var asResultData = new Array();
88
    for (var i=0,c=aiRows.length; i<c; i++) {
89
        iRow = aiRows[i];
90
        var aData = this.fnGetData(iRow);
91
        var sValue = aData[iColumn];
92
        // ignore empty values?
93
        if (bIgnoreEmpty == true && sValue.length == 0) continue;
94
        // ignore unique values?
95
        else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
96
        // else push the value onto the result data array
97
        else asResultData.push(sValue);
98
    }
99
    return asResultData;
100
}
101
102
// List of unbind keys (Ctrl, Alt, Direction keys, etc.)
103
// These keys must not launch filtering
104
var blacklist_keys = new Array(0, 16, 17, 18, 37, 38, 39, 40);
105
106
// Set a filtering delay for global search field
107
jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
108
    /*
109
     * Inputs:      object:oSettings - dataTables settings object - automatically given
110
     *              integer:iDelay - delay in milliseconds
111
     * Usage:       $('#example').dataTable().fnSetFilteringDelay(250);
112
     * Author:      Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
113
     * License:     GPL v2 or BSD 3 point style
114
     * Contact:     zygimantas.berziunas /AT\ hotmail.com
115
     */
116
    var
117
        _that = this,
118
        iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
119
120
    this.each( function ( i ) {
121
        $.fn.dataTableExt.iApiIndex = i;
122
        var
123
            $this = this,
124
            oTimerId = null,
125
            sPreviousSearch = null,
126
            anControl = $( 'input', _that.fnSettings().aanFeatures.f );
127
128
        anControl.unbind( 'keyup.DT' ).bind( 'keyup.DT', function(event) {
129
            var $$this = $this;
130
            if (blacklist_keys.indexOf(event.keyCode) != -1) {
131
                return this;
132
            }else if ( event.keyCode == '13' ) {
133
                $.fn.dataTableExt.iApiIndex = i;
134
                _that.fnFilter( $(this).val() );
135
            } else {
136
                if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
137
                    window.clearTimeout(oTimerId);
138
                    sPreviousSearch = anControl.val();
139
                    oTimerId = window.setTimeout(function() {
140
                        $.fn.dataTableExt.iApiIndex = i;
141
                        _that.fnFilter( anControl.val() );
142
                    }, iDelay);
143
                }
144
            }
145
        });
146
147
        return this;
148
    } );
149
    return this;
150
}
151
152
// Add a filtering delay on general search and on all input (with a class 'filter')
153
jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay ) {
154
    var table = this;
155
    this.fnSetFilteringDelay(iDelay);
156
    var filterTimerId = null;
157
    $(table).find("input."+sClass).keyup(function(event) {
158
      if (blacklist_keys.indexOf(event.keyCode) != -1) {
159
        return this;
160
      }else if ( event.keyCode == '13' ) {
161
        table.fnFilter( $(this).val(), $(this).attr('data-column_num') );
162
      } else {
163
        window.clearTimeout(filterTimerId);
164
        var input = this;
165
        filterTimerId = window.setTimeout(function() {
166
          table.fnFilter($(input).val(), $(input).attr('data-column_num'));
167
        }, iDelay);
168
      }
169
    });
170
    $(table).find("select."+sClass).on('change', function() {
171
        table.fnFilter($(this).val(), $(this).attr('data-column_num'));
172
    });
173
}
174
175
// Sorting on html contains
176
// <a href="foo.pl">bar</a> sort on 'bar'
177
function dt_overwrite_html_sorting_localeCompare() {
178
    jQuery.fn.dataTableExt.oSort['html-asc']  = function(a,b) {
179
        a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
180
        b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
181
        if (typeof(a.localeCompare == "function")) {
182
           return a.localeCompare(b);
183
        } else {
184
           return (a > b) ? 1 : ((a < b) ? -1 : 0);
185
        }
186
    };
187
188
    jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
189
        a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
190
        b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
191
        if(typeof(b.localeCompare == "function")) {
192
            return b.localeCompare(a);
193
        } else {
194
            return (b > a) ? 1 : ((b < a) ? -1 : 0);
195
        }
196
    };
197
198
    jQuery.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
199
        var x = a.replace( /<.*?>/g, "" );
200
        var y = b.replace( /<.*?>/g, "" );
201
        x = parseFloat( x );
202
        y = parseFloat( y );
203
        return ((x < y) ? -1 : ((x > y) ?  1 : 0));
204
    };
205
206
    jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
207
        var x = a.replace( /<.*?>/g, "" );
208
        var y = b.replace( /<.*?>/g, "" );
209
        x = parseFloat( x );
210
        y = parseFloat( y );
211
        return ((x < y) ?  1 : ((x > y) ? -1 : 0));
212
    };
213
}
214
215
$.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
216
    var x = a.replace( /<.*?>/g, "" );
217
    var y = b.replace( /<.*?>/g, "" );
218
    x = parseFloat( x );
219
    y = parseFloat( y );
220
    return ((x < y) ? -1 : ((x > y) ?  1 : 0));
221
};
222
223
$.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
224
    var x = a.replace( /<.*?>/g, "" );
225
    var y = b.replace( /<.*?>/g, "" );
226
    x = parseFloat( x );
227
    y = parseFloat( y );
228
    return ((x < y) ?  1 : ((x > y) ? -1 : 0));
229
};
230
231
(function() {
232
233
/*
234
 * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
235
 * Author: Jim Palmer (based on chunking idea from Dave Koelle)
236
 * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
237
 * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
238
 */
239
function naturalSort (a, b) {
240
    var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
241
        sre = /(^[ ]*|[ ]*$)/g,
242
        dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
243
        hre = /^0x[0-9a-f]+$/i,
244
        ore = /^0/,
245
        // convert all to strings and trim()
246
        x = a.toString().replace(sre, '') || '',
247
        y = b.toString().replace(sre, '') || '',
248
        // chunk/tokenize
249
        xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
250
        yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
251
        // numeric, hex or date detection
252
        xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
253
        yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
254
    // first try and sort Hex codes or Dates
255
    if (yD)
256
        if ( xD < yD ) return -1;
257
        else if ( xD > yD )  return 1;
258
    // natural sorting through split numeric strings and default strings
259
    for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
260
        // find floats not starting with '0', string or 0 if not defined (Clint Priest)
261
        var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
262
        var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
263
        // handle numeric vs string comparison - number < string - (Kyle Adams)
264
        if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
265
        // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
266
        else if (typeof oFxNcL !== typeof oFyNcL) {
267
            oFxNcL += '';
268
            oFyNcL += '';
269
        }
270
        if (oFxNcL < oFyNcL) return -1;
271
        if (oFxNcL > oFyNcL) return 1;
272
    }
273
    return 0;
274
}
275
276
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
277
    "natural-asc": function ( a, b ) {
278
        return naturalSort(a,b);
279
    },
280
281
    "natural-desc": function ( a, b ) {
282
        return naturalSort(a,b) * -1;
283
    }
284
} );
285
286
}());
287
34
/* Plugin to allow sorting on data stored in a span's title attribute
288
/* Plugin to allow sorting on data stored in a span's title attribute
35
 *
289
 *
36
 * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
290
 * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
37
 *
291
 *
38
 * In DataTables config:
292
 * In DataTables config:
39
 *     "columns": [
293
 *     "aoColumns": [
40
 *        { "type": "title-string" },
294
 *        { "sType": "title-string" },
41
 *      ]
295
 *      ]
42
 * http://datatables.net/plug-ins/sorting#hidden_title_string
296
 * http://datatables.net/plug-ins/sorting#hidden_title_string
43
 */
297
 */
44
jQuery.extend( jQuery.fn.dataTableExt.sort, {
298
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
45
    "title-string-pre": function ( a ) {
299
    "title-string-pre": function ( a ) {
46
        return a.match(/title="(.*?)"/)[1].toLowerCase();
300
        var m = a.match(/title="(.*?)"/);
301
        if ( null !== m && m.length ) {
302
            return m[1].toLowerCase();
303
        }
304
        return "";
47
    },
305
    },
48
306
49
    "title-string-asc": function ( a, b ) {
307
    "title-string-asc": function ( a, b ) {
Lines 55-71 jQuery.extend( jQuery.fn.dataTableExt.sort, { Link Here
55
    }
313
    }
56
} );
314
} );
57
315
58
/* Plugin to allow sorting numerically on data stored in a span's title attribute
316
/* Plugin to allow sorting on numeric data stored in a span's title attribute
59
 *
317
 *
60
 * Ex: <td><span title="[% total %]">Total: [% total %]</span></td>
318
 * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
319
 *              [% formatted currency %]
320
 *     </span></td>
61
 *
321
 *
62
 * In DataTables config:
322
 * In DataTables config:
63
 *     "columns": [
323
 *     "aoColumns": [
64
 *        { "type": "title-numeric" }
324
 *        { "sType": "title-numeric" },
65
 *     ]
325
 *      ]
66
 * http://legacy.datatables.net/plug-ins/sorting#hidden_title
326
 * http://datatables.net/plug-ins/sorting#hidden_title
67
 */
327
 */
68
jQuery.extend( jQuery.fn.dataTableExt.sort, {
328
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
69
    "title-numeric-pre": function ( a ) {
329
    "title-numeric-pre": function ( a ) {
70
        var x = a.match(/title="*(-?[0-9\.]+)/)[1];
330
        var x = a.match(/title="*(-?[0-9\.]+)/)[1];
71
        return parseFloat( x );
331
        return parseFloat( x );
Lines 85-92 jQuery.extend( jQuery.fn.dataTableExt.sort, { Link Here
85
    /* Plugin to allow text sorting to ignore articles
345
    /* Plugin to allow text sorting to ignore articles
86
     *
346
     *
87
     * In DataTables config:
347
     * In DataTables config:
88
     *     "columns": [
348
     *     "aoColumns": [
89
     *        { "type": "anti-the" },
349
     *        { "sType": "anti-the" },
90
     *      ]
350
     *      ]
91
     * Based on the plugin found here:
351
     * Based on the plugin found here:
92
     * http://datatables.net/plug-ins/sorting#anti_the
352
     * http://datatables.net/plug-ins/sorting#anti_the
Lines 95-102 jQuery.extend( jQuery.fn.dataTableExt.sort, { Link Here
95
     * from a configuration file (in English, "a," "an," and "the")
355
     * from a configuration file (in English, "a," "an," and "the")
96
     */
356
     */
97
357
98
    if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
358
    var config_exclude_articles_from_sort = __('a an the');
99
        var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
359
    if (config_exclude_articles_from_sort){
360
        var articles = config_exclude_articles_from_sort.split(" ");
100
        var rpattern = "";
361
        var rpattern = "";
101
        for(i=0;i<articles.length;i++){
362
        for(i=0;i<articles.length;i++){
102
            rpattern += "^" + articles[i] + " ";
363
            rpattern += "^" + articles[i] + " ";
Lines 105-111 jQuery.extend( jQuery.fn.dataTableExt.sort, { Link Here
105
        var re = new RegExp(rpattern, "i");
366
        var re = new RegExp(rpattern, "i");
106
    }
367
    }
107
368
108
    jQuery.extend( jQuery.fn.dataTableExt.sort, {
369
    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
109
        "anti-the-pre": function ( a ) {
370
        "anti-the-pre": function ( a ) {
110
            var x = String(a).replace( /<[\s\S]*?>/g, "" );
371
            var x = String(a).replace( /<[\s\S]*?>/g, "" );
111
            var y = x.trim();
372
            var y = x.trim();
Lines 124-136 jQuery.extend( jQuery.fn.dataTableExt.sort, { Link Here
124
385
125
}());
386
}());
126
387
388
// Remove string between NSB NSB characters
389
$.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
390
    var pattern = new RegExp("\x88.*\x89");
391
    a = a.replace(pattern, "");
392
    b = b.replace(pattern, "");
393
    return (a > b) ? 1 : ((a < b) ? -1 : 0);
394
}
395
$.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
396
    var pattern = new RegExp("\x88.*\x89");
397
    a = a.replace(pattern, "");
398
    b = b.replace(pattern, "");
399
    return (b > a) ? 1 : ((b < a) ? -1 : 0);
400
}
401
402
/* Define two custom functions (asc and desc) for basket callnumber sorting */
403
jQuery.fn.dataTableExt.oSort['callnumbers-asc']  = function(x,y) {
404
        var x_array = x.split("<div>");
405
        var y_array = y.split("<div>");
406
407
        /* Pop the first elements, they are empty strings */
408
        x_array.shift();
409
        y_array.shift();
410
411
        x_array = jQuery.map( x_array, function( a ) {
412
            return parse_callnumber( a );
413
        });
414
        y_array = jQuery.map( y_array, function( a ) {
415
            return parse_callnumber( a );
416
        });
417
418
        x_array.sort();
419
        y_array.sort();
420
421
        x = x_array.shift();
422
        y = y_array.shift();
423
424
        if ( !x ) { x = ""; }
425
        if ( !y ) { y = ""; }
426
427
        return ((x < y) ? -1 : ((x > y) ?  1 : 0));
428
};
429
430
jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
431
        var x_array = x.split("<div>");
432
        var y_array = y.split("<div>");
433
434
        /* Pop the first elements, they are empty strings */
435
        x_array.shift();
436
        y_array.shift();
437
438
        x_array = jQuery.map( x_array, function( a ) {
439
            return parse_callnumber( a );
440
        });
441
        y_array = jQuery.map( y_array, function( a ) {
442
            return parse_callnumber( a );
443
        });
444
445
        x_array.sort();
446
        y_array.sort();
447
448
        x = x_array.pop();
449
        y = y_array.pop();
450
451
        if ( !x ) { x = ""; }
452
        if ( !y ) { y = ""; }
453
454
        return ((x < y) ?  1 : ((x > y) ? -1 : 0));
455
};
456
457
function parse_callnumber ( html ) {
458
    var array = html.split('<span class="callnumber">');
459
    if ( array[1] ) {
460
        array = array[1].split('</span>');
461
        return array[0];
462
    } else {
463
        return "";
464
    }
465
}
466
467
// see http://www.datatables.net/examples/advanced_init/footer_callback.html
468
function footer_column_sum( api, column_numbers ) {
469
    // Remove the formatting to get integer data for summation
470
    var intVal = function ( i ) {
471
        if ( typeof i === 'number' ) {
472
            if ( isNaN(i) ) return 0;
473
            return i;
474
        } else if ( typeof i === 'string' ) {
475
            var value = i.replace(/[a-zA-Z ,.]/g, '')*1;
476
            if ( isNaN(value) ) return 0;
477
            return value;
478
        }
479
        return 0;
480
    };
481
482
483
    for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) {
484
        var column_number = column_numbers[indice];
485
486
        var total = 0;
487
        var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount");
488
        $(cells).each(function(){
489
            total += intVal( $(this).html() );
490
        });
491
        total /= 100; // Hard-coded decimal precision
492
493
        // Update footer
494
        $( api.column( column_number ).footer() ).html(total.format_price());
495
    };
496
}
497
498
function filterDataTable( table, column, term ){
499
    if( column ){
500
        table.column( column ).search( term ).draw("page");
501
    } else {
502
        table.search( term ).draw("page");
503
    }
504
}
505
127
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
506
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
128
    console.warn(message);
507
    console.warn(message);
129
};
508
};
130
509
131
(function($) {
510
(function($) {
132
511
133
    $.fn.api = function(options) {
512
    $.fn.api = function(options, columns_settings, add_filters) {
134
        var settings = null;
513
        var settings = null;
135
        if(options) {
514
        if(options) {
136
            if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains';
515
            if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains';
Lines 140-145 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
140
                        "paging": true,
519
                        "paging": true,
141
                        'serverSide': true,
520
                        'serverSide': true,
142
                        'searching': true,
521
                        'searching': true,
522
                        'processing': true,
523
                        'language': {
524
                            'emptyTable': (options.emptyTable) ? options.emptyTable : "No data available in table"
525
                        },
143
                        'pagingType': 'full',
526
                        'pagingType': 'full',
144
                        'ajax': {
527
                        'ajax': {
145
                            'type': 'GET',
528
                            'type': 'GET',
Lines 213-219 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { Link Here
213
                        }
596
                        }
214
                    }, options);
597
                    }, options);
215
        }
598
        }
599
600
        var counter = 0;
601
        var hidden_ids = [];
602
        var included_ids = [];
603
604
        $(columns_settings).each( function() {
605
            var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' );
606
            var used_id = settings.bKohaColumnsUseNames ? named_id : counter;
607
            if ( used_id == -1 ) return;
608
609
            if ( this['is_hidden'] == "1" ) {
610
                hidden_ids.push( used_id );
611
            }
612
            if ( this['cannot_be_toggled'] == "0" ) {
613
                included_ids.push( used_id );
614
            }
615
            counter++;
616
        });
617
618
        var exportColumns = ":visible:not(.noExport)";
619
        if( settings.hasOwnProperty("exportColumns") ){
620
            // A custom buttons configuration has been passed from the page
621
            exportColumns = settings["exportColumns"];
622
        }
623
624
        var export_format = {
625
            body: function ( data, row, column, node ) {
626
                var newnode = $(node);
627
628
                if ( newnode.find(".noExport").length > 0 ) {
629
                    newnode = newnode.clone();
630
                    newnode.find(".noExport").remove();
631
                }
632
633
                return newnode.text().replace( /\n/g, ' ' ).trim();
634
            }
635
        }
636
637
        var export_buttons = [
638
            {
639
                extend: 'excelHtml5',
640
                text: _("Excel"),
641
                exportOptions: {
642
                    columns: exportColumns,
643
                    format:  export_format
644
                },
645
            },
646
            {
647
                extend: 'csvHtml5',
648
                text: _("CSV"),
649
                exportOptions: {
650
                    columns: exportColumns,
651
                    format:  export_format
652
                },
653
            },
654
            {
655
                extend: 'copyHtml5',
656
                text: _("Copy"),
657
                exportOptions: {
658
                    columns: exportColumns,
659
                    format:  export_format
660
                },
661
            },
662
            {
663
                extend: 'print',
664
                text: _("Print"),
665
                exportOptions: {
666
                    columns: exportColumns,
667
                    format:  export_format
668
                },
669
            }
670
        ];
671
672
        settings[ "buttons" ] = [
673
            {
674
                fade: 100,
675
                className: "dt_button_clear_filter",
676
                titleAttr: _("Clear filter"),
677
                enabled: false,
678
                text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
679
                action: function ( e, dt, node, config ) {
680
                    dt.search( "" ).draw("page");
681
                    node.addClass("disabled");
682
                }
683
            }
684
        ];
685
686
        if( included_ids.length > 0 ){
687
            settings[ "buttons" ].push(
688
                {
689
                    extend: 'colvis',
690
                    fade: 100,
691
                    columns: included_ids,
692
                    className: "columns_controls",
693
                    titleAttr: _("Columns settings"),
694
                    text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
695
                    exportOptions: {
696
                        columns: exportColumns
697
                    }
698
                }
699
            );
700
        }
701
702
        settings[ "buttons" ].push(
703
            {
704
                extend: 'collection',
705
                autoClose: true,
706
                fade: 100,
707
                className: "export_controls",
708
                titleAttr: _("Export or print"),
709
                text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>',
710
                buttons: export_buttons
711
            }
712
        );
713
714
        if ( add_filters ) {
715
            // Duplicate the table header row for columnFilter
716
            thead_row = this.find('thead tr');
717
            clone = thead_row.clone().addClass('filters_row');
718
            clone.find("th.NoSort").html('');
719
            thead_row.before(clone);
720
        }
721
722
        $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
723
216
        return $(this).dataTable(settings);
724
        return $(this).dataTable(settings);
217
    };
725
    };
218
726
219
})(jQuery);
727
})(jQuery);
220
- 

Return to bug 25287