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