Mercurial > lada > lada-client
annotate resources/lib/datetime/UX_DateTimePicker.js @ 565:83c0f476d825
Felder erweitert. Alles was auf weiter Stores zugreift funktioniert noch nicht
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Mon, 09 Mar 2015 17:12:27 +0100 |
parents | b6875e900e3a |
children |
rev | line source |
---|---|
550
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 Ext.define('Ext.ux.DateTimePicker', { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 extend: 'Ext.picker.Date', |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 alias: 'widget.datetimepicker', |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 todayText: "Now", |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 timeLabel: 'Time', |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 requires: ['Ext.ux.form.TimePickerField'], |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 initComponent: function() { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 // keep time part for value |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 var value = this.value || new Date(); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 this.callParent(); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 this.value = value; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 onRender: function(container, position) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 if(!this.timefield) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 this.timefield = Ext.create('Ext.ux.form.TimePickerField', { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 fieldLabel: this.timeLabel, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 labelWidth: 40, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 value: Ext.Date.format(this.value, 'H:i:s') |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 }); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 this.timefield.ownerCt = this; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 this.timefield.on('change', this.timeChange, this); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 this.callParent(arguments); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 var table = Ext.get(Ext.DomQuery.selectNode('table', this.el.dom)); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 var tfEl = Ext.core.DomHelper.insertAfter(table, { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 tag: 'div', |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 style: 'border:0px;', |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 children: [{ |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 tag: 'div', |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 cls: 'x-datepicker-footer ux-timefield' |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 }] |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 }, true); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 this.timefield.render(this.el.child('div div.ux-timefield')); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 var p = this.getEl().parent('div.x-layer'); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 if(p) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 p.setStyle("height", p.getHeight() + 31); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 // listener 时间域修改, timefield change |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 timeChange: function(tf, time, rawtime) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 // if(!this.todayKeyListener) { // before render |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 this.value = this.fillDateTime(this.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 // } else { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 // this.setValue(this.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 // } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 // @private |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 fillDateTime: function(value) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 if(this.timefield) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 var rawtime = this.timefield.getRawValue(); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 value.setHours(rawtime.h); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 value.setMinutes(rawtime.m); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 value.setSeconds(rawtime.s); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 return value; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 // @private |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 changeTimeFiledValue: function(value) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 this.timefield.un('change', this.timeChange, this); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 this.timefield.setValue(this.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 this.timefield.on('change', this.timeChange, this); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 /* TODO 时间值与输入框绑定, 考虑: 创建this.timeValue 将日期和时间分开保存. */ |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 // overwrite |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 setValue: function(value) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 this.value = value; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 this.changeTimeFiledValue(value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 return this.update(this.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 // overwrite |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 getValue: function() { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 return this.fillDateTime(this.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 // overwrite : fill time before setValue |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 handleDateClick: function(e, t) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 var me = this, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 handler = me.handler; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 e.stopEvent(); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 if(!me.disabled && t.dateValue && !Ext.fly(t.parentNode).hasCls(me.disabledCellCls)) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 me.doCancelFocus = me.focusOnSelect === false; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 me.setValue(this.fillDateTime(new Date(t.dateValue))); // overwrite: fill time before setValue |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
88 delete me.doCancelFocus; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
89 me.fireEvent('select', me, me.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
90 if(handler) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 handler.call(me.scope || me, me, me.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 me.onSelect(); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 }, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 // overwrite : fill time before setValue |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 selectToday: function() { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 var me = this, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 btn = me.todayBtn, |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 handler = me.handler; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
102 |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 if(btn && !btn.disabled) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 // me.setValue(Ext.Date.clearTime(new Date())); //src |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 me.setValue(new Date());// overwrite: fill time before setValue |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 me.fireEvent('select', me, me.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 if(handler) { |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 handler.call(me.scope || me, me, me.value); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
110 me.onSelect(); |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 return me; |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 } |
b6875e900e3a
Added datetime library.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 }); |