[open-ils-commits] r19126 - in branches/rel_1_6/Open-ILS/web/js/dojo/openils: . widget (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jan 5 16:54:44 EST 2011


Author: phasefx
Date: 2011-01-05 16:54:39 -0500 (Wed, 05 Jan 2011)
New Revision: 19126

Modified:
   branches/rel_1_6/Open-ILS/web/js/dojo/openils/Util.js
   branches/rel_1_6/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Log:
backporting r16742,r17492 for proper dojo timestamp handling

Modified: branches/rel_1_6/Open-ILS/web/js/dojo/openils/Util.js
===================================================================
--- branches/rel_1_6/Open-ILS/web/js/dojo/openils/Util.js	2011-01-05 19:31:13 UTC (rev 19125)
+++ branches/rel_1_6/Open-ILS/web/js/dojo/openils/Util.js	2011-01-05 21:54:39 UTC (rev 19126)
@@ -26,7 +26,32 @@
     dojo.declare('openils.Util', null, {});
 
 
+    openils.Util.timeStampRegexp =
+        /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+-]\d{2})(\d{2})$/;
+
+    openils.Util.timeStampAsDateObj = function(s) {
+        if (s.constructor.name == "Date") return s;
+        return dojo.date.stamp.fromISOString(
+            s.replace(openils.Util.timeStampRegexp, "$1:$2")
+        );
+    }
+
     /**
+     * Returns a locale-appropriate representation of a timestamp when the
+     * timestamp (first argument) is actually a string as provided by
+     * fieldmapper objects.
+     * The second argument is an optional argument that will be provided
+     * as the second argument to dojo.date.locale.format()
+     */
+    openils.Util.timeStamp = function(s, opts) {
+        if (typeof(opts) == "undefined") opts = {};
+
+        return dojo.date.locale.format(
+            openils.Util.timeStampAsDateObj(s), opts
+        );
+    };
+
+    /**
      * Wrapper for dojo.addOnLoad that verifies a valid login session is active
      * before adding the function to the onload set
      */

Modified: branches/rel_1_6/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
===================================================================
--- branches/rel_1_6/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2011-01-05 19:31:13 UTC (rev 19125)
+++ branches/rel_1_6/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2011-01-05 21:54:39 UTC (rev 19126)
@@ -144,10 +144,9 @@
                     }
                 case 'timestamp':
                     if (!value) return '';
-                    dojo.require('dojo.date.locale');
-                    dojo.require('dojo.date.stamp');
-                    var date = dojo.date.stamp.fromISOString(value);
-                    return dojo.date.locale.format(date, {formatLength:'short'});
+                    return openils.Util.timeStamp(
+                        value, {"formatLength": "short"}
+                    );
                 case 'org_unit':
                     if(value === null || value === undefined) return '';
                     return fieldmapper.aou.findOrgUnit(value).shortname();
@@ -223,8 +222,11 @@
                         dojo.require('dijit.form.DateTextBox');
                         dojo.require('dojo.date.stamp');
                         this.widget = new dijit.form.DateTextBox(this.dijitArgs, this.parentNode);
-                        if(this.widgetValue != null) 
-                            this.widgetValue = dojo.date.stamp.fromISOString(this.widgetValue);
+                        if (this.widgetValue != null) {
+                            this.widgetValue = openils.Util.timeStampAsDateObj(
+                                this.widgetValue
+                            );
+                        }
                         break;
 
                     case 'bool':



More information about the open-ils-commits mailing list