PageRenderTime 35ms CodeModel.GetById 1ms app.highlight 26ms RepoModel.GetById 2ms app.codeStats 0ms

/branches/jsdoc_tk_gui/setup/workingDirectory/Webeo/gui/calendar/Calendar.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 134 lines | 93 code | 25 blank | 16 comment | 15 complexity | 96488ff74d3fff06594661f31de7b898 MD5 | raw file
  1//TODO
  2
  3ek.register("gui.calendar.Calendar");
  4
  5ek.requireCSS("css.gui.calendar.Calendar", "calendar.cal1"); 
  6
  7Calendar.prototype.version = "1.0";
  8
  9
 10// months as they appear in the calendar's title
 11Calendar.prototype.months = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
 12		"Juillet", "Ao?t", "Septembre", "Octobre", "Novembre", "Décembre"];
 13
 14// week day titles as they appear on the calendar
 15Calendar.prototype.days = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"];
 16
 17/**
 18 *@vis public
 19 */
 20Calendar.prototype.getVersion = function (alert){
 21	if(alert)
 22		alert('Calendar.js => version: ' +this.version);
 23	else
 24		return this.version;
 25}
 26
 27/**
 28
 29 */
 30function Calendar (dom){
 31
 32	this.parentDom = (typeof dom == "object")? dom : Dom.getElement(dom);
 33
 34	this.currentDate = new Date();
 35	this.firstDayOfWeek = 1;
 36	
 37	this.rows = new Array(6);
 38	this.cells = new Array(6);
 39	for (var i = 0; i < this.cells.length; i++){
 40		this.cells[i] = new Array(7);
 41	}
 42	
 43	this.drawCalendar();
 44	
 45	this.fillCalendar();
 46		
 47} 
 48Calendar.prototype.drawCalendar = function(){
 49	table = Dom.createHTMLTableElement();
 50	this.drawMonthYearHeader(table);
 51	this.drawDays(table);	
 52	this.parentDom.appendChild(table);
 53}
 54
 55Calendar.prototype.drawMonthYearHeader = function(tableDom){
 56	row = Dom.createHTMLTableRowElement();
 57	var str = this.months[this.currentDate.getMonth()];
 58	str += " " + (1900+this.currentDate.getYear());
 59	row.appendChild(Dom.createHTMLTableCellElement(str, null, null, this.days.length));
 60	tableDom.appendChild(row);
 61}
 62
 63Calendar.prototype.drawDays = function(tableDom){
 64	this.drawDaysHeaders(tableDom);
 65	this.drawWeeks(tableDom);
 66}
 67
 68Calendar.prototype.drawDaysHeaders = function(tableDom){
 69	row = Dom.createHTMLTableRowElement();
 70	for(var i = 0 ; i < this.days.length ; i++){
 71		col = (this.firstDayOfWeek + i) % 7;
 72		row.appendChild(Dom.createHTMLTableCellElement(this.days[col], "dayHeader"));
 73	}
 74	tableDom.appendChild(row);
 75}
 76
 77Calendar.prototype.drawWeeks = function(tableDom){
 78	for(var i = 0 ; i < this.rows.length ; i++){
 79		row = Dom.createHTMLTableRowElement();
 80		this.drawWeekDay(i, row);
 81		//Store the row
 82		this.rows[i] = row;
 83		//Add the row to the table
 84		tableDom.appendChild(row);
 85	}
 86}
 87Calendar.prototype.drawWeekDay = function(rowIdx, weekDom){
 88	for(var i = 0 ; i < this.days.length ; i++){
 89		cell = Dom.createHTMLTableCellElement();
 90		this.cells[rowIdx][i] = cell;
 91		weekDom.appendChild(cell);
 92	}
 93}
 94
 95Calendar.prototype.fillCalendar = function(){
 96	
 97	currentMonth = this.currentDate.getMonth();
 98	
 99	this.currentDate.setDate(1);
100	startDay = this.currentDate.getDay();
101	
102	//Go back
103	this.currentDate.setMonth(currentMonth-1);
104	this.currentDate.setDate(31 - (startDay-1 - this.firstDayOfWeek));
105	
106	
107	for(var i = 0 ; i < this.cells.length ; i++){
108		
109		for(var j = 0 ; j < this.cells[i].length ;j++){
110			col = (this.firstDayOfWeek + j) % 7;
111			if(this.currentDate.getDay() == col){
112				this.cells[i][j].innerHTML = this.currentDate.getDate();
113				this.cells[i][j].setAttribute("class", 
114				this.getClassForCell(this.currentDate.getDay(), currentMonth ==this.currentDate.getMonth()));	
115				//next day
116				this.currentDate.setDate(this.currentDate.getDate()+1);
117			}	
118		}
119	}
120}
121/** 
122 *  
123 */
124Calendar.prototype.getClassForCell = function(day, sameMonth){
125	if(sameMonth){
126		if(day == 0 || day == 6){
127			return "weekend";
128		}else{
129			return "day";
130		}
131	}else{
132		return "anotherDay";
133	}
134}