source: trunk/web/addons/job_monarch/lib/extjs/source/widgets/form/TimeField.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 5.2 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9/**
10 * @class Ext.form.TimeField
11 * @extends Ext.form.ComboBox
12 * Provides a time input field with a time dropdown and automatic time validation.  Example usage:
13 * <pre><code>
14new Ext.form.TimeField({
15    minValue: '9:00 AM',
16    maxValue: '6:00 PM',
17    increment: 30
18});
19</code></pre>
20 * @constructor
21 * Create a new TimeField
22 * @param {Object} config
23 */
24Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
25    /**
26     * @cfg {Date/String} minValue
27     * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string
28     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null).
29     */
30    minValue : null,
31    /**
32     * @cfg {Date/String} maxValue
33     * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string
34     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null).
35     */
36    maxValue : null,
37    /**
38     * @cfg {String} minText
39     * The error text to display when the date in the cell is before minValue (defaults to
40     * 'The time in this field must be equal to or after {0}').
41     */
42    minText : "The time in this field must be equal to or after {0}",
43    /**
44     * @cfg {String} maxText
45     * The error text to display when the time is after maxValue (defaults to
46     * 'The time in this field must be equal to or before {0}').
47     */
48    maxText : "The time in this field must be equal to or before {0}",
49    /**
50     * @cfg {String} invalidText
51     * The error text to display when the time in the field is invalid (defaults to
52     * '{value} is not a valid time').
53     */
54    invalidText : "{0} is not a valid time",
55    /**
56     * @cfg {String} format
57     * The default time format string which can be overriden for localization support.  The format must be
58     * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM').  For 24-hour time
59     * format try 'H:i' instead.
60     */
61    format : "g:i A",
62    /**
63     * @cfg {String} altFormats
64     * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
65     * format (defaults to 'g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H').
66     */
67    altFormats : "g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H",
68    /**
69     * @cfg {Number} increment
70     * The number of minutes between each time value in the list (defaults to 15).
71     */
72    increment: 15,
73
74    // private override
75    mode: 'local',
76    // private override
77    triggerAction: 'all',
78    // private override
79    typeAhead: false,
80   
81    // private - This is the date to use when generating time values in the absence of either minValue
82    // or maxValue.  Using the current date causes DST issues on DST boundary dates, so this is an
83    // arbitrary "safe" date that can be any date aside from DST boundary dates.
84    initDate: '1/1/2008',
85
86    // private
87    initComponent : function(){
88        Ext.form.TimeField.superclass.initComponent.call(this);
89
90        if(typeof this.minValue == "string"){
91            this.minValue = this.parseDate(this.minValue);
92        }
93        if(typeof this.maxValue == "string"){
94            this.maxValue = this.parseDate(this.maxValue);
95        }
96
97        if(!this.store){
98            var min = this.parseDate(this.minValue);
99            if(!min){
100                min = new Date(this.initDate).clearTime();
101            }
102            var max = this.parseDate(this.maxValue);
103            if(!max){
104                max = new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1);
105            }
106            var times = [];
107            while(min <= max){
108                times.push([min.dateFormat(this.format)]);
109                min = min.add('mi', this.increment);
110            }
111            this.store = new Ext.data.SimpleStore({
112                fields: ['text'],
113                data : times
114            });
115            this.displayField = 'text';
116        }
117    },
118
119    // inherited docs
120    getValue : function(){
121        var v = Ext.form.TimeField.superclass.getValue.call(this);
122        return this.formatDate(this.parseDate(v)) || '';
123    },
124
125    // inherited docs
126    setValue : function(value){
127        Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
128    },
129
130    // private overrides
131    validateValue : Ext.form.DateField.prototype.validateValue,
132    parseDate : Ext.form.DateField.prototype.parseDate,
133    formatDate : Ext.form.DateField.prototype.formatDate,
134
135    // private
136    beforeBlur : function(){
137        var v = this.parseDate(this.getRawValue());
138        if(v){
139            this.setValue(v.dateFormat(this.format));
140        }
141    }
142
143    /**
144     * @cfg {Boolean} grow @hide
145     */
146    /**
147     * @cfg {Number} growMin @hide
148     */
149    /**
150     * @cfg {Number} growMax @hide
151     */
152    /**
153     * @hide
154     * @method autoSize
155     */
156});
157Ext.reg('timefield', Ext.form.TimeField);
Note: See TracBrowser for help on using the repository browser.