4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-picker-Time-method-constructor'><span id='Ext-picker-Time'>/**
19 </span></span> * @class Ext.picker.Time
20 * @extends Ext.view.BoundList
21 * <p>A time picker which provides a list of times from which to choose. This is used by the
22 * {@link Ext.form.field.Time} class to allow browsing and selection of valid times, but could also be used
23 * with other components.</p>
24 * <p>By default, all times starting at midnight and incrementing every 15 minutes will be presented.
25 * This list of available times can be controlled using the {@link #minValue}, {@link #maxValue}, and
26 * {@link #increment} configuration properties. The format of the times presented in the list can be
27 * customized with the {@link #format} config.</p>
28 * <p>To handle when the user selects a time from the list, you can subscribe to the {@link #selectionchange}
31 * {@img Ext.picker.Time/Ext.picker.Time.png Ext.picker.Time component}
34 new Ext.create('Ext.picker.Time', {
36 minValue: Ext.Date.parse('04:30:00 AM', 'h:i:s A'),
37 maxValue: Ext.Date.parse('08:00:00 AM', 'h:i:s A'),
38 renderTo: Ext.getBody()
42 * Create a new TimePicker
43 * @param {Object} config The config object
47 Ext.define('Ext.picker.Time', {
48 extend: 'Ext.view.BoundList',
49 alias: 'widget.timepicker',
50 requires: ['Ext.data.Store', 'Ext.Date'],
52 <span id='Ext-picker-Time-cfg-minValue'> /**
53 </span> * @cfg {Date} minValue
54 * The minimum time to be shown in the list of times. This must be a Date object (only the time fields
55 * will be used); no parsing of String values will be done. Defaults to undefined.
58 <span id='Ext-picker-Time-cfg-maxValue'> /**
59 </span> * @cfg {Date} maxValue
60 * The maximum time to be shown in the list of times. This must be a Date object (only the time fields
61 * will be used); no parsing of String values will be done. Defaults to undefined.
64 <span id='Ext-picker-Time-cfg-increment'> /**
65 </span> * @cfg {Number} increment
66 * The number of minutes between each time value in the list (defaults to 15).
70 <span id='Ext-picker-Time-cfg-format'> /**
71 </span> * @cfg {String} format
72 * The default time format string which can be overriden for localization support. The format must be
73 * valid according to {@link Ext.Date#parse} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
74 * format try 'H:i' instead.
76 format : "g:i A",
78 <span id='Ext-picker-Time-property-displayField'> /**
80 * The field in the implicitly-generated Model objects that gets displayed in the list. This is
81 * an internal field name only and is not useful to change via config.
85 <span id='Ext-picker-Time-property-initDate'> /**
87 * Year, month, and day that all times will be normalized into internally.
91 componentCls: Ext.baseCSSPrefix + 'timepicker',
93 <span id='Ext-picker-Time-property-loadingText'> /**
98 initComponent: function() {
101 clearTime = dateUtil.clearTime,
102 initDate = me.initDate.join('/');
104 // Set up absolute min and max for the entire day
105 me.absMin = clearTime(new Date(initDate));
106 me.absMax = dateUtil.add(clearTime(new Date(initDate)), 'mi', (24 * 60) - 1);
108 me.store = me.createStore();
114 <span id='Ext-picker-Time-method-setMinValue'> /**
115 </span> * Set the {@link #minValue} and update the list of available times. This must be a Date
116 * object (only the time fields will be used); no parsing of String values will be done.
117 * @param {Date} value
119 setMinValue: function(value) {
120 this.minValue = value;
124 <span id='Ext-picker-Time-method-setMaxValue'> /**
125 </span> * Set the {@link #maxValue} and update the list of available times. This must be a Date
126 * object (only the time fields will be used); no parsing of String values will be done.
127 * @param {Date} value
129 setMaxValue: function(value) {
130 this.maxValue = value;
134 <span id='Ext-picker-Time-method-normalizeDate'> /**
136 * Sets the year/month/day of the given Date object to the {@link #initDate}, so that only
137 * the time fields are significant. This makes values suitable for time comparison.
140 normalizeDate: function(date) {
141 var initDate = this.initDate;
142 date.setFullYear(initDate[0], initDate[1] - 1, initDate[2]);
146 <span id='Ext-picker-Time-method-updateList'> /**
147 </span> * Update the list of available times in the list to be constrained within the
148 * {@link #minValue} and {@link #maxValue}.
150 updateList: function() {
152 min = me.normalizeDate(me.minValue || me.absMin),
153 max = me.normalizeDate(me.maxValue || me.absMax);
155 me.store.filterBy(function(record) {
156 var date = record.get('date');
157 return date >= min && date <= max;
161 <span id='Ext-picker-Time-method-createStore'> /**
163 * Creates the internal {@link Ext.data.Store} that contains the available times. The store
164 * is loaded with all possible times, and it is later filtered to hide those times outside
165 * the minValue/maxValue.
167 createStore: function() {
174 while(min <= max){
176 disp: utilDate.dateFormat(min, me.format),
179 min = utilDate.add(min, 'mi', me.increment);
182 return Ext.create('Ext.data.Store', {
183 fields: ['disp', 'date'],