Bug 14424: Admin Help Files for 3.20
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / datatables.js
1 // These default options are for translation but can be used
2 // for any other datatables settings
3 // MSG_DT_* variables comes from datatables-strings.inc
4 // To use it, write:
5 //  $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, {
6 //      // other settings
7 //  } ) );
8 var dataTablesDefaults = {
9     "oLanguage": {
10         "oPaginate": {
11             "sFirst"    : window.MSG_DT_FIRST || "First",
12             "sLast"     : window.MSG_DT_LAST || "Last",
13             "sNext"     : window.MSG_DT_NEXT || "Next",
14             "sPrevious" : window.MSG_DT_PREVIOUS || "Previous"
15         },
16         "sEmptyTable"       : window.MSG_DT_EMPTY_TABLE || "No data available in table",
17         "sInfo"             : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries",
18         "sInfoEmpty"        : window.MSG_DT_INFO_EMPTY || "No entries to show",
19         "sInfoFiltered"     : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)",
20         "sLengthMenu"       : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries",
21         "sLoadingRecords"   : window.MSG_DT_LOADING_RECORDS || "Loading...",
22         "sProcessing"       : window.MSG_DT_PROCESSING || "Processing...",
23         "sSearch"           : window.MSG_DT_SEARCH || "Search:",
24         "sZeroRecords"      : window.MSG_DT_ZERO_RECORDS || "No matching records found"
25     },
26     "sDom": 'C<"top pager"ilpf>tr<"bottom pager"ip>',
27     "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All"]],
28     "iDisplayLength": 20
29 };
30
31
32 // Return an array of string containing the values of a particular column
33 $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
34     // check that we have a column id
35     if ( typeof iColumn == "undefined" ) return new Array();
36     // by default we only wany unique data
37     if ( typeof bUnique == "undefined" ) bUnique = true;
38     // by default we do want to only look at filtered data
39     if ( typeof bFiltered == "undefined" ) bFiltered = true;
40     // by default we do not wany to include empty values
41     if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
42     // list of rows which we're going to loop through
43     var aiRows;
44     // use only filtered rows
45     if (bFiltered == true) aiRows = oSettings.aiDisplay;
46     // use all rows
47     else aiRows = oSettings.aiDisplayMaster; // all row numbers
48
49     // set up data array
50     var asResultData = new Array();
51     for (var i=0,c=aiRows.length; i<c; i++) {
52         iRow = aiRows[i];
53         var aData = this.fnGetData(iRow);
54         var sValue = aData[iColumn];
55         // ignore empty values?
56         if (bIgnoreEmpty == true && sValue.length == 0) continue;
57         // ignore unique values?
58         else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
59         // else push the value onto the result data array
60         else asResultData.push(sValue);
61     }
62     return asResultData;
63 }
64
65 // List of unbind keys (Ctrl, Alt, Direction keys, etc.)
66 // These keys must not launch filtering
67 var blacklist_keys = new Array(0, 16, 17, 18, 37, 38, 39, 40);
68
69 // Set a filtering delay for global search field
70 jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
71     /*
72      * Inputs:      object:oSettings - dataTables settings object - automatically given
73      *              integer:iDelay - delay in milliseconds
74      * Usage:       $('#example').dataTable().fnSetFilteringDelay(250);
75      * Author:      Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
76      * License:     GPL v2 or BSD 3 point style
77      * Contact:     zygimantas.berziunas /AT\ hotmail.com
78      */
79     var
80         _that = this,
81         iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
82
83     this.each( function ( i ) {
84         $.fn.dataTableExt.iApiIndex = i;
85         var
86             $this = this,
87             oTimerId = null,
88             sPreviousSearch = null,
89             anControl = $( 'input', _that.fnSettings().aanFeatures.f );
90
91         anControl.unbind( 'keyup.DT' ).bind( 'keyup.DT', function(event) {
92             var $$this = $this;
93             if (blacklist_keys.indexOf(event.keyCode) != -1) {
94                 return this;
95             }else if ( event.keyCode == '13' ) {
96                 $.fn.dataTableExt.iApiIndex = i;
97                 _that.fnFilter( $(this).val() );
98             } else {
99                 if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
100                     window.clearTimeout(oTimerId);
101                     sPreviousSearch = anControl.val();
102                     oTimerId = window.setTimeout(function() {
103                         $.fn.dataTableExt.iApiIndex = i;
104                         _that.fnFilter( anControl.val() );
105                     }, iDelay);
106                 }
107             }
108         });
109
110         return this;
111     } );
112     return this;
113 }
114
115 // Add a filtering delay on general search and on all input (with a class 'filter')
116 jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay ) {
117     var table = this;
118     this.fnSetFilteringDelay(iDelay);
119     var filterTimerId = null;
120     $(table).find("input."+sClass).keyup(function(event) {
121       if (blacklist_keys.indexOf(event.keyCode) != -1) {
122         return this;
123       }else if ( event.keyCode == '13' ) {
124         table.fnFilter( $(this).val(), $(this).attr('data-column_num') );
125       } else {
126         window.clearTimeout(filterTimerId);
127         var input = this;
128         filterTimerId = window.setTimeout(function() {
129           table.fnFilter($(input).val(), $(input).attr('data-column_num'));
130         }, iDelay);
131       }
132     });
133     $(table).find("select."+sClass).on('change', function() {
134         table.fnFilter($(this).val(), $(this).attr('data-column_num'));
135     });
136 }
137
138 // Useful if you want to filter on dates with 2 inputs (start date and end date)
139 // You have to include calendar.inc to use it
140 function dt_add_rangedate_filter(begindate_id, enddate_id, dateCol) {
141     $.fn.dataTableExt.afnFiltering.push(
142         function( oSettings, aData, iDataIndex ) {
143
144             var beginDate = Date_from_syspref($("#"+begindate_id).val()).getTime();
145             var endDate   = Date_from_syspref($("#"+enddate_id).val()).getTime();
146
147             var data = Date_from_syspref(aData[dateCol]).getTime();
148
149             if ( !parseInt(beginDate) && ! parseInt(endDate) ) {
150                 return true;
151             }
152             else if ( beginDate <= data && !parseInt(endDate) ) {
153                 return true;
154             }
155             else if ( data <= endDate && !parseInt(beginDate) ) {
156                 return true;
157             }
158             else if ( beginDate <= data && data <= endDate) {
159                 return true;
160             }
161             return false;
162         }
163     );
164 }
165
166 // Sorting on html contains
167 // <a href="foo.pl">bar</a> sort on 'bar'
168 function dt_overwrite_html_sorting_localeCompare() {
169     jQuery.fn.dataTableExt.oSort['html-asc']  = function(a,b) {
170         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
171         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
172         if (typeof(a.localeCompare == "function")) {
173            return a.localeCompare(b);
174         } else {
175            return (a > b) ? 1 : ((a < b) ? -1 : 0);
176         }
177     };
178
179     jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
180         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
181         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
182         if(typeof(b.localeCompare == "function")) {
183             return b.localeCompare(a);
184         } else {
185             return (b > a) ? 1 : ((b < a) ? -1 : 0);
186         }
187     };
188
189     jQuery.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
190         var x = a.replace( /<.*?>/g, "" );
191         var y = b.replace( /<.*?>/g, "" );
192         x = parseFloat( x );
193         y = parseFloat( y );
194         return ((x < y) ? -1 : ((x > y) ?  1 : 0));
195     };
196
197     jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
198         var x = a.replace( /<.*?>/g, "" );
199         var y = b.replace( /<.*?>/g, "" );
200         x = parseFloat( x );
201         y = parseFloat( y );
202         return ((x < y) ?  1 : ((x > y) ? -1 : 0));
203     };
204 }
205
206 // Sorting on string without accentued characters
207 function dt_overwrite_string_sorting_localeCompare() {
208     jQuery.fn.dataTableExt.oSort['string-asc']  = function(a,b) {
209         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
210         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
211         if (typeof(a.localeCompare == "function")) {
212            return a.localeCompare(b);
213         } else {
214            return (a > b) ? 1 : ((a < b) ? -1 : 0);
215         }
216     };
217
218     jQuery.fn.dataTableExt.oSort['string-desc'] = function(a,b) {
219         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
220         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
221         if(typeof(b.localeCompare == "function")) {
222             return b.localeCompare(a);
223         } else {
224             return (b > a) ? 1 : ((b < a) ? -1 : 0);
225         }
226     };
227 }
228
229 // Replace a node with a html and js contain.
230 function replace_html( original_node, type ) {
231     switch ( $(original_node).attr('data-type') ) {
232         case "range_dates":
233             var id = $(original_node).attr("data-id");
234             var format = $(original_node).attr("data-format");
235             replace_html_date( original_node, id, format );
236             break;
237         default:
238             alert(_("This node can't be replaced"));
239     }
240 }
241
242 // Replace a node with a "From [date] To [date]" element
243 // Used on tfoot > td
244 function replace_html_date( original_node, id, format ) {
245     var node = $('<span style="white-space:nowrap">' + _("From") + '<input type="text" id="' + id + 'from" readonly="readonly" placeholder=\'' + _("Pick date") + '\' size="7" /><a title="' + _("Delete this filter") + '" style="cursor:pointer" onclick=\'$("#' + id + 'from").val("").change();\' >&times;</a></span><br/><span style="white-space:nowrap">' + _("To") + '<input type="text" id="' + id + 'to" readonly="readonly" placeholder=\'' + _("Pick date") + '\' size="7" /><a title="' + _("Delete this filter") + '" style="cursor:pointer" onclick=\'$("#' + id + 'to").val("").change();\' >&times;</a></span>');
246     $(original_node).replaceWith(node);
247     var script = document.createElement( 'script' );
248     script.type = 'text/javascript';
249     var script_content = "Calendar.setup({";
250     script_content += "    inputField: \"" + id + "from\",";
251     script_content += "    ifFormat: \"" + format + "\",";
252     script_content += "    button: \"" + id + "from\",";
253     script_content += "    onClose: function(){ $(\"#" + id + "from\").change(); this.hide();}";
254     script_content += "  });";
255     script_content += "  Calendar.setup({";
256     script_content += "    inputField: \"" + id + "to\",";
257     script_content += "    ifFormat: \"" + format + "\",";
258     script_content += "    button: \"" + id + "to\",";
259     script_content += "    onClose: function(){ $(\"#" + id + "to\").change(); this.hide();}";
260     script_content += "  });";
261     script.text = script_content;
262     $(original_node).append( script );
263 }
264
265 $.fn.dataTableExt.oPagination.four_button = {
266     /*
267      * Function: oPagination.four_button.fnInit
268      * Purpose:  Initalise dom elements required for pagination with a list of the pages
269      * Returns:  -
270      * Inputs:   object:oSettings - dataTables settings object
271      *           node:nPaging - the DIV which contains this pagination control
272      *           function:fnCallbackDraw - draw function which must be called on update
273      */
274     "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
275     {
276         nFirst = document.createElement( 'span' );
277         nPrevious = document.createElement( 'span' );
278         nNext = document.createElement( 'span' );
279         nLast = document.createElement( 'span' );
280
281         nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
282         nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
283         nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
284         nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
285
286         nFirst.className = "paginate_button first";
287         nPrevious.className = "paginate_button previous";
288         nNext.className="paginate_button next";
289         nLast.className = "paginate_button last";
290
291         nPaging.appendChild( nFirst );
292         nPaging.appendChild( nPrevious );
293         nPaging.appendChild( nNext );
294         nPaging.appendChild( nLast );
295
296         $(nFirst).click( function () {
297             oSettings.oApi._fnPageChange( oSettings, "first" );
298             fnCallbackDraw( oSettings );
299         } );
300
301         $(nPrevious).click( function() {
302             oSettings.oApi._fnPageChange( oSettings, "previous" );
303             fnCallbackDraw( oSettings );
304         } );
305
306         $(nNext).click( function() {
307             oSettings.oApi._fnPageChange( oSettings, "next" );
308             fnCallbackDraw( oSettings );
309         } );
310
311         $(nLast).click( function() {
312             oSettings.oApi._fnPageChange( oSettings, "last" );
313             fnCallbackDraw( oSettings );
314         } );
315
316         /* Disallow text selection */
317         $(nFirst).bind( 'selectstart', function () { return false; } );
318         $(nPrevious).bind( 'selectstart', function () { return false; } );
319         $(nNext).bind( 'selectstart', function () { return false; } );
320         $(nLast).bind( 'selectstart', function () { return false; } );
321     },
322
323     /*
324      * Function: oPagination.four_button.fnUpdate
325      * Purpose:  Update the list of page buttons shows
326      * Returns:  -
327      * Inputs:   object:oSettings - dataTables settings object
328      *           function:fnCallbackDraw - draw function which must be called on update
329      */
330     "fnUpdate": function ( oSettings, fnCallbackDraw )
331     {
332         if ( !oSettings.aanFeatures.p )
333         {
334             return;
335         }
336
337         /* Loop over each instance of the pager */
338         var an = oSettings.aanFeatures.p;
339         for ( var i=0, iLen=an.length ; i<iLen ; i++ )
340         {
341             var buttons = an[i].getElementsByTagName('span');
342             if ( oSettings._iDisplayStart === 0 )
343             {
344                 buttons[0].className = "paginate_disabled_previous";
345                 buttons[1].className = "paginate_disabled_previous";
346             }
347             else
348             {
349                 buttons[0].className = "paginate_enabled_previous";
350                 buttons[1].className = "paginate_enabled_previous";
351             }
352
353             if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
354             {
355                 buttons[2].className = "paginate_disabled_next";
356                 buttons[3].className = "paginate_disabled_next";
357             }
358             else
359             {
360                 buttons[2].className = "paginate_enabled_next";
361                 buttons[3].className = "paginate_enabled_next";
362             }
363         }
364     }
365 };
366
367 $.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
368     var x = a.replace( /<.*?>/g, "" );
369     var y = b.replace( /<.*?>/g, "" );
370     x = parseFloat( x );
371     y = parseFloat( y );
372     return ((x < y) ? -1 : ((x > y) ?  1 : 0));
373 };
374
375 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
376     var x = a.replace( /<.*?>/g, "" );
377     var y = b.replace( /<.*?>/g, "" );
378     x = parseFloat( x );
379     y = parseFloat( y );
380     return ((x < y) ?  1 : ((x > y) ? -1 : 0));
381 };
382
383 (function() {
384
385 /*
386  * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
387  * Author: Jim Palmer (based on chunking idea from Dave Koelle)
388  * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
389  * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
390  */
391 function naturalSort (a, b) {
392     var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
393         sre = /(^[ ]*|[ ]*$)/g,
394         dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
395         hre = /^0x[0-9a-f]+$/i,
396         ore = /^0/,
397         // convert all to strings and trim()
398         x = a.toString().replace(sre, '') || '',
399         y = b.toString().replace(sre, '') || '',
400         // chunk/tokenize
401         xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
402         yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
403         // numeric, hex or date detection
404         xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
405         yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
406     // first try and sort Hex codes or Dates
407     if (yD)
408         if ( xD < yD ) return -1;
409         else if ( xD > yD )  return 1;
410     // natural sorting through split numeric strings and default strings
411     for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
412         // find floats not starting with '0', string or 0 if not defined (Clint Priest)
413         var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
414         var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
415         // handle numeric vs string comparison - number < string - (Kyle Adams)
416         if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
417         // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
418         else if (typeof oFxNcL !== typeof oFyNcL) {
419             oFxNcL += '';
420             oFyNcL += '';
421         }
422         if (oFxNcL < oFyNcL) return -1;
423         if (oFxNcL > oFyNcL) return 1;
424     }
425     return 0;
426 }
427
428 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
429     "natural-asc": function ( a, b ) {
430         return naturalSort(a,b);
431     },
432
433     "natural-desc": function ( a, b ) {
434         return naturalSort(a,b) * -1;
435     }
436 } );
437
438 }());
439
440 /* Plugin to allow sorting on data stored in a span's title attribute
441  *
442  * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
443  *
444  * In DataTables config:
445  *     "aoColumns": [
446  *        { "sType": "title-string" },
447  *      ]
448  * http://datatables.net/plug-ins/sorting#hidden_title_string
449  */
450 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
451     "title-string-pre": function ( a ) {
452         return a.match(/title="(.*?)"/)[1].toLowerCase();
453     },
454
455     "title-string-asc": function ( a, b ) {
456         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
457     },
458
459     "title-string-desc": function ( a, b ) {
460         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
461     }
462 } );
463
464 /* Plugin to allow sorting on numeric data stored in a span's title attribute
465  *
466  * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
467  *              [% formatted currency %]
468  *     </span></td>
469  *
470  * In DataTables config:
471  *     "aoColumns": [
472  *        { "sType": "title-numeric" },
473  *      ]
474  * http://datatables.net/plug-ins/sorting#hidden_title
475  */
476 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
477     "title-numeric-pre": function ( a ) {
478         var x = a.match(/title="*(-?[0-9\.]+)/)[1];
479         return parseFloat( x );
480     },
481
482     "title-numeric-asc": function ( a, b ) {
483         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
484     },
485
486     "title-numeric-desc": function ( a, b ) {
487         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
488     }
489 } );
490
491 (function() {
492
493     /* Plugin to allow text sorting to ignore articles
494      *
495      * In DataTables config:
496      *     "aoColumns": [
497      *        { "sType": "anti-the" },
498      *      ]
499      * Based on the plugin found here:
500      * http://datatables.net/plug-ins/sorting#anti_the
501      * Modified to exclude HTML tags from sorting
502      * Extended to accept a string of space-separated articles
503      * from a configuration file (in English, "a," "an," and "the")
504      */
505
506     if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
507         var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
508         var rpattern = "";
509         for(i=0;i<articles.length;i++){
510             rpattern += "^" + articles[i] + " ";
511             if(i < articles.length - 1){ rpattern += "|"; }
512         }
513         var re = new RegExp(rpattern, "i");
514     }
515
516     jQuery.extend( jQuery.fn.dataTableExt.oSort, {
517         "anti-the-pre": function ( a ) {
518             var x = String(a).replace( /<[\s\S]*?>/g, "" );
519             var y = x.trim();
520             var z = y.replace(re, "").toLowerCase();
521             return z;
522         },
523
524         "anti-the-asc": function ( a, b ) {
525             return ((a < b) ? -1 : ((a > b) ? 1 : 0));
526         },
527
528         "anti-the-desc": function ( a, b ) {
529             return ((a < b) ? 1 : ((a > b) ? -1 : 0));
530         }
531     });
532
533 }());
534
535 // Remove string between NSB NSB characters
536 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
537     var pattern = new RegExp("\x88.*\x89");
538     a = a.replace(pattern, "");
539     b = b.replace(pattern, "");
540     return (a > b) ? 1 : ((a < b) ? -1 : 0);
541 }
542 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
543     var pattern = new RegExp("\x88.*\x89");
544     a = a.replace(pattern, "");
545     b = b.replace(pattern, "");
546     return (b > a) ? 1 : ((b < a) ? -1 : 0);
547 }
548
549 /* Define two custom functions (asc and desc) for basket callnumber sorting */
550 jQuery.fn.dataTableExt.oSort['callnumbers-asc']  = function(x,y) {
551         var x_array = x.split("<div>");
552         var y_array = y.split("<div>");
553
554         /* Pop the first elements, they are empty strings */
555         x_array.shift();
556         y_array.shift();
557
558         x_array = jQuery.map( x_array, function( a ) {
559             return parse_callnumber( a );
560         });
561         y_array = jQuery.map( y_array, function( a ) {
562             return parse_callnumber( a );
563         });
564
565         x_array.sort();
566         y_array.sort();
567
568         x = x_array.shift();
569         y = y_array.shift();
570
571         if ( !x ) { x = ""; }
572         if ( !y ) { y = ""; }
573
574         return ((x < y) ? -1 : ((x > y) ?  1 : 0));
575 };
576
577 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
578         var x_array = x.split("<div>");
579         var y_array = y.split("<div>");
580
581         /* Pop the first elements, they are empty strings */
582         x_array.shift();
583         y_array.shift();
584
585         x_array = jQuery.map( x_array, function( a ) {
586             return parse_callnumber( a );
587         });
588         y_array = jQuery.map( y_array, function( a ) {
589             return parse_callnumber( a );
590         });
591
592         x_array.sort();
593         y_array.sort();
594
595         x = x_array.pop();
596         y = y_array.pop();
597
598         if ( !x ) { x = ""; }
599         if ( !y ) { y = ""; }
600
601         return ((x < y) ?  1 : ((x > y) ? -1 : 0));
602 };
603
604 function parse_callnumber ( html ) {
605     var array = html.split('<span class="callnumber">');
606     if ( array[1] ) {
607         array = array[1].split('</span>');
608         return array[0];
609     } else {
610         return "";
611     }
612 }
613
614 // see http://www.datatables.net/examples/advanced_init/footer_callback.html
615 function footer_column_sum( api, column_numbers ) {
616     // Remove the formatting to get integer data for summation
617     var intVal = function ( i ) {
618         if ( typeof i === 'number' ) {
619             if ( isNaN(i) ) return 0;
620             return i;
621         } else if ( typeof i === 'string' ) {
622             var value = i.replace(/[a-zA-Z ,.]/g, '')*1;
623             if ( isNaN(value) ) return 0;
624             return value;
625         }
626         return 0;
627     };
628
629
630     for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) {
631         var column_number = column_numbers[indice];
632
633         var total = 0;
634         var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount");
635         $(cells).each(function(){
636             total += intVal( $(this).html() );
637         });
638         total /= 100; // Hard-coded decimal precision
639
640         // Update footer
641         $( api.column( column_number ).footer() ).html(total.format_price());
642     };
643 }