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