Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.DropdownTimePicker");
13
dojo.provide("dojo.widget.DropdownTimePicker");
12
dojo.require("dojo.widget.*");
14
dojo.require("dojo.widget.*");
13
dojo.require("dojo.widget.DropdownContainer");
15
dojo.require("dojo.widget.DropdownContainer");
14
dojo.require("dojo.widget.TimePicker");
16
dojo.require("dojo.widget.TimePicker");
15
dojo.require("dojo.event.*");
17
dojo.require("dojo.event.*");
16
dojo.require("dojo.html.*");
18
dojo.require("dojo.html.*");
17
dojo.require("dojo.date.format");
19
dojo.require("dojo.date.format");
18
dojo.require("dojo.date.serialize");
20
dojo.require("dojo.date.serialize");
19
dojo.require("dojo.i18n.common");
21
dojo.require("dojo.i18n.common");
20
dojo.requireLocalization("dojo.widget", "DropdownTimePicker", null, "ROOT");
22
dojo.requireLocalization("dojo.widget", "DropdownTimePicker", null, "ROOT");
21
dojo.widget.defineWidget("dojo.widget.DropdownTimePicker", dojo.widget.DropdownContainer, {iconURL:dojo.uri.moduleUri("dojo.widget", "templates/images/timeIcon.gif"), formatLength:"short", displayFormat:"", timeFormat:"", saveFormat:"", value:"", name:"", postMixInProperties:function () {
23
dojo.widget.defineWidget("dojo.widget.DropdownTimePicker", dojo.widget.DropdownContainer, {iconURL:dojo.uri.moduleUri("dojo.widget", "templates/images/timeIcon.gif"), formatLength:"short", displayFormat:"", timeFormat:"", saveFormat:"", value:"", name:"", postMixInProperties:function () {
22
	dojo.widget.DropdownTimePicker.superclass.postMixInProperties.apply(this, arguments);
24
	dojo.widget.DropdownTimePicker.superclass.postMixInProperties.apply(this, arguments);
23
	var messages = dojo.i18n.getLocalization("dojo.widget", "DropdownTimePicker", this.lang);
25
	var messages = dojo.i18n.getLocalization("dojo.widget", "DropdownTimePicker", this.lang);
24
	this.iconAlt = messages.selectTime;
26
	this.iconAlt = messages.selectTime;
25
	if (typeof (this.value) == "string" && this.value.toLowerCase() == "today") {
27
	if (typeof (this.value) == "string" && this.value.toLowerCase() == "today") {
26
		this.value = new Date();
28
		this.value = new Date();
27
	}
29
	}
28
	if (this.value && isNaN(this.value)) {
30
	if (this.value && isNaN(this.value)) {
29
		var orig = this.value;
31
		var orig = this.value;
30
		this.value = dojo.date.fromRfc3339(this.value);
32
		this.value = dojo.date.fromRfc3339(this.value);
31
		if (!this.value) {
33
		if (!this.value) {
32
			var d = dojo.date.format(new Date(), {selector:"dateOnly", datePattern:"yyyy-MM-dd"});
34
			var d = dojo.date.format(new Date(), {selector:"dateOnly", datePattern:"yyyy-MM-dd"});
33
			var c = orig.split(":");
35
			var c = orig.split(":");
34
			for (var i = 0; i < c.length; ++i) {
36
			for (var i = 0; i < c.length; ++i) {
35
				if (c[i].length == 1) {
37
				if (c[i].length == 1) {
36
					c[i] = "0" + c[i];
38
					c[i] = "0" + c[i];
37
				}
39
				}
38
			}
40
			}
39
			orig = c.join(":");
41
			orig = c.join(":");
40
			this.value = dojo.date.fromRfc3339(d + "T" + orig);
42
			this.value = dojo.date.fromRfc3339(d + "T" + orig);
41
			dojo.deprecated("dojo.widget.DropdownTimePicker", "time attributes must be passed in Rfc3339 format", "0.5");
43
			dojo.deprecated("dojo.widget.DropdownTimePicker", "time attributes must be passed in Rfc3339 format", "0.5");
42
		}
44
		}
43
	}
45
	}
44
	if (this.value && !isNaN(this.value)) {
46
	if (this.value && !isNaN(this.value)) {
45
		this.value = new Date(this.value);
47
		this.value = new Date(this.value);
46
	}
48
	}
47
}, fillInTemplate:function () {
49
}, fillInTemplate:function () {
48
	dojo.widget.DropdownTimePicker.superclass.fillInTemplate.apply(this, arguments);
50
	dojo.widget.DropdownTimePicker.superclass.fillInTemplate.apply(this, arguments);
49
	var value = "";
51
	var value = "";
50
	if (this.value instanceof Date) {
52
	if (this.value instanceof Date) {
51
		value = this.value;
53
		value = this.value;
52
	} else {
54
	} else {
53
		if (this.value) {
55
		if (this.value) {
54
			var orig = this.value;
56
			var orig = this.value;
55
			var d = dojo.date.format(new Date(), {selector:"dateOnly", datePattern:"yyyy-MM-dd"});
57
			var d = dojo.date.format(new Date(), {selector:"dateOnly", datePattern:"yyyy-MM-dd"});
56
			var c = orig.split(":");
58
			var c = orig.split(":");
57
			for (var i = 0; i < c.length; ++i) {
59
			for (var i = 0; i < c.length; ++i) {
58
				if (c[i].length == 1) {
60
				if (c[i].length == 1) {
59
					c[i] = "0" + c[i];
61
					c[i] = "0" + c[i];
60
				}
62
				}
61
			}
63
			}
62
			orig = c.join(":");
64
			orig = c.join(":");
63
			value = dojo.date.fromRfc3339(d + "T" + orig);
65
			value = dojo.date.fromRfc3339(d + "T" + orig);
64
		}
66
		}
65
	}
67
	}
66
	var tpArgs = {widgetContainerId:this.widgetId, lang:this.lang, value:value};
68
	var tpArgs = {widgetContainerId:this.widgetId, lang:this.lang, value:value};
67
	this.timePicker = dojo.widget.createWidget("TimePicker", tpArgs, this.containerNode, "child");
69
	this.timePicker = dojo.widget.createWidget("TimePicker", tpArgs, this.containerNode, "child");
68
	dojo.event.connect(this.timePicker, "onValueChanged", this, "_updateText");
70
	dojo.event.connect(this.timePicker, "onValueChanged", this, "_updateText");
69
	if (this.value) {
71
	if (this.value) {
70
		this._updateText();
72
		this._updateText();
71
	}
73
	}
72
	this.containerNode.style.zIndex = this.zIndex;
74
	this.containerNode.style.zIndex = this.zIndex;
73
	this.containerNode.explodeClassName = "timeContainer";
75
	this.containerNode.explodeClassName = "timeContainer";
74
	this.valueNode.name = this.name;
76
	this.valueNode.name = this.name;
75
}, getValue:function () {
77
}, getValue:function () {
76
	return this.valueNode.value;
78
	return this.valueNode.value;
77
}, getTime:function () {
79
}, getTime:function () {
78
	return this.timePicker.storedTime;
80
	return this.timePicker.storedTime;
79
}, setValue:function (rfcDate) {
81
}, setValue:function (rfcDate) {
80
	this.setTime(rfcDate);
82
	this.setTime(rfcDate);
81
}, setTime:function (dateObj) {
83
}, setTime:function (dateObj) {
82
	var value = "";
84
	var value = "";
83
	if (dateObj instanceof Date) {
85
	if (dateObj instanceof Date) {
84
		value = dateObj;
86
		value = dateObj;
85
	} else {
87
	} else {
86
		if (this.value) {
88
		if (this.value) {
87
			var orig = this.value;
89
			var orig = this.value;
88
			var d = dojo.date.format(new Date(), {selector:"dateOnly", datePattern:"yyyy-MM-dd"});
90
			var d = dojo.date.format(new Date(), {selector:"dateOnly", datePattern:"yyyy-MM-dd"});
89
			var c = orig.split(":");
91
			var c = orig.split(":");
90
			for (var i = 0; i < c.length; ++i) {
92
			for (var i = 0; i < c.length; ++i) {
91
				if (c[i].length == 1) {
93
				if (c[i].length == 1) {
92
					c[i] = "0" + c[i];
94
					c[i] = "0" + c[i];
93
				}
95
				}
94
			}
96
			}
95
			orig = c.join(":");
97
			orig = c.join(":");
96
			value = dojo.date.fromRfc3339(d + "T" + orig);
98
			value = dojo.date.fromRfc3339(d + "T" + orig);
97
		}
99
		}
98
	}
100
	}
99
	this.timePicker.setTime(value);
101
	this.timePicker.setTime(value);
100
	this._syncValueNode();
102
	this._syncValueNode();
101
}, _updateText:function () {
103
}, _updateText:function () {
102
	if (this.timePicker.selectedTime.anyTime) {
104
	if (this.timePicker.selectedTime.anyTime) {
103
		this.inputNode.value = "";
105
		this.inputNode.value = "";
104
	} else {
106
	} else {
105
		if (this.timeFormat) {
107
		if (this.timeFormat) {
106
			dojo.deprecated("dojo.widget.DropdownTimePicker", "Must use displayFormat attribute instead of timeFormat.  See dojo.date.format for specification.", "0.5");
108
			dojo.deprecated("dojo.widget.DropdownTimePicker", "Must use displayFormat attribute instead of timeFormat.  See dojo.date.format for specification.", "0.5");
107
			this.inputNode.value = dojo.date.strftime(this.timePicker.time, this.timeFormat, this.lang);
109
			this.inputNode.value = dojo.date.strftime(this.timePicker.time, this.timeFormat, this.lang);
108
		} else {
110
		} else {
109
			this.inputNode.value = dojo.date.format(this.timePicker.time, {formatLength:this.formatLength, timePattern:this.displayFormat, selector:"timeOnly", locale:this.lang});
111
			this.inputNode.value = dojo.date.format(this.timePicker.time, {formatLength:this.formatLength, timePattern:this.displayFormat, selector:"timeOnly", locale:this.lang});
110
		}
112
		}
111
	}
113
	}
112
	this._syncValueNode();
114
	this._syncValueNode();
113
	this.onValueChanged(this.getTime());
115
	this.onValueChanged(this.getTime());
114
	this.hideContainer();
116
	this.hideContainer();
115
}, onValueChanged:function (dateObj) {
117
}, onValueChanged:function (dateObj) {
116
}, onInputChange:function () {
118
}, onInputChange:function () {
117
	if (this.dateFormat) {
119
	if (this.dateFormat) {
118
		dojo.deprecated("dojo.widget.DropdownTimePicker", "Cannot parse user input.  Must use displayFormat attribute instead of dateFormat.  See dojo.date.format for specification.", "0.5");
120
		dojo.deprecated("dojo.widget.DropdownTimePicker", "Cannot parse user input.  Must use displayFormat attribute instead of dateFormat.  See dojo.date.format for specification.", "0.5");
119
	} else {
121
	} else {
120
		var input = dojo.string.trim(this.inputNode.value);
122
		var input = dojo.string.trim(this.inputNode.value);
121
		if (input) {
123
		if (input) {
122
			var inputTime = dojo.date.parse(input, {formatLength:this.formatLength, timePattern:this.displayFormat, selector:"timeOnly", locale:this.lang});
124
			var inputTime = dojo.date.parse(input, {formatLength:this.formatLength, timePattern:this.displayFormat, selector:"timeOnly", locale:this.lang});
123
			if (inputTime) {
125
			if (inputTime) {
124
				this.setTime(inputTime);
126
				this.setTime(inputTime);
125
			}
127
			}
126
		} else {
128
		} else {
127
			this.valueNode.value = input;
129
			this.valueNode.value = input;
128
		}
130
		}
129
	}
131
	}
130
	if (input) {
132
	if (input) {
131
		this._updateText();
133
		this._updateText();
132
	}
134
	}
133
}, _syncValueNode:function () {
135
}, _syncValueNode:function () {
134
	var time = this.timePicker.time;
136
	var time = this.timePicker.time;
135
	var value;
137
	var value;
136
	switch (this.saveFormat.toLowerCase()) {
138
	switch (this.saveFormat.toLowerCase()) {
137
	  case "rfc":
139
	  case "rfc":
138
	  case "iso":
140
	  case "iso":
139
	  case "":
141
	  case "":
140
		value = dojo.date.toRfc3339(time, "timeOnly");
142
		value = dojo.date.toRfc3339(time, "timeOnly");
141
		break;
143
		break;
142
	  case "posix":
144
	  case "posix":
143
	  case "unix":
145
	  case "unix":
144
		value = Number(time);
146
		value = Number(time);
145
		break;
147
		break;
146
	  default:
148
	  default:
147
		value = dojo.date.format(time, {datePattern:this.saveFormat, selector:"timeOnly", locale:this.lang});
149
		value = dojo.date.format(time, {datePattern:this.saveFormat, selector:"timeOnly", locale:this.lang});
148
	}
150
	}
149
	this.valueNode.value = value;
151
	this.valueNode.value = value;
150
}, destroy:function (finalize) {
152
}, destroy:function (finalize) {
151
	this.timePicker.destroy(finalize);
153
	this.timePicker.destroy(finalize);
152
	dojo.widget.DropdownTimePicker.superclass.destroy.apply(this, arguments);
154
	dojo.widget.DropdownTimePicker.superclass.destroy.apply(this, arguments);
153
}});
155
}});
154
 
156