Subversion Repositories Applications.papyrus

Rev

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