[Koha-patches] [PATCH] Bug 8428 - can't save contracts

Owen Leonard oleonard at myacpl.org
Thu Aug 23 19:05:35 CEST 2012


When I replaced the old calendar widget with the jQueryUI version
we lost a JavaScript function which is required by a couple of
pages: Date_from_syspref. This patch adds the function back
to the calendar include and corrects variables in the two
affected templates to make it work again.

To test:

- create a new contract. Submitting should work properly and
  without JavaScript errors.
- Open the serials claims page (serials/claims.pl) and filter
  the results by date. Submitting the filter form should
  work properly and without JavaScript errors.
---
 .../intranet-tmpl/prog/en/includes/calendar.inc    |   21 ++++++++++++++++++++
 .../prog/en/modules/admin/aqcontract.tt            |    4 ++--
 .../prog/en/modules/serials/claims.tt              |    4 ++--
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
index d77e9e0..fc8a1a3 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
@@ -1,5 +1,26 @@
 <script type="text/javascript">
 //<![CDATA[
+
+var debug    = "[% debug %]";
+var dformat  = "[% dateformat %]";
+var sentmsg = 0;
+if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");}
+
+function Date_from_syspref(dstring) {
+        var dateX = dstring.split(/[-/]/);
+        if (debug > 1 && sentmsg < 1) {sentmsg++; alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));}
+        if (dformat === "iso") {
+                return new Date(dateX[0], (dateX[1] - 1), dateX[2]);  // YYYY-MM-DD to (YYYY,m(0-11),d)
+        } else if (dformat === "us") {
+                return new Date(dateX[2], (dateX[0] - 1), dateX[1]);  // MM/DD/YYYY to (YYYY,m(0-11),d)
+        } else if (dformat === "metric") {
+                return new Date(dateX[2], (dateX[1] - 1), dateX[0]);  // DD/MM/YYYY to (YYYY,m(0-11),d)
+        } else {
+                if (debug > 0) {alert("KOHA ERROR - Unrecognized date format: " +dformat);}
+                return 0;
+        }
+}
+
 /* Instead of including multiple localization files as you would normally see with
    jQueryUI we expose the localization strings in the default configuration */
 jQuery(function($){
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tt
index 7103971..e723ed4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tt
@@ -22,8 +22,8 @@ function Check(ff) {
         ok=1;
         _alertString += _("- Name missing") + "\n";
     }
-    var startDate = Date_from_syspref($("#contractstartdate").val());
-    var endDate   = Date_from_syspref($("#contractenddate").val());
+    var startDate = Date_from_syspref($("#from").val());
+    var endDate   = Date_from_syspref($("#to").val());
     if (!parseInt(startDate.getTime())) {
         ok=1;
         _alertString += _("- Start date missing or invalid.") + "\n";
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt
index b47b51b..5d9f7a9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tt
@@ -92,8 +92,8 @@
 	}
 	// Filter by date
 	function filterByDate() {
-	    var beginDate = Date_from_syspref($("#begindate").val()).getTime();
-	    var endDate   = Date_from_syspref($("#enddate").val()).getTime();
+        var beginDate = Date_from_syspref($("#from").val()).getTime();
+        var endDate   = Date_from_syspref($("#to").val()).getTime();
 	    
 	    // Checks if the beginning date is valid
 	    if (!parseInt(beginDate)) {
-- 
1.7.9.5



More information about the Koha-patches mailing list