Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dijit.form.TimeTextBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dijit.form.TimeTextBox"] = true;
3
dojo.provide("dijit.form.TimeTextBox");
4
 
5
dojo.require("dojo.date");
6
dojo.require("dojo.date.locale");
7
dojo.require("dojo.date.stamp");
8
dojo.require("dijit._TimePicker");
9
dojo.require("dijit.form.ValidationTextBox");
10
 
11
dojo.declare(
12
	"dijit.form.TimeTextBox",
13
	dijit.form.RangeBoundTextBox,
14
	{
15
		// summary:
16
		//		A validating, serializable, range-bound date text box.
17
 
18
		// constraints object: min, max
19
		regExpGen: dojo.date.locale.regexp,
20
		compare: dojo.date.compare,
21
		format: function(/*Date*/ value, /*Object*/ constraints){
22
			if(!value || value.toString() == this._invalid){ return null; }
23
			return dojo.date.locale.format(value, constraints);
24
		},
25
		parse: dojo.date.locale.parse,
26
		serialize: dojo.date.stamp.toISOString,
27
 
28
		value: new Date(""),	// NaN
29
		_invalid: (new Date("")).toString(),	// NaN
30
 
31
		_popupClass: "dijit._TimePicker",
32
 
33
		postMixInProperties: function(){
34
			//dijit.form.RangeBoundTextBox.prototype.postMixInProperties.apply(this, arguments);
35
			this.inherited("postMixInProperties",arguments);
36
			var constraints = this.constraints;
37
			constraints.selector = 'time';
38
			if(typeof constraints.min == "string"){ constraints.min = dojo.date.stamp.fromISOString(constraints.min); }
39
 			if(typeof constraints.max == "string"){ constraints.max = dojo.date.stamp.fromISOString(constraints.max); }
40
		},
41
 
42
		_onFocus: function(/*Event*/ evt){
43
			// summary: open the TimePicker popup
44
			this._open();
45
		},
46
 
47
		setValue: function(/*Date*/ value, /*Boolean, optional*/ priorityChange){
48
			// summary:
49
			//	Sets the date on this textbox
50
			this.inherited('setValue', arguments);
51
			if(this._picker){
52
				// #3948: fix blank date on popup only
53
				if(!value || value.toString() == this._invalid){value=new Date();}
54
				this._picker.setValue(value);
55
			}
56
		},
57
 
58
		_open: function(){
59
			// summary:
60
			//	opens the TimePicker, and sets the onValueSelected value
61
 
62
			if(this.disabled){return;}
63
 
64
			var self = this;
65
 
66
			if(!this._picker){
67
				var popupProto=dojo.getObject(this._popupClass, false);
68
				this._picker = new popupProto({
69
					onValueSelected: function(value){
70
 
71
						self.focus(); // focus the textbox before the popup closes to avoid reopening the popup
72
						setTimeout(dojo.hitch(self, "_close"), 1); // allow focus time to take
73
 
74
						// this will cause InlineEditBox and other handlers to do stuff so make sure it's last
75
						dijit.form.TimeTextBox.superclass.setValue.call(self, value, true);
76
					},
77
					lang: this.lang,
78
					constraints:this.constraints,
79
					isDisabledDate: function(/*Date*/ date){
80
						// summary:
81
						// 	disables dates outside of the min/max of the TimeTextBox
82
						return self.constraints && (dojo.date.compare(self.constraints.min,date) > 0 || dojo.date.compare(self.constraints.max,date) < 0);
83
					}
84
				});
85
				this._picker.setValue(this.getValue() || new Date());
86
			}
87
			if(!this._opened){
88
				dijit.popup.open({
89
					parent: this,
90
					popup: this._picker,
91
					around: this.domNode,
92
					onCancel: dojo.hitch(this, this._close),
93
					onClose: function(){ self._opened=false; }
94
				});
95
				this._opened=true;
96
			}
97
 
98
			dojo.marginBox(this._picker.domNode,{ w:this.domNode.offsetWidth });
99
		},
100
 
101
		_close: function(){
102
			if(this._opened){
103
				dijit.popup.close(this._picker);
104
				this._opened=false;
105
			}
106
		},
107
 
108
		_onBlur: function(){
109
			// summary: called magically when focus has shifted away from this widget and it's dropdown
110
			this._close();
111
			this.inherited('_onBlur', arguments);
112
			// don't focus on <input>.  the user has explicitly focused on something else.
113
		},
114
 
115
		getDisplayedValue:function(){
116
			return this.textbox.value;
117
		},
118
 
119
		setDisplayedValue:function(/*String*/ value){
120
			this.textbox.value=value;
121
		}
122
	}
123
);
124
 
125
}