Subversion Repositories Applications.papyrus

Rev

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