Bug 3806 - Holidays table doesn't order by date correcly
authorOwen Leonard <oleonard@myacpl.org>
Tue, 6 Dec 2011 20:09:27 +0000 (15:09 -0500)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 30 Jan 2012 21:25:47 +0000 (22:25 +0100)
Adding dateformat filter to JavaScript tablesorter
configurations.

Follow-up adds a custom date parser for dates without year ("01/10")

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested yearly repeatables under Calendar for all three date formats.

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt

index 19b2309..686e3af 100644 (file)
                newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
        }
        $(document).ready(function() {
+
+[% IF ( dateformat_metric ) %]         $.tablesorter.addParser({ // http://tablesorter.com/docs/example-parsers.html
+                       id: 'shortDates',
+                       is: function(s){
+                               return false;
+                       },
+                       format: function(s){
+                               var datepattern = new RegExp("[0-9]\/[0-9]");
+                               if( datepattern.test(s)){ // sorting a date without a year: "01/12"
+                                       var dateparts = s.split("/").reverse().join("-"); // build an ISO date to be sorted as text
+                                       s = "2000-" + dateparts; // use 2000 as the default year
+                               }
+                               return s;
+                       },
+                       type: 'text'
+               });
+[% END %]
                $(".hint").hide();
                $("#branch").change(function(){
                        changeBranch();
                });
-               $("#holidayexceptions").tablesorter({
+               $("#holidayexceptions").tablesorter({[% IF ( dateformat_metric ) %]
+                 dateFormat: 'uk',[% END %]
                  sortList: [[0,0]], widgets: ['zebra']
                });
-               $("#holidayweeklyrepeatable").tablesorter({
+               $("#holidayweeklyrepeatable").tablesorter({[% IF ( dateformat_metric ) %]
+                 dateFormat: 'uk',[% END %]
                  sortList: [[0,0]], widgets: ['zebra']
                });
-               $("#holidaysyearlyrepeatable").tablesorter({
-                 sortList: [[0,0]], widgets: ['zebra']
+               $("#holidaysyearlyrepeatable").tablesorter({[% IF ( dateformat_metric ) %]
+                       headers : {
+                               0: {
+                                       sorter : 'shortDates'
+                               }
+                       },[% END %]
+                       sortList: [[0,0]], widgets: ['zebra']
                });
-               $("#holidaysunique").tablesorter({
+               $("#holidaysunique").tablesorter({[% IF ( dateformat_metric ) %]
+                 dateFormat: 'uk',[% END %]
                  sortList: [[0,0]], widgets: ['zebra']
                });
                $("a.helptext").click(function(){
 <table id="holidaysyearlyrepeatable">
 <thead>
 <tr>
-  [% IF ( dateformat == 'metric' ) %]
+  [% IF ( dateformat_metric ) %]
   <th class="repeatableyearly">Day/Month</th>
   [% ELSE %]
   <th class="repeatableyearly">Month/Day</th>