X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=koha-tmpl%2Fintranet-tmpl%2Fprog%2Fen%2Fjs%2Fdatatables.js;h=cc809c1c9a4a756c49e81a7be7b488125ab20b99;hb=b80b8fa40f706b9cade5f6ee39d73e1b1f9616c9;hp=e0cc888f590429698daf4e32ec4b37b584cac1e6;hpb=28646dd55007003300b8c76262c25ab96e04871e;p=koha_fer diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js index e0cc888f59..cc809c1c9a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -23,7 +23,8 @@ var dataTablesDefaults = { "sSearch" : window.MSG_DT_SEARCH || "Search:", "sZeroRecords" : window.MSG_DT_ZERO_RECORDS || "No matching records found" }, - "sDom": '<"top pager"ilpf>t<"bottom pager"ip>' + "sDom": '<"top pager"ilpf>t<"bottom pager"ip>', + "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, window.MSG_DT_ALL || "All"]] }; @@ -115,7 +116,7 @@ jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay var table = this; this.fnSetFilteringDelay(iDelay); var filterTimerId = null; - $("input."+sClass).keyup(function(event) { + $(table).find("input."+sClass).keyup(function(event) { if (blacklist_keys.indexOf(event.keyCode) != -1) { return this; }else if ( event.keyCode == '13' ) { @@ -220,6 +221,22 @@ function dt_overwrite_html_sorting_localeCompare() { return (b > a) ? 1 : ((b < a) ? -1 : 0); } }; + + jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) { + var x = a.replace( /<.*?>/g, "" ); + var y = b.replace( /<.*?>/g, "" ); + x = parseFloat( x ); + y = parseFloat( y ); + return ((x < y) ? -1 : ((x > y) ? 1 : 0)); + }; + + jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) { + var x = a.replace( /<.*?>/g, "" ); + var y = b.replace( /<.*?>/g, "" ); + x = parseFloat( x ); + y = parseFloat( y ); + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); + }; } // Sorting on string without accentued characters @@ -297,10 +314,10 @@ $.fn.dataTableExt.oPagination.four_button = { nNext = document.createElement( 'span' ); nLast = document.createElement( 'span' ); -/* nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) ); + nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) ); nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) ); nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) ); - nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );*/ + nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) ); nFirst.className = "paginate_button first"; nPrevious.className = "paginate_button previous"; @@ -360,25 +377,272 @@ $.fn.dataTableExt.oPagination.four_button = { var buttons = an[i].getElementsByTagName('span'); if ( oSettings._iDisplayStart === 0 ) { - buttons[0].className = "paginate_disabled_first"; + buttons[0].className = "paginate_disabled_previous"; buttons[1].className = "paginate_disabled_previous"; } else { - buttons[0].className = "paginate_enabled_first"; + buttons[0].className = "paginate_enabled_previous"; buttons[1].className = "paginate_enabled_previous"; } if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) { buttons[2].className = "paginate_disabled_next"; - buttons[3].className = "paginate_disabled_last"; + buttons[3].className = "paginate_disabled_next"; } else { buttons[2].className = "paginate_enabled_next"; - buttons[3].className = "paginate_enabled_last"; + buttons[3].className = "paginate_enabled_next"; } } } }; + +$.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) { + var x = a.replace( /<.*?>/g, "" ); + var y = b.replace( /<.*?>/g, "" ); + x = parseFloat( x ); + y = parseFloat( y ); + return ((x < y) ? -1 : ((x > y) ? 1 : 0)); +}; + +$.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) { + var x = a.replace( /<.*?>/g, "" ); + var y = b.replace( /<.*?>/g, "" ); + x = parseFloat( x ); + y = parseFloat( y ); + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); +}; + +(function() { + +/* + * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license + * Author: Jim Palmer (based on chunking idea from Dave Koelle) + * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo + * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js + */ +function naturalSort (a, b) { + var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi, + sre = /(^[ ]*|[ ]*$)/g, + dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/, + hre = /^0x[0-9a-f]+$/i, + ore = /^0/, + // convert all to strings and trim() + x = a.toString().replace(sre, '') || '', + y = b.toString().replace(sre, '') || '', + // chunk/tokenize + xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), + yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), + // numeric, hex or date detection + xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)), + yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null; + // first try and sort Hex codes or Dates + if (yD) + if ( xD < yD ) return -1; + else if ( xD > yD ) return 1; + // natural sorting through split numeric strings and default strings + for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { + // find floats not starting with '0', string or 0 if not defined (Clint Priest) + var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; + var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; + // handle numeric vs string comparison - number < string - (Kyle Adams) + if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1; + // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' + else if (typeof oFxNcL !== typeof oFyNcL) { + oFxNcL += ''; + oFyNcL += ''; + } + if (oFxNcL < oFyNcL) return -1; + if (oFxNcL > oFyNcL) return 1; + } + return 0; +} + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "natural-asc": function ( a, b ) { + return naturalSort(a,b); + }, + + "natural-desc": function ( a, b ) { + return naturalSort(a,b) * -1; + } +} ); + +}()); + +/* Plugin to allow sorting on data stored in a span's title attribute + * + * Ex: [% formatted_date %] + * + * In DataTables config: + * "aoColumns": [ + * { "sType": "title-string" }, + * ] + * http://datatables.net/plug-ins/sorting#hidden_title_string + */ +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "title-string-pre": function ( a ) { + return a.match(/title="(.*?)"/)[1].toLowerCase(); + }, + + "title-string-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "title-string-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} ); + +/* Plugin to allow sorting on numeric data stored in a span's title attribute + * + * Ex: + * [% formatted currency %] + * + * + * In DataTables config: + * "aoColumns": [ + * { "sType": "title-numeric" }, + * ] + * http://datatables.net/plug-ins/sorting#hidden_title + */ +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "title-numeric-pre": function ( a ) { + var x = a.match(/title="*(-?[0-9\.]+)/)[1]; + return parseFloat( x ); + }, + + "title-numeric-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "title-numeric-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} ); + +(function() { + + /* Plugin to allow text sorting to ignore articles + * + * In DataTables config: + * "aoColumns": [ + * { "sType": "anti-the" }, + * ] + * Based on the plugin found here: + * http://datatables.net/plug-ins/sorting#anti_the + * Modified to exclude HTML tags from sorting + * Extended to accept a string of space-separated articles + * from a configuration file (in English, "a," "an," and "the") + */ + + if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){ + var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" "); + var rpattern = ""; + for(i=0;i/g, "" ); + var y = x.trim(); + var z = y.replace(re, "").toLowerCase(); + return z; + }, + + "anti-the-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "anti-the-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } + }); + +}()); + +// Remove string between NSB NSB characters +$.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) { + var pattern = new RegExp("\x88.*\x89"); + a = a.replace(pattern, ""); + b = b.replace(pattern, ""); + return (a > b) ? 1 : ((a < b) ? -1 : 0); +} +$.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) { + var pattern = new RegExp("\x88.*\x89"); + a = a.replace(pattern, ""); + b = b.replace(pattern, ""); + return (b > a) ? 1 : ((b < a) ? -1 : 0); +} + +/* Define two custom functions (asc and desc) for basket callnumber sorting */ +jQuery.fn.dataTableExt.oSort['callnumbers-asc'] = function(x,y) { + var x_array = x.split("
"); + var y_array = y.split("
"); + + /* Pop the first elements, they are empty strings */ + x_array.shift(); + y_array.shift(); + + x_array = jQuery.map( x_array, function( a ) { + return parse_callnumber( a ); + }); + y_array = jQuery.map( y_array, function( a ) { + return parse_callnumber( a ); + }); + + x_array.sort(); + y_array.sort(); + + x = x_array.shift(); + y = y_array.shift(); + + if ( !x ) { x = ""; } + if ( !y ) { y = ""; } + + return ((x < y) ? -1 : ((x > y) ? 1 : 0)); +}; + +jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) { + var x_array = x.split("
"); + var y_array = y.split("
"); + + /* Pop the first elements, they are empty strings */ + x_array.shift(); + y_array.shift(); + + x_array = jQuery.map( x_array, function( a ) { + return parse_callnumber( a ); + }); + y_array = jQuery.map( y_array, function( a ) { + return parse_callnumber( a ); + }); + + x_array.sort(); + y_array.sort(); + + x = x_array.pop(); + y = y_array.pop(); + + if ( !x ) { x = ""; } + if ( !y ) { y = ""; } + + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); +}; + +function parse_callnumber ( html ) { + var array = html.split(''); + if ( array[1] ) { + array = array[1].split(''); + return array[0]; + } else { + return ""; + } +}