X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/b37ceabb82336ee82757cd32efe353cfab8ec267..f5240829880f87e0cf581c6a296e436fdef0ef80:/examples/calendar/src/widgets/DateRangeField.js diff --git a/examples/calendar/src/widgets/DateRangeField.js b/examples/calendar/src/widgets/DateRangeField.js new file mode 100644 index 00000000..22654ff8 --- /dev/null +++ b/examples/calendar/src/widgets/DateRangeField.js @@ -0,0 +1,284 @@ +/*! + * Ext JS Library 3.3.0 + * Copyright(c) 2006-2010 Ext JS, Inc. + * licensing@extjs.com + * http://www.extjs.com/license + */ +/** + * @class Ext.calendar.DateRangeField + * @extends Ext.form.Field + *
A combination field that includes start and end dates and times, as well as an optional all-day checkbox.
+ * @constructor + * @param {Object} config The config object + */ +Ext.calendar.DateRangeField = Ext.extend(Ext.form.Field, { + /** + * @cfg {String} toText + * The text to display in between the date/time fields (defaults to 'to') + */ + toText: 'to', + /** + * @cfg {String} toText + * The text to display as the label for the all day checkbox (defaults to 'All day') + */ + allDayText: 'All day', + + // private + onRender: function(ct, position) { + if (!this.el) { + this.startDate = new Ext.form.DateField({ + id: this.id + '-start-date', + format: 'n/j/Y', + width: 100, + listeners: { + 'change': { + fn: function() { + this.checkDates('date', 'start'); + }, + scope: this + } + } + }); + this.startTime = new Ext.form.TimeField({ + id: this.id + '-start-time', + hidden: this.showTimes === false, + labelWidth: 0, + hideLabel: true, + width: 90, + listeners: { + 'select': { + fn: function() { + this.checkDates('time', 'start'); + }, + scope: this + } + } + }); + this.endTime = new Ext.form.TimeField({ + id: this.id + '-end-time', + hidden: this.showTimes === false, + labelWidth: 0, + hideLabel: true, + width: 90, + listeners: { + 'select': { + fn: function() { + this.checkDates('time', 'end'); + }, + scope: this + } + } + }); + this.endDate = new Ext.form.DateField({ + id: this.id + '-end-date', + format: 'n/j/Y', + hideLabel: true, + width: 100, + listeners: { + 'change': { + fn: function() { + this.checkDates('date', 'end'); + }, + scope: this + } + } + }); + this.allDay = new Ext.form.Checkbox({ + id: this.id + '-allday', + hidden: this.showTimes === false || this.showAllDay === false, + boxLabel: this.allDayText, + handler: function(chk, checked) { + this.startTime.setVisible(!checked); + this.endTime.setVisible(!checked); + }, + scope: this + }); + this.toLabel = new Ext.form.Label({ + xtype: 'label', + id: this.id + '-to-label', + text: this.toText + }); + + this.fieldCt = new Ext.Container({ + autoEl: { + id: this.id + }, + //make sure the container el has the field's id + cls: 'ext-dt-range', + renderTo: ct, + layout: 'table', + layoutConfig: { + columns: 6 + }, + defaults: { + hideParent: true + }, + items: [ + this.startDate, + this.startTime, + this.toLabel, + this.endTime, + this.endDate, + this.allDay + ] + }); + + this.fieldCt.ownerCt = this; + this.el = this.fieldCt.getEl(); + this.items = new Ext.util.MixedCollection(); + this.items.addAll([this.startDate, this.endDate, this.toLabel, this.startTime, this.endTime, this.allDay]); + } + Ext.calendar.DateRangeField.superclass.onRender.call(this, ct, position); + }, + + // private + checkDates: function(type, startend) { + var startField = Ext.getCmp(this.id + '-start-' + type), + endField = Ext.getCmp(this.id + '-end-' + type), + startValue = this.getDT('start'), + endValue = this.getDT('end'); + + if (startValue > endValue) { + if (startend == 'start') { + endField.setValue(startValue); + } else { + startField.setValue(endValue); + this.checkDates(type, 'start'); + } + } + if (type == 'date') { + this.checkDates('time', startend); + } + }, + + /** + * Returns an array containing the following values in order:DateTime
: DateTime
: Boolean
: Array
: DateTime
: Object
: