raimund@550: Ext.define('Ext.ux.DateTimePicker', { raimund@550: extend: 'Ext.picker.Date', raimund@550: alias: 'widget.datetimepicker', raimund@550: todayText: "Now", raimund@550: timeLabel: 'Time', raimund@550: requires: ['Ext.ux.form.TimePickerField'], raimund@550: raimund@550: initComponent: function() { raimund@550: // keep time part for value raimund@550: var value = this.value || new Date(); raimund@550: this.callParent(); raimund@550: this.value = value; raimund@550: }, raimund@550: onRender: function(container, position) { raimund@550: if(!this.timefield) { raimund@550: this.timefield = Ext.create('Ext.ux.form.TimePickerField', { raimund@550: fieldLabel: this.timeLabel, raimund@550: labelWidth: 40, raimund@550: value: Ext.Date.format(this.value, 'H:i:s') raimund@550: }); raimund@550: } raimund@550: this.timefield.ownerCt = this; raimund@550: this.timefield.on('change', this.timeChange, this); raimund@550: this.callParent(arguments); raimund@550: raimund@550: var table = Ext.get(Ext.DomQuery.selectNode('table', this.el.dom)); raimund@550: var tfEl = Ext.core.DomHelper.insertAfter(table, { raimund@550: tag: 'div', raimund@550: style: 'border:0px;', raimund@550: children: [{ raimund@550: tag: 'div', raimund@550: cls: 'x-datepicker-footer ux-timefield' raimund@550: }] raimund@550: }, true); raimund@550: this.timefield.render(this.el.child('div div.ux-timefield')); raimund@550: raimund@550: var p = this.getEl().parent('div.x-layer'); raimund@550: if(p) { raimund@550: p.setStyle("height", p.getHeight() + 31); raimund@550: } raimund@550: }, raimund@550: // listener 时间域修改, timefield change raimund@550: timeChange: function(tf, time, rawtime) { raimund@550: // if(!this.todayKeyListener) { // before render raimund@550: this.value = this.fillDateTime(this.value); raimund@550: // } else { raimund@550: // this.setValue(this.value); raimund@550: // } raimund@550: }, raimund@550: // @private raimund@550: fillDateTime: function(value) { raimund@550: if(this.timefield) { raimund@550: var rawtime = this.timefield.getRawValue(); raimund@550: value.setHours(rawtime.h); raimund@550: value.setMinutes(rawtime.m); raimund@550: value.setSeconds(rawtime.s); raimund@550: } raimund@550: return value; raimund@550: }, raimund@550: // @private raimund@550: changeTimeFiledValue: function(value) { raimund@550: this.timefield.un('change', this.timeChange, this); raimund@550: this.timefield.setValue(this.value); raimund@550: this.timefield.on('change', this.timeChange, this); raimund@550: }, raimund@550: raimund@550: /* TODO 时间值与输入框绑定, 考虑: 创建this.timeValue 将日期和时间分开保存. */ raimund@550: // overwrite raimund@550: setValue: function(value) { raimund@550: this.value = value; raimund@550: this.changeTimeFiledValue(value); raimund@550: return this.update(this.value); raimund@550: }, raimund@550: // overwrite raimund@550: getValue: function() { raimund@550: return this.fillDateTime(this.value); raimund@550: }, raimund@550: raimund@550: // overwrite : fill time before setValue raimund@550: handleDateClick: function(e, t) { raimund@550: var me = this, raimund@550: handler = me.handler; raimund@550: raimund@550: e.stopEvent(); raimund@550: if(!me.disabled && t.dateValue && !Ext.fly(t.parentNode).hasCls(me.disabledCellCls)) { raimund@550: me.doCancelFocus = me.focusOnSelect === false; raimund@550: me.setValue(this.fillDateTime(new Date(t.dateValue))); // overwrite: fill time before setValue raimund@550: delete me.doCancelFocus; raimund@550: me.fireEvent('select', me, me.value); raimund@550: if(handler) { raimund@550: handler.call(me.scope || me, me, me.value); raimund@550: } raimund@550: me.onSelect(); raimund@550: } raimund@550: }, raimund@550: raimund@550: // overwrite : fill time before setValue raimund@550: selectToday: function() { raimund@550: var me = this, raimund@550: btn = me.todayBtn, raimund@550: handler = me.handler; raimund@550: raimund@550: if(btn && !btn.disabled) { raimund@550: // me.setValue(Ext.Date.clearTime(new Date())); //src raimund@550: me.setValue(new Date());// overwrite: fill time before setValue raimund@550: me.fireEvent('select', me, me.value); raimund@550: if(handler) { raimund@550: handler.call(me.scope || me, me, me.value); raimund@550: } raimund@550: me.onSelect(); raimund@550: } raimund@550: return me; raimund@550: } raimund@550: });