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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.DropdownDatePicker");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.widget.DropdownContainer");
16
dojo.require("dojo.widget.DatePicker");
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.string.common");
22
dojo.require("dojo.i18n.common");
23
dojo.requireLocalization("dojo.widget", "DropdownDatePicker", null, "ROOT");
24
dojo.widget.defineWidget("dojo.widget.DropdownDatePicker", dojo.widget.DropdownContainer, {iconURL:dojo.uri.moduleUri("dojo.widget", "templates/images/dateIcon.gif"), formatLength:"short", displayFormat:"", saveFormat:"", value:"", name:"", displayWeeks:6, adjustWeeks:false, startDate:"1492-10-12", endDate:"2941-10-12", weekStartsOn:"", staticDisplay:false, postMixInProperties:function (localProperties, frag) {
25
	dojo.widget.DropdownDatePicker.superclass.postMixInProperties.apply(this, arguments);
26
	var messages = dojo.i18n.getLocalization("dojo.widget", "DropdownDatePicker", this.lang);
27
	this.iconAlt = messages.selectDate;
28
	if (typeof (this.value) == "string" && this.value.toLowerCase() == "today") {
29
		this.value = new Date();
30
	}
31
	if (this.value && isNaN(this.value)) {
32
		var orig = this.value;
33
		this.value = dojo.date.fromRfc3339(this.value);
34
		if (!this.value) {
35
			this.value = new Date(orig);
36
			dojo.deprecated("dojo.widget.DropdownDatePicker", "date attributes must be passed in Rfc3339 format", "0.5");
37
		}
38
	}
39
	if (this.value && !isNaN(this.value)) {
40
		this.value = new Date(this.value);
41
	}
42
}, fillInTemplate:function (args, frag) {
43
	dojo.widget.DropdownDatePicker.superclass.fillInTemplate.call(this, args, frag);
44
	var dpArgs = {widgetContainerId:this.widgetId, lang:this.lang, value:this.value, startDate:this.startDate, endDate:this.endDate, displayWeeks:this.displayWeeks, weekStartsOn:this.weekStartsOn, adjustWeeks:this.adjustWeeks, staticDisplay:this.staticDisplay};
45
	this.datePicker = dojo.widget.createWidget("DatePicker", dpArgs, this.containerNode, "child");
46
	dojo.event.connect(this.datePicker, "onValueChanged", this, "_updateText");
47
	dojo.event.connect(this.inputNode, "onChange", this, "_updateText");
48
	if (this.value) {
49
		this._updateText();
50
	}
51
	this.containerNode.explodeClassName = "calendarBodyContainer";
52
	this.valueNode.name = this.name;
53
}, getValue:function () {
54
	return this.valueNode.value;
55
}, getDate:function () {
56
	return this.datePicker.value;
57
}, setValue:function (rfcDate) {
58
	this.setDate(rfcDate);
59
}, setDate:function (dateObj) {
60
	this.datePicker.setDate(dateObj);
61
	this._syncValueNode();
62
}, _updateText:function () {
63
	this.inputNode.value = this.datePicker.value ? dojo.date.format(this.datePicker.value, {formatLength:this.formatLength, datePattern:this.displayFormat, selector:"dateOnly", locale:this.lang}) : "";
64
	if (this.value < this.datePicker.startDate || this.value > this.datePicker.endDate) {
65
		this.inputNode.value = "";
66
	}
67
	this._syncValueNode();
68
	this.onValueChanged(this.getDate());
69
	this.hideContainer();
70
}, onValueChanged:function (dateObj) {
71
}, onInputChange:function () {
72
	var input = dojo.string.trim(this.inputNode.value);
73
	if (input) {
74
		var inputDate = dojo.date.parse(input, {formatLength:this.formatLength, datePattern:this.displayFormat, selector:"dateOnly", locale:this.lang});
75
		if (!this.datePicker._isDisabledDate(inputDate)) {
76
			this.setDate(inputDate);
77
		}
78
	} else {
79
		if (input == "") {
80
			this.datePicker.setDate("");
81
		}
82
		this.valueNode.value = input;
83
	}
84
	if (input) {
85
		this._updateText();
86
	}
87
}, _syncValueNode:function () {
88
	var date = this.datePicker.value;
89
	var value = "";
90
	switch (this.saveFormat.toLowerCase()) {
91
	  case "rfc":
92
	  case "iso":
93
	  case "":
94
		value = dojo.date.toRfc3339(date, "dateOnly");
95
		break;
96
	  case "posix":
97
	  case "unix":
98
		value = Number(date);
99
		break;
100
	  default:
101
		if (date) {
102
			value = dojo.date.format(date, {datePattern:this.saveFormat, selector:"dateOnly", locale:this.lang});
103
		}
104
	}
105
	this.valueNode.value = value;
106
}, destroy:function (finalize) {
107
	this.datePicker.destroy(finalize);
108
	dojo.widget.DropdownDatePicker.superclass.destroy.apply(this, arguments);
109
}});
110