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 * A time picker which provides a list of times from which to choose. This is used by the Ext.form.field.Time
17 * class to allow browsing and selection of valid times, but could also be used with other components.
19 * By default, all times starting at midnight and incrementing every 15 minutes will be presented. This list of
20 * available times can be controlled using the {@link #minValue}, {@link #maxValue}, and {@link #increment}
21 * configuration properties. The format of the times presented in the list can be customized with the {@link #format}
24 * To handle when the user selects a time from the list, you can subscribe to the {@link #selectionchange} event.
27 * Ext.create('Ext.picker.Time', {
29 * minValue: Ext.Date.parse('04:30:00 AM', 'h:i:s A'),
30 * maxValue: Ext.Date.parse('08:00:00 AM', 'h:i:s A'),
31 * renderTo: Ext.getBody()
34 Ext.define('Ext.picker.Time', {
35 extend: 'Ext.view.BoundList',
36 alias: 'widget.timepicker',
37 requires: ['Ext.data.Store', 'Ext.Date'],
40 * @cfg {Date} minValue
41 * The minimum time to be shown in the list of times. This must be a Date object (only the time fields will be
42 * used); no parsing of String values will be done.
46 * @cfg {Date} maxValue
47 * The maximum time to be shown in the list of times. This must be a Date object (only the time fields will be
48 * used); no parsing of String values will be done.
52 * @cfg {Number} increment
53 * The number of minutes between each time value in the list.
58 * @cfg {String} format
59 * The default time format string which can be overriden for localization support. The format must be valid
60 * according to {@link Ext.Date#parse} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time format try 'H:i'
67 * The field in the implicitly-generated Model objects that gets displayed in the list. This is
68 * an internal field name only and is not useful to change via config.
74 * Year, month, and day that all times will be normalized into internally.
78 componentCls: Ext.baseCSSPrefix + 'timepicker',
85 initComponent: function() {
88 clearTime = dateUtil.clearTime,
89 initDate = me.initDate;
91 // Set up absolute min and max for the entire day
92 me.absMin = clearTime(new Date(initDate[0], initDate[1], initDate[2]));
93 me.absMax = dateUtil.add(clearTime(new Date(initDate[0], initDate[1], initDate[2])), 'mi', (24 * 60) - 1);
95 me.store = me.createStore();
102 * Set the {@link #minValue} and update the list of available times. This must be a Date object (only the time
103 * fields will be used); no parsing of String values will be done.
104 * @param {Date} value
106 setMinValue: function(value) {
107 this.minValue = value;
112 * Set the {@link #maxValue} and update the list of available times. This must be a Date object (only the time
113 * fields will be used); no parsing of String values will be done.
114 * @param {Date} value
116 setMaxValue: function(value) {
117 this.maxValue = value;
123 * Sets the year/month/day of the given Date object to the {@link #initDate}, so that only
124 * the time fields are significant. This makes values suitable for time comparison.
127 normalizeDate: function(date) {
128 var initDate = this.initDate;
129 date.setFullYear(initDate[0], initDate[1], initDate[2]);
134 * Update the list of available times in the list to be constrained within the {@link #minValue}
135 * and {@link #maxValue}.
137 updateList: function() {
139 min = me.normalizeDate(me.minValue || me.absMin),
140 max = me.normalizeDate(me.maxValue || me.absMax);
142 me.store.filterBy(function(record) {
143 var date = record.get('date');
144 return date >= min && date <= max;
150 * Creates the internal {@link Ext.data.Store} that contains the available times. The store
151 * is loaded with all possible times, and it is later filtered to hide those times outside
152 * the minValue/maxValue.
154 createStore: function() {
163 disp: utilDate.dateFormat(min, me.format),
166 min = utilDate.add(min, 'mi', me.increment);
169 return Ext.create('Ext.data.Store', {
170 fields: ['disp', 'date'],