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'>/**
19 </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 Ext.define('Ext.picker.Time', {
43 extend: 'Ext.view.BoundList',
44 alias: 'widget.timepicker',
45 requires: ['Ext.data.Store', 'Ext.Date'],
47 <span id='Ext-picker-Time-cfg-minValue'> /**
48 </span> * @cfg {Date} minValue
49 * The minimum time to be shown in the list of times. This must be a Date object (only the time fields
50 * will be used); no parsing of String values will be done. Defaults to undefined.
53 <span id='Ext-picker-Time-cfg-maxValue'> /**
54 </span> * @cfg {Date} maxValue
55 * The maximum time to be shown in the list of times. This must be a Date object (only the time fields
56 * will be used); no parsing of String values will be done. Defaults to undefined.
59 <span id='Ext-picker-Time-cfg-increment'> /**
60 </span> * @cfg {Number} increment
61 * The number of minutes between each time value in the list (defaults to 15).
65 <span id='Ext-picker-Time-cfg-format'> /**
66 </span> * @cfg {String} format
67 * The default time format string which can be overriden for localization support. The format must be
68 * valid according to {@link Ext.Date#parse} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
69 * format try 'H:i' instead.
71 format : "g:i A",
73 <span id='Ext-picker-Time-property-displayField'> /**
75 * The field in the implicitly-generated Model objects that gets displayed in the list. This is
76 * an internal field name only and is not useful to change via config.
80 <span id='Ext-picker-Time-property-initDate'> /**
82 * Year, month, and day that all times will be normalized into internally.
86 componentCls: Ext.baseCSSPrefix + 'timepicker',
88 <span id='Ext-picker-Time-property-loadMask'> /**
93 initComponent: function() {
96 clearTime = dateUtil.clearTime,
97 initDate = me.initDate.join('/');
99 // Set up absolute min and max for the entire day
100 me.absMin = clearTime(new Date(initDate));
101 me.absMax = dateUtil.add(clearTime(new Date(initDate)), 'mi', (24 * 60) - 1);
103 me.store = me.createStore();
109 <span id='Ext-picker-Time-method-setMinValue'> /**
110 </span> * Set the {@link #minValue} and update the list of available times. This must be a Date
111 * object (only the time fields will be used); no parsing of String values will be done.
112 * @param {Date} value
114 setMinValue: function(value) {
115 this.minValue = value;
119 <span id='Ext-picker-Time-method-setMaxValue'> /**
120 </span> * Set the {@link #maxValue} and update the list of available times. This must be a Date
121 * object (only the time fields will be used); no parsing of String values will be done.
122 * @param {Date} value
124 setMaxValue: function(value) {
125 this.maxValue = value;
129 <span id='Ext-picker-Time-method-normalizeDate'> /**
131 * Sets the year/month/day of the given Date object to the {@link #initDate}, so that only
132 * the time fields are significant. This makes values suitable for time comparison.
135 normalizeDate: function(date) {
136 var initDate = this.initDate;
137 date.setFullYear(initDate[0], initDate[1] - 1, initDate[2]);
141 <span id='Ext-picker-Time-method-updateList'> /**
142 </span> * Update the list of available times in the list to be constrained within the
143 * {@link #minValue} and {@link #maxValue}.
145 updateList: function() {
147 min = me.normalizeDate(me.minValue || me.absMin),
148 max = me.normalizeDate(me.maxValue || me.absMax);
150 me.store.filterBy(function(record) {
151 var date = record.get('date');
152 return date >= min && date <= max;
156 <span id='Ext-picker-Time-method-createStore'> /**
158 * Creates the internal {@link Ext.data.Store} that contains the available times. The store
159 * is loaded with all possible times, and it is later filtered to hide those times outside
160 * the minValue/maxValue.
162 createStore: function() {
169 while(min <= max){
171 disp: utilDate.dateFormat(min, me.format),
174 min = utilDate.add(min, 'mi', me.increment);
177 return Ext.create('Ext.data.Store', {
178 fields: ['disp', 'date'],