root / trunk / web / dojo / dijit / form / _DateTimeTextBox.js
History | View | Annotate | Download (4.36 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dijit.form._DateTimeTextBox"]){ |
9 |
dojo._hasResource["dijit.form._DateTimeTextBox"]=true; |
10 |
dojo.provide("dijit.form._DateTimeTextBox");
|
11 |
dojo.require("dojo.date");
|
12 |
dojo.require("dojo.date.locale");
|
13 |
dojo.require("dojo.date.stamp");
|
14 |
dojo.require("dijit.form.ValidationTextBox");
|
15 |
new Date("X"); |
16 |
dojo.declare("dijit.form._DateTimeTextBox",dijit.form.RangeBoundTextBox,{regExpGen:dojo.date.locale.regexp,datePackage:"dojo.date",compare:dojo.date.compare,format:function(_1,_2){ |
17 |
if(!_1){
|
18 |
return ""; |
19 |
} |
20 |
return this.dateLocaleModule.format(_1,_2); |
21 |
},parse:function(_3,_4){ |
22 |
return this.dateLocaleModule.parse(_3,_4)||(this._isEmpty(_3)?null:undefined); |
23 |
},serialize:function(_5,_6){ |
24 |
if(_5.toGregorian){
|
25 |
_5=_5.toGregorian(); |
26 |
} |
27 |
return dojo.date.stamp.toISOString(_5,_6);
|
28 |
},value:new Date(""),_blankValue:null,popupClass:"",_selector:"",constructor:function(_7){ |
29 |
var _8=_7.datePackage?_7.datePackage+".Date":"Date"; |
30 |
this.dateClassObj=dojo.getObject(_8,false); |
31 |
this.value=new this.dateClassObj(""); |
32 |
this.datePackage=_7.datePackage||this.datePackage; |
33 |
this.dateLocaleModule=dojo.getObject(this.datePackage+".locale",false); |
34 |
this.regExpGen=this.dateLocaleModule.regexp; |
35 |
},_setConstraintsAttr:function(_9){ |
36 |
_9.selector=this._selector;
|
37 |
_9.fullYear=true;
|
38 |
var _a=dojo.date.stamp.fromISOString;
|
39 |
if(typeof _9.min=="string"){ |
40 |
_9.min=_a(_9.min); |
41 |
} |
42 |
if(typeof _9.max=="string"){ |
43 |
_9.max=_a(_9.max); |
44 |
} |
45 |
this.inherited(arguments,[_9]); |
46 |
},_onFocus:function(_b){ |
47 |
this._open();
|
48 |
this.inherited(arguments); |
49 |
},_setValueAttr:function(_c,_d,_e){ |
50 |
if(_c!==undefined){ |
51 |
if(!_c||_c.toString()==dijit.form._DateTimeTextBox.prototype.value.toString()){
|
52 |
_c=null;
|
53 |
} |
54 |
if(_c instanceof Date&&!(this.dateClassObj instanceof Date)){ |
55 |
_c=new this.dateClassObj(_c); |
56 |
} |
57 |
} |
58 |
this.inherited(arguments,[_c,_d,_e]); |
59 |
if(this._picker){ |
60 |
if(!_c){
|
61 |
_c=new this.dateClassObj(); |
62 |
} |
63 |
this._picker.set("value",_c); |
64 |
} |
65 |
},_open:function(){ |
66 |
if(this.disabled||this.readOnly||!this.popupClass){ |
67 |
return;
|
68 |
} |
69 |
var _f=this; |
70 |
if(!this._picker){ |
71 |
var _10=dojo.getObject(this.popupClass,false); |
72 |
this._picker=new _10({onValueSelected:function(_11){ |
73 |
if(_f._tabbingAway){
|
74 |
delete _f._tabbingAway;
|
75 |
}else{
|
76 |
_f.focus(); |
77 |
} |
78 |
setTimeout(dojo.hitch(_f,"_close"),1); |
79 |
dijit.form._DateTimeTextBox.superclass._setValueAttr.call(_f,_11,true);
|
80 |
},id:this.id+"_popup",dir:_f.dir,lang:_f.lang,value:this.get("value")||new this.dateClassObj(),constraints:_f.constraints,datePackage:_f.datePackage,isDisabledDate:function(_12){ |
81 |
var _13=dojo.date.compare;
|
82 |
var _14=_f.constraints;
|
83 |
return _14&&((_14.min&&_13(_14.min,_12,_f._selector)>0)||(_14.max&&_13(_14.max,_12,_f._selector)<0)); |
84 |
}}); |
85 |
} |
86 |
if(!this._opened){ |
87 |
dijit.popup.open({parent:this,popup:this._picker,orient:{"BL":"TL","TL":"BL"},around:this.domNode,onCancel:dojo.hitch(this,this._close),onClose:function(){ |
88 |
_f._opened=false;
|
89 |
}}); |
90 |
this._opened=true; |
91 |
} |
92 |
dojo.marginBox(this._picker.domNode,{w:this.domNode.offsetWidth}); |
93 |
},_close:function(){ |
94 |
if(this._opened){ |
95 |
dijit.popup.close(this._picker);
|
96 |
this._opened=false; |
97 |
} |
98 |
},_onBlur:function(){ |
99 |
this._close();
|
100 |
if(this._picker){ |
101 |
this._picker.destroy();
|
102 |
delete this._picker; |
103 |
} |
104 |
this.inherited(arguments); |
105 |
},_getDisplayedValueAttr:function(){ |
106 |
return this.textbox.value; |
107 |
},_setDisplayedValueAttr:function(_15,_16){ |
108 |
this._setValueAttr(this.parse(_15,this.constraints),_16,_15); |
109 |
},destroy:function(){ |
110 |
if(this._picker){ |
111 |
this._picker.destroy();
|
112 |
delete this._picker; |
113 |
} |
114 |
this.inherited(arguments); |
115 |
},postCreate:function(){ |
116 |
this.inherited(arguments); |
117 |
this.connect(this.focusNode,"onkeypress",this._onKeyPress); |
118 |
this.connect(this.focusNode,"onclick",this._open); |
119 |
},_onKeyPress:function(e){ |
120 |
var p=this._picker,dk=dojo.keys; |
121 |
if(p&&this._opened&&p.handleKey){ |
122 |
if(p.handleKey(e)===false){ |
123 |
return;
|
124 |
} |
125 |
} |
126 |
if(this._opened&&e.charOrCode==dk.ESCAPE&&!(e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){ |
127 |
this._close();
|
128 |
dojo.stopEvent(e); |
129 |
}else{
|
130 |
if(!this._opened&&e.charOrCode==dk.DOWN_ARROW){ |
131 |
this._open();
|
132 |
dojo.stopEvent(e); |
133 |
}else{
|
134 |
if(e.charOrCode===dk.TAB){
|
135 |
this._tabbingAway=true; |
136 |
}else{
|
137 |
if(this._opened&&(e.keyChar||e.charOrCode===dk.BACKSPACE||e.charOrCode==dk.DELETE)){ |
138 |
setTimeout(dojo.hitch(this,function(){ |
139 |
if(this._picker&&this._opened){ |
140 |
dijit.placeOnScreenAroundElement(p.domNode.parentNode,this.domNode,{"BL":"TL","TL":"BL"},p.orient?dojo.hitch(p,"orient"):null); |
141 |
} |
142 |
}),1);
|
143 |
} |
144 |
} |
145 |
} |
146 |
} |
147 |
}}); |
148 |
} |