Subversion Repositories Applications.papyrus

Rev

Rev 1422 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
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:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.TimePicker");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.widget.HtmlWidget");
16
dojo.require("dojo.event.*");
17
dojo.require("dojo.date.serialize");
18
dojo.require("dojo.date.format");
19
dojo.require("dojo.dom");
20
dojo.require("dojo.html.style");
1422 alexandre_ 21
dojo.requireLocalization("dojo.i18n.calendar", "gregorian", null, "ko,zh-cn,zh,sv,ja,en,zh-tw,it,hu,nl,fi,zh-hk,fr,pt,ROOT,es,de,pt-br");
1318 alexandre_ 22
dojo.requireLocalization("dojo.widget", "TimePicker", null, "ROOT");
23
dojo.widget.defineWidget("dojo.widget.TimePicker", dojo.widget.HtmlWidget, function () {
24
	this.time = "";
25
	this.useDefaultTime = false;
26
	this.useDefaultMinutes = false;
27
	this.storedTime = "";
28
	this.currentTime = {};
29
	this.classNames = {selectedTime:"selectedItem"};
30
	this.any = "any";
31
	this.selectedTime = {hour:"", minute:"", amPm:"", anyTime:false};
32
	this.hourIndexMap = ["", 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11, 0];
33
	this.minuteIndexMap = [0, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11];
34
}, {isContainer:false, templateString:"<div class=\"timePickerContainer\" dojoAttachPoint=\"timePickerContainerNode\">\n\t<table class=\"timeContainer\" cellspacing=\"0\" >\n\t\t<thead>\n\t\t\t<tr>\n\t\t\t\t<td class=\"timeCorner cornerTopLeft\" valign=\"top\">&nbsp;</td>\n\t\t\t\t<td class=\"timeLabelContainer hourSelector\">${this.calendar.field-hour}</td>\n\t\t\t\t<td class=\"timeLabelContainer minutesHeading\">${this.calendar.field-minute}</td>\n\t\t\t\t<td class=\"timeCorner cornerTopRight\" valign=\"top\">&nbsp;</td>\n\t\t\t</tr>\n\t\t</thead>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td valign=\"top\" colspan=\"2\" class=\"hours\">\n\t\t\t\t\t<table align=\"center\">\n\t\t\t\t\t\t<tbody dojoAttachPoint=\"hourContainerNode\"  \n\t\t\t\t\t\t\tdojoAttachEvent=\"onClick: onSetSelectedHour;\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>12</td>\n\t\t\t\t\t\t\t\t<td>6</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>1</td>\n\t\t\t\t\t\t\t\t<td>7</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>2</td>\n\t\t\t\t\t\t\t\t<td>8</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>3</td>\n\t\t\t\t\t\t\t\t<td>9</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>4</td>\n\t\t\t\t\t\t\t\t<td>10</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>5</td>\n\t\t\t\t\t\t\t\t<td>11</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td valign=\"top\" class=\"minutes\" colspan=\"2\">\n\t\t\t\t\t<table align=\"center\">\n\t\t\t\t\t\t<tbody dojoAttachPoint=\"minuteContainerNode\" \n\t\t\t\t\t\t\tdojoAttachEvent=\"onClick: onSetSelectedMinute;\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>00</td>\n\t\t\t\t\t\t\t\t<td>30</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>05</td>\n\t\t\t\t\t\t\t\t<td>35</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>10</td>\n\t\t\t\t\t\t\t\t<td>40</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>15</td>\n\t\t\t\t\t\t\t\t<td>45</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>20</td>\n\t\t\t\t\t\t\t\t<td>50</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>25</td>\n\t\t\t\t\t\t\t\t<td>55</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class=\"cornerBottomLeft\">&nbsp;</td>\n\t\t\t\t<td valign=\"top\" class=\"timeOptions\">\n\t\t\t\t\t<table class=\"amPmContainer\">\n\t\t\t\t\t\t<tbody dojoAttachPoint=\"amPmContainerNode\" \n\t\t\t\t\t\t\tdojoAttachEvent=\"onClick: onSetSelectedAmPm;\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td id=\"am\">${this.calendar.am}</td>\n\t\t\t\t\t\t\t\t<td id=\"pm\">${this.calendar.pm}</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t\t<td class=\"timeOptions\">\n\t\t\t\t\t<div dojoAttachPoint=\"anyTimeContainerNode\" \n\t\t\t\t\t\tdojoAttachEvent=\"onClick: onSetSelectedAnyTime;\" \n\t\t\t\t\t\tclass=\"anyTimeContainer\">${this.widgetStrings.any}</div>\n\t\t\t\t</td>\n\t\t\t\t<td class=\"cornerBottomRight\">&nbsp;</td>\n\t\t\t</tr>\n\t\t</tbody>\n\t</table>\n</div>\n", templateCssString:"/*Time Picker */\n.timePickerContainer {\n\twidth:122px;\n\tfont-family:Tahoma, Myriad, Helvetica, Arial, Verdana, sans-serif;\n\tfont-size:16px;\n}\n\n.timeContainer {\n\tborder-collapse:collapse;\n\tborder-spacing:0;\n}\n\n.timeContainer thead {\n\tcolor:#293a4b;\n\tfont-size:0.9em;\n\tfont-weight:700;\n}\n\n.timeContainer thead td {\n\tpadding:0.25em;\n\tfont-size:0.80em;\n\tborder-bottom:1px solid #6782A8;\n}\n\n.timeCorner {\n\twidth:10px;\n}\n\n.cornerTopLeft {\n\tbackground: url(\"images/dpCurveTL.png\") top left no-repeat;\n}\n\n.cornerTopRight {\n\tbackground: url(\"images/dpCurveTR.png\") top right no-repeat;\n}\n\n.timeLabelContainer {\n\tbackground: url(\"images/dpMonthBg.png\") top left repeat-x;\n}\n\n.hours, .minutes, .timeBorder {\n\tbackground: #7591bc url(\"images/dpBg.gif\") top left repeat-x;\n\n}\n\n.hours td, .minutes td {\n\tpadding:0.2em;\n\ttext-align:center;\n\tfont-size:0.7em;\n\tfont-weight:bold;\n\tcursor:pointer;\n\tcursor:hand;\n\tcolor:#fff;\n}\n\n.minutes {\n\tborder-left:1px solid #f5d1db;\n}\n\n.hours {\n\tborder-right:1px solid #6782A8;\n}\n\n.hourSelector {\n\tborder-right:1px solid #6782A8;\n\tpadding:5px;\n\tpadding-right:10px;\n}\n\n.minutesSelector {\n\tpadding:5px;\n\tborder-left:1px solid #f5c7d4;\n\ttext-align:center;\n}\n\n.minutesHeading {\n\tpadding-left:9px !important;\n}\n\n.timeOptions {\n\tbackground-color:#F9C9D7;\n}\n\n.timeContainer .cornerBottomLeft, .timeContainer .cornerBottomRight, .timeContainer .timeOptions {\n\tborder-top:1px solid #6782A8;\n}\n\n.timeContainer .cornerBottomLeft {\n\tbackground: url(\"images/dpCurveBL.png\") bottom left no-repeat !important;\n\twidth:9px !important;\n\tpadding:0;\n\tmargin:0;\n}\n\n.timeContainer .cornerBottomRight {\n\tbackground: url(\"images/dpCurveBR.png\") bottom right no-repeat !important;\n\twidth:9px !important;\n\tpadding:0;\n\tmargin:0;\n}\n\n.timeOptions {\n\tcolor:#fff;\n\tbackground:url(\"images/dpYearBg.png\") top left repeat-x;\n\n}\n\n.selectedItem {\n\tbackground-color:#fff;\n\tcolor:#6782a8 !important;\n}\n\n.timeOptions .selectedItem {\n\tcolor:#fff !important;\n\tbackground-color:#9ec3fb !important;\n}\n\n.anyTimeContainer {\n\ttext-align:center;\n\tfont-weight:bold;\n\tfont-size:0.7em;\n\tpadding:0.1em;\n\tcursor:pointer;\n\tcursor:hand;\n\tcolor:#fff !important;\n}\n\n.amPmContainer {\n\twidth:100%;\n}\n\n.amPmContainer td {\n\ttext-align:center;\n\tfont-size:0.7em;\n\tfont-weight:bold;\n\tcursor:pointer;\n\tcursor:hand;\n\tcolor:#fff;\n}\n\n\n\n/*.timePickerContainer {\n\tmargin:1.75em 0 0.5em 0;\n\twidth:10em;\n\tfloat:left;\n}\n\n.timeContainer {\n\tborder-collapse:collapse;\n\tborder-spacing:0;\n}\n\n.timeContainer thead td{\n\tborder-bottom:1px solid #e6e6e6;\n\tpadding:0 0.4em 0.2em 0.4em;\n}\n\n.timeContainer td {\n\tfont-size:0.9em;\n\tpadding:0 0.25em 0 0.25em;\n\ttext-align:left;\n\tcursor:pointer;cursor:hand;\n}\n\n.timeContainer td.minutesHeading {\n\tborder-left:1px solid #e6e6e6;\n\tborder-right:1px solid #e6e6e6;\t\n}\n\n.timeContainer .minutes {\n\tborder-left:1px solid #e6e6e6;\n\tborder-right:1px solid #e6e6e6;\n}\n\n.selectedItem {\n\tbackground-color:#3a3a3a;\n\tcolor:#ffffff;\n}*/\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/TimePicker.css"), postMixInProperties:function (localProperties, frag) {
35
	dojo.widget.TimePicker.superclass.postMixInProperties.apply(this, arguments);
36
	this.calendar = dojo.i18n.getLocalization("dojo.i18n.calendar", "gregorian", this.lang);
37
	this.widgetStrings = dojo.i18n.getLocalization("dojo.widget", "TimePicker", this.lang);
38
}, fillInTemplate:function (args, frag) {
39
	var source = this.getFragNodeRef(frag);
40
	dojo.html.copyStyle(this.domNode, source);
41
	if (args.value) {
42
		if (args.value instanceof Date) {
43
			this.storedTime = dojo.date.toRfc3339(args.value);
44
		} else {
45
			this.storedTime = args.value;
46
		}
47
	}
48
	this.initData();
49
	this.initUI();
50
}, initData:function () {
51
	if (this.storedTime.indexOf("T") != -1 && this.storedTime.split("T")[1] && this.storedTime != " " && this.storedTime.split("T")[1] != "any") {
52
		this.time = dojo.widget.TimePicker.util.fromRfcDateTime(this.storedTime, this.useDefaultMinutes, this.selectedTime.anyTime);
53
	} else {
54
		if (this.useDefaultTime) {
55
			this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", this.useDefaultMinutes, this.selectedTime.anyTime);
56
		} else {
57
			this.selectedTime.anyTime = true;
58
			this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", 0, 1);
59
		}
60
	}
61
}, initUI:function () {
62
	if (!this.selectedTime.anyTime && this.time) {
63
		var amPmHour = dojo.widget.TimePicker.util.toAmPmHour(this.time.getHours());
64
		var hour = amPmHour[0];
65
		var isAm = amPmHour[1];
66
		var minute = this.time.getMinutes();
67
		var minuteIndex = parseInt(minute / 5);
68
		this.onSetSelectedHour(this.hourIndexMap[hour]);
69
		this.onSetSelectedMinute(this.minuteIndexMap[minuteIndex]);
70
		this.onSetSelectedAmPm(isAm);
71
	} else {
72
		this.onSetSelectedAnyTime();
73
	}
74
}, setTime:function (date) {
75
	if (date) {
76
		this.selectedTime.anyTime = false;
77
		this.setDateTime(dojo.date.toRfc3339(date));
78
	} else {
79
		this.selectedTime.anyTime = true;
80
	}
81
	this.initData();
82
	this.initUI();
83
}, setDateTime:function (rfcDate) {
84
	this.storedTime = rfcDate;
85
}, onClearSelectedHour:function (evt) {
86
	this.clearSelectedHour();
87
}, onClearSelectedMinute:function (evt) {
88
	this.clearSelectedMinute();
89
}, onClearSelectedAmPm:function (evt) {
90
	this.clearSelectedAmPm();
91
}, onClearSelectedAnyTime:function (evt) {
92
	this.clearSelectedAnyTime();
93
	if (this.selectedTime.anyTime) {
94
		this.selectedTime.anyTime = false;
95
		this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", this.useDefaultMinutes);
96
		this.initUI();
97
	}
98
}, clearSelectedHour:function () {
99
	var hourNodes = this.hourContainerNode.getElementsByTagName("td");
100
	for (var i = 0; i < hourNodes.length; i++) {
101
		dojo.html.setClass(hourNodes.item(i), "");
102
	}
103
}, clearSelectedMinute:function () {
104
	var minuteNodes = this.minuteContainerNode.getElementsByTagName("td");
105
	for (var i = 0; i < minuteNodes.length; i++) {
106
		dojo.html.setClass(minuteNodes.item(i), "");
107
	}
108
}, clearSelectedAmPm:function () {
109
	var amPmNodes = this.amPmContainerNode.getElementsByTagName("td");
110
	for (var i = 0; i < amPmNodes.length; i++) {
111
		dojo.html.setClass(amPmNodes.item(i), "");
112
	}
113
}, clearSelectedAnyTime:function () {
114
	dojo.html.setClass(this.anyTimeContainerNode, "anyTimeContainer");
115
}, onSetSelectedHour:function (evt) {
116
	this.onClearSelectedAnyTime();
117
	this.onClearSelectedHour();
118
	this.setSelectedHour(evt);
119
	this.onSetTime();
120
}, setSelectedHour:function (evt) {
121
	if (evt && evt.target) {
122
		if (evt.target.nodeType == dojo.dom.ELEMENT_NODE) {
123
			var eventTarget = evt.target;
124
		} else {
125
			var eventTarget = evt.target.parentNode;
126
		}
127
		dojo.event.browser.stopEvent(evt);
128
		dojo.html.setClass(eventTarget, this.classNames.selectedTime);
129
		this.selectedTime["hour"] = eventTarget.innerHTML;
130
	} else {
131
		if (!isNaN(evt)) {
132
			var hourNodes = this.hourContainerNode.getElementsByTagName("td");
133
			if (hourNodes.item(evt)) {
134
				dojo.html.setClass(hourNodes.item(evt), this.classNames.selectedTime);
135
				this.selectedTime["hour"] = hourNodes.item(evt).innerHTML;
136
			}
137
		}
138
	}
139
	this.selectedTime.anyTime = false;
140
}, onSetSelectedMinute:function (evt) {
141
	this.onClearSelectedAnyTime();
142
	this.onClearSelectedMinute();
143
	this.setSelectedMinute(evt);
144
	this.selectedTime.anyTime = false;
145
	this.onSetTime();
146
}, setSelectedMinute:function (evt) {
147
	if (evt && evt.target) {
148
		if (evt.target.nodeType == dojo.dom.ELEMENT_NODE) {
149
			var eventTarget = evt.target;
150
		} else {
151
			var eventTarget = evt.target.parentNode;
152
		}
153
		dojo.event.browser.stopEvent(evt);
154
		dojo.html.setClass(eventTarget, this.classNames.selectedTime);
155
		this.selectedTime["minute"] = eventTarget.innerHTML;
156
	} else {
157
		if (!isNaN(evt)) {
158
			var minuteNodes = this.minuteContainerNode.getElementsByTagName("td");
159
			if (minuteNodes.item(evt)) {
160
				dojo.html.setClass(minuteNodes.item(evt), this.classNames.selectedTime);
161
				this.selectedTime["minute"] = minuteNodes.item(evt).innerHTML;
162
			}
163
		}
164
	}
165
}, onSetSelectedAmPm:function (evt) {
166
	this.onClearSelectedAnyTime();
167
	this.onClearSelectedAmPm();
168
	this.setSelectedAmPm(evt);
169
	this.selectedTime.anyTime = false;
170
	this.onSetTime();
171
}, setSelectedAmPm:function (evt) {
172
	var eventTarget = evt.target;
173
	if (evt && eventTarget) {
174
		if (eventTarget.nodeType != dojo.dom.ELEMENT_NODE) {
175
			eventTarget = eventTarget.parentNode;
176
		}
177
		dojo.event.browser.stopEvent(evt);
178
		this.selectedTime.amPm = eventTarget.id;
179
		dojo.html.setClass(eventTarget, this.classNames.selectedTime);
180
	} else {
181
		evt = evt ? 0 : 1;
182
		var amPmNodes = this.amPmContainerNode.getElementsByTagName("td");
183
		if (amPmNodes.item(evt)) {
184
			this.selectedTime.amPm = amPmNodes.item(evt).id;
185
			dojo.html.setClass(amPmNodes.item(evt), this.classNames.selectedTime);
186
		}
187
	}
188
}, onSetSelectedAnyTime:function (evt) {
189
	this.onClearSelectedHour();
190
	this.onClearSelectedMinute();
191
	this.onClearSelectedAmPm();
192
	this.setSelectedAnyTime();
193
	this.onSetTime();
194
}, setSelectedAnyTime:function (evt) {
195
	this.selectedTime.anyTime = true;
196
	dojo.html.setClass(this.anyTimeContainerNode, this.classNames.selectedTime + " " + "anyTimeContainer");
197
}, onClick:function (evt) {
198
	dojo.event.browser.stopEvent(evt);
199
}, onSetTime:function () {
200
	if (this.selectedTime.anyTime) {
201
		this.time = new Date();
202
		var tempDateTime = dojo.widget.TimePicker.util.toRfcDateTime(this.time);
203
		this.setDateTime(tempDateTime.split("T")[0]);
204
	} else {
205
		var hour = 12;
206
		var minute = 0;
207
		var isAm = false;
208
		if (this.selectedTime["hour"]) {
209
			hour = parseInt(this.selectedTime["hour"], 10);
210
		}
211
		if (this.selectedTime["minute"]) {
212
			minute = parseInt(this.selectedTime["minute"], 10);
213
		}
214
		if (this.selectedTime["amPm"]) {
215
			isAm = (this.selectedTime["amPm"].toLowerCase() == "am");
216
		}
217
		this.time = new Date();
218
		this.time.setHours(dojo.widget.TimePicker.util.fromAmPmHour(hour, isAm));
219
		this.time.setMinutes(minute);
220
		this.setDateTime(dojo.widget.TimePicker.util.toRfcDateTime(this.time));
221
	}
222
	this.onValueChanged(this.time);
223
}, onValueChanged:function (date) {
224
}});
225
dojo.widget.TimePicker.util = new function () {
226
	this.toRfcDateTime = function (jsDate) {
227
		if (!jsDate) {
228
			jsDate = new Date();
229
		}
230
		jsDate.setSeconds(0);
231
		return dojo.date.strftime(jsDate, "%Y-%m-%dT%H:%M:00%z");
232
	};
233
	this.fromRfcDateTime = function (rfcDate, useDefaultMinutes, isAnyTime) {
234
		var tempDate = new Date();
235
		if (!rfcDate || rfcDate.indexOf("T") == -1) {
236
			if (useDefaultMinutes) {
237
				tempDate.setMinutes(Math.floor(tempDate.getMinutes() / 5) * 5);
238
			} else {
239
				tempDate.setMinutes(0);
240
			}
241
		} else {
242
			var tempTime = rfcDate.split("T")[1].split(":");
243
			var tempDate = new Date();
244
			tempDate.setHours(tempTime[0]);
245
			tempDate.setMinutes(tempTime[1]);
246
		}
247
		return tempDate;
248
	};
249
	this.toAmPmHour = function (hour) {
250
		var amPmHour = hour;
251
		var isAm = true;
252
		if (amPmHour == 0) {
253
			amPmHour = 12;
254
		} else {
255
			if (amPmHour > 12) {
256
				amPmHour = amPmHour - 12;
257
				isAm = false;
258
			} else {
259
				if (amPmHour == 12) {
260
					isAm = false;
261
				}
262
			}
263
		}
264
		return [amPmHour, isAm];
265
	};
266
	this.fromAmPmHour = function (amPmHour, isAm) {
267
		var hour = parseInt(amPmHour, 10);
268
		if (isAm && hour == 12) {
269
			hour = 0;
270
		} else {
271
			if (!isAm && hour < 12) {
272
				hour = hour + 12;
273
			}
274
		}
275
		return hour;
276
	};
277
};
278