From 81d460cf6cc62c5c6769596134ef057bc938e53d Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Tue, 6 Dec 2011 15:09:27 -0500
Subject: [PATCH] Bug 3806 - Holidays table doesn't order by date correcly
Content-Type: text/plain; charset="utf-8"

Adding dateformat filter to JavaScript tablesorter
configurations.

Follow-up adds a custom date parser for dates without year ("01/10")
---
 .../prog/en/modules/tools/holidays.tt              |   37 ++++++++++++++++---
 1 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt
index 19b2309..686e3af 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt
@@ -84,20 +84,45 @@
 		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(){
@@ -438,7 +463,7 @@
 <table id="holidaysyearlyrepeatable">
 <thead>
 <tr>
-  [% IF ( dateformat == 'metric' ) %]
+  [% IF ( dateformat_metric ) %]
   <th class="repeatableyearly">Day/Month</th>
   [% ELSE %]
   <th class="repeatableyearly">Month/Day</th>
-- 
1.7.3