3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.calendar.DateRangeField"></div>/**
16 * @class Ext.calendar.DateRangeField
17 * @extends Ext.form.Field
18 * <p>A combination field that includes start and end dates and times, as well as an optional all-day checkbox.</p>
20 * @param {Object} config The config object
22 Ext.calendar.DateRangeField = Ext.extend(Ext.form.Field, {
23 <div id="cfg-Ext.calendar.DateRangeField-toText"></div>/**
24 * @cfg {String} toText
25 * The text to display in between the date/time fields (defaults to 'to')
28 <div id="cfg-Ext.calendar.DateRangeField-toText"></div>/**
29 * @cfg {String} toText
30 * The text to display as the label for the all day checkbox (defaults to 'All day')
32 allDayText: 'All day',
35 onRender: function(ct, position) {
37 this.startDate = new Ext.form.DateField({
38 id: this.id + '-start-date',
44 this.checkDates('date', 'start');
50 this.startTime = new Ext.form.TimeField({
51 id: this.id + '-start-time',
52 hidden: this.showTimes === false,
59 this.checkDates('time', 'start');
65 this.endTime = new Ext.form.TimeField({
66 id: this.id + '-end-time',
67 hidden: this.showTimes === false,
74 this.checkDates('time', 'end');
80 this.endDate = new Ext.form.DateField({
81 id: this.id + '-end-date',
88 this.checkDates('date', 'end');
94 this.allDay = new Ext.form.Checkbox({
95 id: this.id + '-allday',
96 hidden: this.showTimes === false || this.showAllDay === false,
97 boxLabel: this.allDayText,
98 handler: function(chk, checked) {
99 this.startTime.setVisible(!checked);
100 this.endTime.setVisible(!checked);
104 this.toLabel = new Ext.form.Label({
106 id: this.id + '-to-label',
110 this.fieldCt = new Ext.Container({
114 //make sure the container el has the field's id
134 this.fieldCt.ownerCt = this;
135 this.el = this.fieldCt.getEl();
136 this.items = new Ext.util.MixedCollection();
137 this.items.addAll([this.startDate, this.endDate, this.toLabel, this.startTime, this.endTime, this.allDay]);
139 Ext.calendar.DateRangeField.superclass.onRender.call(this, ct, position);
143 checkDates: function(type, startend) {
144 var startField = Ext.getCmp(this.id + '-start-' + type),
145 endField = Ext.getCmp(this.id + '-end-' + type),
146 startValue = this.getDT('start'),
147 endValue = this.getDT('end');
149 if (startValue > endValue) {
150 if (startend == 'start') {
151 endField.setValue(startValue);
153 startField.setValue(endValue);
154 this.checkDates(type, 'start');
157 if (type == 'date') {
158 this.checkDates('time', startend);
162 <div id="method-Ext.calendar.DateRangeField-getValue"></div>/**
163 * Returns an array containing the following values in order:<div class="mdetail-params"><ul>
164 * <li><b><code>DateTime</code></b> : <div class="sub-desc">The start date/time</div></li>
165 * <li><b><code>DateTime</code></b> : <div class="sub-desc">The end date/time</div></li>
166 * <li><b><code>Boolean</code></b> : <div class="sub-desc">True if the dates are all-day, false
167 * if the time values should be used</div></li><ul></div>
168 * @return {Array} The array of return values
170 getValue: function() {
174 this.allDay.getValue()
178 // private getValue helper
179 getDT: function(startend) {
180 var time = this[startend + 'Time'].getValue(),
181 dt = this[startend + 'Date'].getValue();
183 if (Ext.isDate(dt)) {
184 dt = dt.format(this[startend + 'Date'].format);
189 if (time != '' && this[startend + 'Time'].isVisible()) {
190 return Date.parseDate(dt + ' ' + time, this[startend + 'Date'].format + ' ' + this[startend + 'Time'].format);
192 return Date.parseDate(dt, this[startend + 'Date'].format);
196 <div id="method-Ext.calendar.DateRangeField-setValue"></div>/**
197 * Sets the values to use in the date range.
198 * @param {Array/Date/Object} v The value(s) to set into the field. Valid types are as follows:<div class="mdetail-params"><ul>
199 * <li><b><code>Array</code></b> : <div class="sub-desc">An array containing, in order, a start date, end date and all-day flag.
200 * This array should exactly match the return type as specified by {@link #getValue}.</div></li>
201 * <li><b><code>DateTime</code></b> : <div class="sub-desc">A single Date object, which will be used for both the start and
202 * end dates in the range. The all-day flag will be defaulted to false.</div></li>
203 * <li><b><code>Object</code></b> : <div class="sub-desc">An object containing properties for StartDate, EndDate and IsAllDay
204 * as defined in {@link Ext.calendar.EventMappings}.</div></li><ul></div>
206 setValue: function(v) {
207 if (Ext.isArray(v)) {
208 this.setDT(v[0], 'start');
209 this.setDT(v[1], 'end');
210 this.allDay.setValue( !! v[2]);
212 else if (Ext.isDate(v)) {
213 this.setDT(v, 'start');
214 this.setDT(v, 'end');
215 this.allDay.setValue(false);
217 else if (v[Ext.calendar.EventMappings.StartDate.name]) {
219 this.setDT(v[Ext.calendar.EventMappings.StartDate.name], 'start');
220 if (!this.setDT(v[Ext.calendar.EventMappings.EndDate.name], 'end')) {
221 this.setDT(v[Ext.calendar.EventMappings.StartDate.name], 'end');
223 this.allDay.setValue( !! v[Ext.calendar.EventMappings.IsAllDay.name]);
227 // private setValue helper
228 setDT: function(dt, startend) {
229 if (dt && Ext.isDate(dt)) {
230 this[startend + 'Date'].setValue(dt);
231 this[startend + 'Time'].setValue(dt.format(this[startend + 'Time'].format));
237 isDirty: function() {
239 if (this.rendered && !this.disabled) {
240 this.items.each(function(item) {
241 if (item.isDirty()) {
251 onDisable: function() {
252 this.delegateFn('disable');
256 onEnable: function() {
257 this.delegateFn('enable');
262 this.delegateFn('reset');
266 delegateFn: function(fn) {
267 this.items.each(function(item) {
275 beforeDestroy: function() {
276 Ext.destroy(this.fieldCt);
277 Ext.calendar.DateRangeField.superclass.beforeDestroy.call(this);
280 <div id="method-Ext.calendar.DateRangeField-getRawValue"></div>/**
281 * @method getRawValue
284 getRawValue: Ext.emptyFn,
285 <div id="method-Ext.calendar.DateRangeField-setRawValue"></div>/**
286 * @method setRawValue
289 setRawValue: Ext.emptyFn
292 Ext.reg('daterangefield', Ext.calendar.DateRangeField);