~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/widgets/form/TimeField.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 3.0 RC2
 
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>
 
14
new 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
 * @xtype timefield
 
24
 */
 
25
Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
 
26
    /**
 
27
     * @cfg {Date/String} minValue
 
28
     * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string 
 
29
     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null).
 
30
     */
 
31
    minValue : null,
 
32
    /**
 
33
     * @cfg {Date/String} maxValue
 
34
     * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string 
 
35
     * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to null).
 
36
     */
 
37
    maxValue : null,
 
38
    /**
 
39
     * @cfg {String} minText
 
40
     * The error text to display when the date in the cell is before minValue (defaults to
 
41
     * 'The time in this field must be equal to or after {0}').
 
42
     */
 
43
    minText : "The time in this field must be equal to or after {0}",
 
44
    /**
 
45
     * @cfg {String} maxText
 
46
     * The error text to display when the time is after maxValue (defaults to
 
47
     * 'The time in this field must be equal to or before {0}').
 
48
     */
 
49
    maxText : "The time in this field must be equal to or before {0}",
 
50
    /**
 
51
     * @cfg {String} invalidText
 
52
     * The error text to display when the time in the field is invalid (defaults to
 
53
     * '{value} is not a valid time').
 
54
     */
 
55
    invalidText : "{0} is not a valid time",
 
56
    /**
 
57
     * @cfg {String} format
 
58
     * The default time format string which can be overriden for localization support.  The format must be
 
59
     * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM').  For 24-hour time
 
60
     * format try 'H:i' instead.
 
61
     */
 
62
    format : "g:i A",
 
63
    /**
 
64
     * @cfg {String} altFormats
 
65
     * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
 
66
     * 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').
 
67
     */
 
68
    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",
 
69
    /**
 
70
     * @cfg {Number} increment
 
71
     * The number of minutes between each time value in the list (defaults to 15).
 
72
     */
 
73
    increment: 15,
 
74
 
 
75
    // private override
 
76
    mode: 'local',
 
77
    // private override
 
78
    triggerAction: 'all',
 
79
    // private override
 
80
    typeAhead: false,
 
81
    
 
82
    // private - This is the date to use when generating time values in the absence of either minValue
 
83
    // or maxValue.  Using the current date causes DST issues on DST boundary dates, so this is an 
 
84
    // arbitrary "safe" date that can be any date aside from DST boundary dates.
 
85
    initDate: '1/1/2008',
 
86
 
 
87
    // private
 
88
    initComponent : function(){
 
89
        Ext.form.TimeField.superclass.initComponent.call(this);
 
90
 
 
91
        if(typeof this.minValue == "string"){
 
92
            this.minValue = this.parseDate(this.minValue);
 
93
        }
 
94
        if(typeof this.maxValue == "string"){
 
95
            this.maxValue = this.parseDate(this.maxValue);
 
96
        }
 
97
 
 
98
        if(!this.store){
 
99
            var min = this.parseDate(this.minValue);
 
100
            if(!min){
 
101
                min = new Date(this.initDate).clearTime();
 
102
            }
 
103
            var max = this.parseDate(this.maxValue);
 
104
            if(!max){
 
105
                max = new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1);
 
106
            }
 
107
            var times = [];
 
108
            while(min <= max){
 
109
                times.push([min.dateFormat(this.format)]);
 
110
                min = min.add('mi', this.increment);
 
111
            }
 
112
            this.store = new Ext.data.ArrayStore({
 
113
                fields: ['text'],
 
114
                data : times
 
115
            });
 
116
            this.displayField = 'text';
 
117
        }
 
118
    },
 
119
 
 
120
    // inherited docs
 
121
    getValue : function(){
 
122
        var v = Ext.form.TimeField.superclass.getValue.call(this);
 
123
        return this.formatDate(this.parseDate(v)) || '';
 
124
    },
 
125
 
 
126
    // inherited docs
 
127
    setValue : function(value){
 
128
        return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
 
129
    },
 
130
 
 
131
    // private overrides
 
132
    validateValue : Ext.form.DateField.prototype.validateValue,
 
133
    parseDate : Ext.form.DateField.prototype.parseDate,
 
134
    formatDate : Ext.form.DateField.prototype.formatDate,
 
135
 
 
136
    // private
 
137
    beforeBlur : function(){
 
138
        var v = this.parseDate(this.getRawValue());
 
139
        if(v){
 
140
            this.setValue(v.dateFormat(this.format));
 
141
        }
 
142
        Ext.form.TimeField.superclass.beforeBlur.call(this);
 
143
    }
 
144
 
 
145
    /**
 
146
     * @cfg {Boolean} grow @hide
 
147
     */
 
148
    /**
 
149
     * @cfg {Number} growMin @hide
 
150
     */
 
151
    /**
 
152
     * @cfg {Number} growMax @hide
 
153
     */
 
154
    /**
 
155
     * @hide
 
156
     * @method autoSize
 
157
     */
 
158
});
 
159
Ext.reg('timefield', Ext.form.TimeField);
 
 
b'\\ No newline at end of file'