Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / widgets / form / TimeField.js
index fc89433..73ad77e 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Ext JS Library 3.0.3
+ * Ext JS Library 3.1.0
  * Copyright(c) 2006-2009 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
@@ -24,15 +24,15 @@ Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
     /**\r
      * @cfg {Date/String} minValue\r
      * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string \r
-     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null).\r
+     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).\r
      */\r
-    minValue : null,\r
+    minValue : undefined,\r
     /**\r
      * @cfg {Date/String} maxValue\r
      * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string \r
-     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null).\r
+     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).\r
      */\r
-    maxValue : null,\r
+    maxValue : undefined,\r
     /**\r
      * @cfg {String} minText\r
      * The error text to display when the date in the cell is before minValue (defaults to\r
@@ -84,26 +84,67 @@ Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
 \r
     // private\r
     initComponent : function(){\r
-        if(typeof this.minValue == "string"){\r
-            this.minValue = this.parseDate(this.minValue);\r
+        if(Ext.isDefined(this.minValue)){\r
+            this.setMinValue(this.minValue, true);\r
         }\r
-        if(typeof this.maxValue == "string"){\r
-            this.maxValue = this.parseDate(this.maxValue);\r
+        if(Ext.isDefined(this.maxValue)){\r
+            this.setMaxValue(this.maxValue, true);\r
         }\r
-\r
         if(!this.store){\r
-            var min = this.parseDate(this.minValue) || new Date(this.initDate).clearTime();\r
-            var max = this.parseDate(this.maxValue) || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1);\r
-            var times = [];\r
-            while(min <= max){\r
-                times.push(min.dateFormat(this.format));\r
-                min = min.add('mi', this.increment);\r
-            }\r
-            this.store = times;\r
+            this.generateStore(true);\r
         }\r
         Ext.form.TimeField.superclass.initComponent.call(this);\r
     },\r
+    \r
+    /**\r
+     * Replaces any existing {@link #minValue} with the new time and refreshes the store.\r
+     * @param {Date/String} value The minimum time that can be selected\r
+     */\r
+    setMinValue: function(value, /* private */ initial){\r
+        this.setLimit(value, true, initial);\r
+        return this;\r
+    },\r
+\r
+    /**\r
+     * Replaces any existing {@link #maxValue} with the new time and refreshes the store.\r
+     * @param {Date/String} value The maximum time that can be selected\r
+     */\r
+    setMaxValue: function(value, /* private */ initial){\r
+        this.setLimit(value, false, initial);\r
+        return this;\r
+    },\r
+    \r
+    // private\r
+    generateStore: function(initial){\r
+        var min = this.minValue || new Date(this.initDate).clearTime(),\r
+            max = this.maxValue || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1),\r
+            times = [];\r
+            \r
+        while(min <= max){\r
+            times.push(min.dateFormat(this.format));\r
+            min = min.add('mi', this.increment);\r
+        }\r
+        this.bindStore(times, initial);\r
+    },\r
 \r
+    // private\r
+    setLimit: function(value, isMin, initial){\r
+        var d;\r
+        if(Ext.isString(value)){\r
+            d = this.parseDate(value);\r
+        }else if(Ext.isDate(value)){\r
+            d = value;\r
+        }\r
+        if(d){\r
+            var val = new Date(this.initDate).clearTime();\r
+            val.setHours(d.getHours(), d.getMinutes(), isMin ? 0 : 59, 0);\r
+            this[isMin ? 'minValue' : 'maxValue'] = val;\r
+            if(!initial){\r
+                this.generateStore();\r
+            }\r
+        }\r
+    },\r
+    \r
     // inherited docs\r
     getValue : function(){\r
         var v = Ext.form.TimeField.superclass.getValue.call(this);\r