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.MonthlyCalendar");
14
dojo.require("dojo.date.common");
15
dojo.require("dojo.date.format");
16
dojo.require("dojo.widget.*");
17
dojo.require("dojo.widget.DatePicker");
18
dojo.require("dojo.event.*");
19
dojo.require("dojo.html.*");
20
dojo.require("dojo.experimental");
21
dojo.experimental("dojo.widget.MonthlyCalendar");
22
dojo.widget.defineWidget("dojo.widget.MonthlyCalendar", dojo.widget.DatePicker, {dayWidth:"wide", templateString:"<div class=\"datePickerContainer\" dojoAttachPoint=\"datePickerContainerNode\">\n\t<h3 class=\"monthLabel\">\n\t<!--\n\t<span \n\t\tdojoAttachPoint=\"decreaseWeekNode\" \n\t\tdojoAttachEvent=\"onClick: onIncrementWeek;\" \n\t\tclass=\"incrementControl\">\n\t\t<img src=\"${dojoWidgetModuleUri}templates/decrementWeek.gif\" alt=\"&uarr;\" />\n\t</span>\n\t-->\n\t<span \n\t\tdojoAttachPoint=\"decreaseMonthNode\" \n\t\tdojoAttachEvent=\"onClick: onIncrementMonth;\" class=\"incrementControl\">\n\t\t<img src=\"${dojoWidgetModuleUri}templates/decrementMonth.gif\" \n\t\t\talt=\"&uarr;\" dojoAttachPoint=\"decrementMonthImageNode\">\n\t</span>\n\t<span dojoAttachPoint=\"monthLabelNode\" class=\"month\">July</span>\n\t<span \n\t\tdojoAttachPoint=\"increaseMonthNode\" \n\t\tdojoAttachEvent=\"onClick: onIncrementMonth;\" class=\"incrementControl\">\n\t\t<img src=\"${dojoWidgetModuleUri}templates/incrementMonth.gif\" \n\t\t\talt=\"&darr;\"  dojoAttachPoint=\"incrementMonthImageNode\">\n\t</span>\n\t<!--\n\t\t<span dojoAttachPoint=\"increaseWeekNode\" \n\t\t\tdojoAttachEvent=\"onClick: onIncrementWeek;\" \n\t\t\tclass=\"incrementControl\">\n\t\t\t<img src=\"${dojoWidgetModuleUri}templates/incrementWeek.gif\" \n\t\t\talt=\"&darr;\" />\n\t\t</span>\n\t-->\n\t</h3>\n\t<table class=\"calendarContainer\">\n\t\t<thead>\n\t\t\t<tr dojoAttachPoint=\"dayLabelsRow\">\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t</tr>\n\t\t</thead>\n\t\t<tbody dojoAttachPoint=\"calendarDatesContainerNode\" \n\t\t\tdojoAttachEvent=\"onClick: onSetDate;\">\n\t\t\t<tr dojoAttachPoint=\"calendarRow0\">\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t</tr>\n\t\t\t<tr dojoAttachPoint=\"calendarRow1\">\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t</tr>\n\t\t\t<tr dojoAttachPoint=\"calendarRow2\">\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t</tr>\n\t\t\t<tr dojoAttachPoint=\"calendarRow3\">\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t</tr>\n\t\t\t<tr dojoAttachPoint=\"calendarRow4\">\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t</tr>\n\t\t\t<tr dojoAttachPoint=\"calendarRow5\">\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t\t<td></td>\n\t\t\t</tr>\n\t\t</tbody>\n\t</table>\n\t<h3 class=\"yearLabel\">\n\t\t<span dojoAttachPoint=\"previousYearLabelNode\"\n\t\t\tdojoAttachEvent=\"onClick: onIncrementYear;\" class=\"previousYear\"></span>\n\t\t<span class=\"selectedYear\" dojoAttachPoint=\"currentYearLabelNode\"></span>\n\t\t<span dojoAttachPoint=\"nextYearLabelNode\" \n\t\t\tdojoAttachEvent=\"onClick: onIncrementYear;\" class=\"nextYear\"></span>\n\t</h3>\n</div>\n", templateCssString:".datePickerContainer {\n\tmargin:0.5em 2em 0.5em 0;\n\t/*width:10em;*/\n\tfloat:left;\n}\n\n.previousMonth {\n\tbackground-color:#bbbbbb;\n}\n\n.currentMonth {\n\tbackground-color:#8f8f8f;\n}\n\n.nextMonth {\n\tbackground-color:#eeeeee;\n}\n\n.currentDate {\n\ttext-decoration:underline;\n\tfont-style:italic;\n}\n\n.selectedItem {\n\tbackground-color:#3a3a3a;\n\tcolor:#ffffff;\n}\n\n.calendarContainer {\n\tborder-collapse:collapse;\n\tborder-spacing:0;\n\tborder-bottom:1px solid #e6e6e6;\n\toverflow: hidden;\n\ttext-align: right;\n}\n\n.calendarContainer thead{\n\tborder-bottom:1px solid #e6e6e6;\n}\n\n.calendarContainer tbody * td {\n		height: 100px;\n		border: 1px solid gray;\n}\n\n.calendarContainer td {\n		width: 100px;\n		padding: 2px;\n\tvertical-align: top;\n}\n\n.monthLabel {\n\tfont-size:0.9em;\n\tfont-weight:400;\n\tmargin:0;\n\ttext-align:center;\n}\n\n.monthLabel .month {\n\tpadding:0 0.4em 0 0.4em;\n}\n\n.yearLabel {\n\tfont-size:0.9em;\n\tfont-weight:400;\n\tmargin:0.25em 0 0 0;\n\ttext-align:right;\n\tcolor:#a3a3a3;\n}\n\n.yearLabel .selectedYear {\n\tcolor:#000;\n\tpadding:0 0.2em;\n}\n\n.nextYear, .previousYear {\n\tcursor:pointer;cursor:hand;\n}\n\n.incrementControl {\n\tcursor:pointer;cursor:hand;\n\twidth:1em;\n}\n\n.dojoMonthlyCalendarEvent {\n\tfont-size:0.7em;\n\toverflow: hidden;\n\tfont-color: grey;\n\twhite-space: nowrap;\n\ttext-align: left;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/MonthlyCalendar.css"), initializer:function () {
23
	this.iCalendars = [];
24
}, addCalendar:function (cal) {
25
	dojo.debug("Adding Calendar");
26
	this.iCalendars.push(cal);
27
	dojo.debug("Starting init");
28
	this.initUI();
29
	dojo.debug("done init");
30
}, createDayContents:function (node, mydate) {
31
	dojo.html.removeChildren(node);
32
	node.appendChild(document.createTextNode(mydate.getDate()));
33
	for (var x = 0; x < this.iCalendars.length; x++) {
34
		var evts = this.iCalendars[x].getEvents(mydate);
35
		if ((dojo.lang.isArray(evts)) && (evts.length > 0)) {
36
			for (var y = 0; y < evts.length; y++) {
37
				var el = document.createElement("div");
38
				dojo.html.addClass(el, "dojoMonthlyCalendarEvent");
39
				el.appendChild(document.createTextNode(evts[y].summary.value));
40
				el.width = dojo.html.getContentBox(node).width;
41
				node.appendChild(el);
42
			}
43
		}
44
	}
45
}, initUI:function () {
46
	var dayLabels = dojo.date.getNames("days", this.dayWidth, "standAlone", this.lang);
47
	var dayLabelNodes = this.dayLabelsRow.getElementsByTagName("td");
48
	for (var i = 0; i < 7; i++) {
49
		dayLabelNodes.item(i).innerHTML = dayLabels[i];
50
	}
51
	this.selectedIsUsed = false;
52
	this.currentIsUsed = false;
53
	var currentClassName = "";
54
	var previousDate = new Date();
55
	var calendarNodes = this.calendarDatesContainerNode.getElementsByTagName("td");
56
	var currentCalendarNode;
57
	previousDate.setHours(8);
58
	var nextDate = new Date(this.firstSaturday.year, this.firstSaturday.month, this.firstSaturday.date, 8);
59
	var lastDay = new Date(this.firstSaturday.year, this.firstSaturday.month, this.firstSaturday.date + 42, 8);
60
	if (this.iCalendars.length > 0) {
61
		for (var x = 0; x < this.iCalendars.length; x++) {
62
			this.iCalendars[x].preComputeRecurringEvents(lastDay);
63
		}
64
	}
65
	if (this.firstSaturday.date < 7) {
66
		var dayInWeek = 6;
67
		for (var i = this.firstSaturday.date; i > 0; i--) {
68
			currentCalendarNode = calendarNodes.item(dayInWeek);
69
			this.createDayContents(currentCalendarNode, nextDate);
70
			dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "current"));
71
			dayInWeek--;
72
			previousDate = nextDate;
73
			nextDate = this.incrementDate(nextDate, false);
74
		}
75
		for (var i = dayInWeek; i > -1; i--) {
76
			currentCalendarNode = calendarNodes.item(i);
77
			this.createDayContents(currentCalendarNode, nextDate);
78
			dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "previous"));
