3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.picker.Time
17 * @extends Ext.view.BoundList
18 * <p>A time picker which provides a list of times from which to choose. This is used by the
19 * {@link Ext.form.field.Time} class to allow browsing and selection of valid times, but could also be used
20 * with other components.</p>
21 * <p>By default, all times starting at midnight and incrementing every 15 minutes will be presented.
22 * This list of available times can be controlled using the {@link #minValue}, {@link #maxValue}, and
23 * {@link #increment} configuration properties. The format of the times presented in the list can be
24 * customized with the {@link #format} config.</p>
25 * <p>To handle when the user selects a time from the list, you can subscribe to the {@link #selectionchange}
28 * {@img Ext.picker.Time/Ext.picker.Time.png Ext.picker.Time component}
31 new Ext.create('Ext.picker.Time', {
33 minValue: Ext.Date.parse('04:30:00 AM', 'h:i:s A'),
34 maxValue: Ext.Date.parse('08:00:00 AM', 'h:i:s A'),
35 renderTo: Ext.getBody()
39 Ext.define('Ext.picker.Time', {
40 extend: 'Ext.view.BoundList',
41 alias: 'widget.timepicker',
42 requires: ['Ext.data.Store', 'Ext.Date'],
45 * @cfg {Date} minValue
46 * The minimum time to be shown in the list of times. This must be a Date object (only the time fields
47 * will be used); no parsing of String values will be done. Defaults to undefined.
51 * @cfg {Date} maxValue
52 * The maximum time to be shown in the list of times. This must be a Date object (only the time fields
53 * will be used); no parsing of String values will be done. Defaults to undefined.
57 * @cfg {Number} increment
58 * The number of minutes between each time value in the list (defaults to 15).
63 * @cfg {String} format
64 * The default time format string which can be overriden for localization support. The format must be
65 * valid according to {@link Ext.Date#parse} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
66 * format try 'H:i' instead.
72 * The field in the implicitly-generated Model objects that gets displayed in the list. This is
73 * an internal field name only and is not useful to change via config.
79 * Year, month, and day that all times will be normalized into internally.
83 componentCls: Ext.baseCSSPrefix + 'timepicker',
90 initComponent: function() {
93 clearTime = dateUtil.clearTime,
94 initDate = me.initDate.join('/');
96 // Set up absolute min and max for the entire day
97 me.absMin = clearTime(new Date(initDate));
98 me.absMax = dateUtil.add(clearTime(new Date(initDate)), 'mi', (24 * 60) - 1);
100 me.store = me.createStore();
107 * Set the {@link #minValue} and update the list of available times. This must be a Date
108 * object (only the time fields will be used); no parsing of String values will be done.
109 * @param {Date} value
111 setMinValue: function(value) {
112 this.minValue = value;
117 * Set the {@link #maxValue} and update the list of available times. This must be a Date
118 * object (only the time fields will be used); no parsing of String values will be done.
119 * @param {Date} value
121 setMaxValue: function(value) {
122 this.maxValue = value;
128 * Sets the year/month/day of the given Date object to the {@link #initDate}, so that only
129 * the time fields are significant. This makes values suitable for time comparison.
132 normalizeDate: function(date) {
133 var initDate = this.initDate;
134 date.setFullYear(initDate[0], initDate[1] - 1, initDate[2]);
139 * Update the list of available times in the list to be constrained within the
140 * {@link #minValue} and {@link #maxValue}.
142 updateList: function() {
144 min = me.normalizeDate(me.minValue || me.absMin),
145 max = me.normalizeDate(me.maxValue || me.absMax);
147 me.store.filterBy(function(record) {
148 var date = record.get('date');
149 return date >= min && date <= max;
155 * Creates the internal {@link Ext.data.Store} that contains the available times. The store
156 * is loaded with all possible times, and it is later filtered to hide those times outside
157 * the minValue/maxValue.
159 createStore: function() {
168 disp: utilDate.dateFormat(min, me.format),
171 min = utilDate.add(min, 'mi', me.increment);
174 return Ext.create('Ext.data.Store', {
175 fields: ['disp', 'date'],