79
			previousDate = nextDate;
80
			nextDate = this.incrementDate(nextDate, false);
81
		}
82
	} else {
83
		nextDate.setDate(1);
84
		for (var i = 0; i < 7; i++) {
85
			currentCalendarNode = calendarNodes.item(i);
86
			this.createDayContents(currentCalendarNode, nextDate);
87
			dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "current"));
88
			previousDate = nextDate;
89
			nextDate = this.incrementDate(nextDate, true);
90
		}
91
	}
92
	previousDate.setDate(this.firstSaturday.date);
93
	previousDate.setMonth(this.firstSaturday.month);
94
	previousDate.setFullYear(this.firstSaturday.year);
95
	nextDate = this.incrementDate(previousDate, true);
96
	var count = 7;
97
	currentCalendarNode = calendarNodes.item(count);
98
	while ((nextDate.getMonth() == previousDate.getMonth()) && (count < 42)) {
99
		this.createDayContents(currentCalendarNode, nextDate);
100
		dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "current"));
101
		currentCalendarNode = calendarNodes.item(++count);
102
		previousDate = nextDate;
103
		nextDate = this.incrementDate(nextDate, true);
104
	}
105
	while (count < 42) {
106
		this.createDayContents(currentCalendarNode, nextDate);
107
		dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "next"));
108
		currentCalendarNode = calendarNodes.item(++count);
109
		previousDate = nextDate;
110
		nextDate = this.incrementDate(nextDate, true);
111
	}
112
	this.setMonthLabel(this.firstSaturday.month);
113
	this.setYearLabels(this.firstSaturday.year);
114
}});
115
dojo.widget.MonthlyCalendar.util = new function () {
116
	this.toRfcDate = function (jsDate) {
117
		if (!jsDate) {
118
			jsDate = this.today;
119
		}
120
		var year = jsDate.getFullYear();
121
		var month = jsDate.getMonth() + 1;
122
		if (month < 10) {
123
			month = "0" + month.toString();
124
		}
125
		var date = jsDate.getDate();
126
		if (date < 10) {
127
			date = "0" + date.toString();
128
		}
129
		return year + "-" + month + "-" + date + "T00:00:00+00:00";
130
	};
131
	this.fromRfcDate = function (rfcDate) {
132
		var tempDate = rfcDate.split("-");
133
		if (tempDate.length < 3) {
134
			return new Date();
135
		}
136
		return new Date(parseInt(tempDate[0]), (parseInt(tempDate[1], 10) - 1), parseInt(tempDate[2].substr(0, 2), 10));
137
	};
138
	this.initFirstSaturday = function (month, year) {
139
		if (!month) {
140
			month = this.date.getMonth();
141
		}
142
		if (!year) {
143
			year = this.date.getFullYear();
144
		}
145
		var firstOfMonth = new Date(year, month, 1);
146
		return {year:year, month:month, date:7 - firstOfMonth.getDay()};
147
	};
148
};
149