1 | /**********************************************************************
|
---|
2 | * Calendar JavaScript [DOM] v3.11 by Michael Loesler *
|
---|
3 | ************************************************************************
|
---|
4 | * Copyright (C) 2005-09 by Michael Loesler, http//derletztekick.com *
|
---|
5 | * *
|
---|
6 | * *
|
---|
7 | * This program is free software; you can redistribute it and/or modify *
|
---|
8 | * it under the terms of the GNU General Public License as published by *
|
---|
9 | * the Free Software Foundation; either version 3 of the License, or *
|
---|
10 | * (at your option) any later version. *
|
---|
11 | * *
|
---|
12 | * This program is distributed in the hope that it will be useful, *
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
---|
15 | * GNU General Public License for more details. *
|
---|
16 | * *
|
---|
17 | * You should have received a copy of the GNU General Public License *
|
---|
18 | * along with this program; if not, see <http://www.gnu.org/licenses/> *
|
---|
19 | * or write to the *
|
---|
20 | * Free Software Foundation, Inc., *
|
---|
21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
---|
22 | * *
|
---|
23 | **********************************************************************/
|
---|
24 | /*
|
---|
25 | function logout()
|
---|
26 | {
|
---|
27 | var xmlHttp = new XMLHttpRequest();
|
---|
28 | xmlHttp.open('POST', "calendar.php?logout=1", true);
|
---|
29 | xmlHttp.onload = function ()
|
---|
30 | {
|
---|
31 | if (xmlHttp.status!=200)
|
---|
32 | {
|
---|
33 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
34 | return;
|
---|
35 | }
|
---|
36 |
|
---|
37 | alert("Logout successful!");
|
---|
38 | };
|
---|
39 |
|
---|
40 | xmlHttp.send();
|
---|
41 | }
|
---|
42 | */
|
---|
43 | function resize()
|
---|
44 | {
|
---|
45 | var table = document.getElementById("table");
|
---|
46 |
|
---|
47 | var W = window.innerWidth;
|
---|
48 | var H = window.innerHeight;
|
---|
49 |
|
---|
50 | table.style.width =W+"px";
|
---|
51 | table.style.height=H+"px";
|
---|
52 | }
|
---|
53 |
|
---|
54 | var institutes= ["User", "EPFL", "ETHZ", "ISDC", "UNIDO", "UNIGE", "UNIWUE" ];
|
---|
55 |
|
---|
56 | function CalendarJS()
|
---|
57 | {
|
---|
58 | this.now = new Date();
|
---|
59 | this.dayname = ["Mo","Tu","We","Th","Fr","Sa","So"];
|
---|
60 | this.monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"];
|
---|
61 | this.tooltip = ["previous month","next month","current date","last year","next year"];
|
---|
62 | this.monthCell = document.createElement("th");
|
---|
63 | this.tableHead = null;
|
---|
64 | this.tableFoot = null;
|
---|
65 | this.parEl = null;
|
---|
66 |
|
---|
67 | this.init = function( id, initDate )
|
---|
68 | {
|
---|
69 | this.now = initDate ? initDate : new Date();
|
---|
70 | this.date = this.now.getDate();
|
---|
71 | this.month = this.mm = this.now.getMonth();
|
---|
72 | this.year = this.yy = this.now.getFullYear();
|
---|
73 | this.monthCell.appendChild(document.createTextNode( this.monthname[this.mm]+"\u00a0"+this.yy ));
|
---|
74 |
|
---|
75 | this.tableHead = this.createTableHead();
|
---|
76 | this.tableFoot = this.createTableFoot();
|
---|
77 |
|
---|
78 | this.parEl = document.getElementById( id );
|
---|
79 | this.show();
|
---|
80 |
|
---|
81 | if (!initDate)
|
---|
82 | this.checkDate();
|
---|
83 | };
|
---|
84 |
|
---|
85 | this.checkDate = function()
|
---|
86 | {
|
---|
87 | var self = this;
|
---|
88 | var today = new Date();
|
---|
89 |
|
---|
90 | if (this.date != today.getDate())
|
---|
91 | {
|
---|
92 | this.tableHead = this.createTableHead();
|
---|
93 | this.tableFoot = this.createTableFoot();
|
---|
94 |
|
---|
95 | this.date = today.getDate();
|
---|
96 | if (this.mm == this.month && this.yy == this.year)
|
---|
97 | this.switchMonth("current");
|
---|
98 |
|
---|
99 | this.month = today.getMonth();
|
---|
100 | if (this.mm == this.month && this.yy == this.year)
|
---|
101 | this.switchMonth("current");
|
---|
102 |
|
---|
103 | this.year = today.getFullYear();
|
---|
104 | if (this.mm == this.month && this.yy == this.year)
|
---|
105 | this.switchMonth("current");
|
---|
106 | }
|
---|
107 | window.setTimeout(function() { self.checkDate(); }, Math.abs(new Date(this.year, this.month, this.date, 24, 0, 0)-this.now));
|
---|
108 | },
|
---|
109 |
|
---|
110 | this.removeElements = function( Obj )
|
---|
111 | {
|
---|
112 | while( Obj.childNodes.length > 0)
|
---|
113 | Obj.removeChild(Obj.lastChild);
|
---|
114 |
|
---|
115 | return Obj;
|
---|
116 | };
|
---|
117 |
|
---|
118 | this.show = function()
|
---|
119 | {
|
---|
120 | this.parEl = this.removeElements( this.parEl );
|
---|
121 | this.monthCell.firstChild.replaceData(0, this.monthCell.firstChild.nodeValue.length, this.monthname[this.mm]+"\u00a0"+this.yy);
|
---|
122 |
|
---|
123 | var table = document.createElement("table");
|
---|
124 | table.id = "table";
|
---|
125 |
|
---|
126 | this.parEl.appendChild( table );
|
---|
127 |
|
---|
128 | table.appendChild( this.tableHead );
|
---|
129 | table.appendChild( this.tableFoot );
|
---|
130 |
|
---|
131 | table.appendChild( this.createTableBody(window.innerHeight-table.offsetHeight) );
|
---|
132 |
|
---|
133 | resize();
|
---|
134 | };
|
---|
135 |
|
---|
136 | this.createTableFoot = function()
|
---|
137 | {
|
---|
138 | var tfoot = document.createElement("tfoot");
|
---|
139 |
|
---|
140 | var tr = document.createElement("tr");
|
---|
141 | var td = document.createElement("td");
|
---|
142 | td.height = "1%";
|
---|
143 | td.colSpan = 7;
|
---|
144 | td.style.padding="3px 3px";
|
---|
145 | tfoot.appendChild(tr);
|
---|
146 | tr.appendChild(td);
|
---|
147 | var table = document.createElement("table");
|
---|
148 | table.width="100%";
|
---|
149 | td.appendChild(table);
|
---|
150 | tr = document.createElement("tr");
|
---|
151 | table.appendChild(tr);
|
---|
152 | for (var i=0; i<institutes.length; i++)
|
---|
153 | {
|
---|
154 | td = document.createElement("td");
|
---|
155 | td.width=100/institutes.length+"%";
|
---|
156 | td.setAttribute("style", "text-align:center;font-size:1em;border:solid #112A5D 2px;padding:3px 3px;");
|
---|
157 | td.changeUser = this.changeUser;
|
---|
158 | td.onclick = function(e) { this.changeUser(); }
|
---|
159 | td.appendChild(document.createTextNode(institutes[i]));
|
---|
160 | tr.appendChild(td);
|
---|
161 |
|
---|
162 | if (i==0)
|
---|
163 | td.style.backgroundColor = "yellow";
|
---|
164 | }
|
---|
165 | document.getElementById("body").setAttribute("data-user", institutes[0]);
|
---|
166 |
|
---|
167 |
|
---|
168 | tr = document.createElement("tr");
|
---|
169 | td = document.createElement("td");
|
---|
170 | td.colSpan = 7;
|
---|
171 | td.style.paddingLeft = "0px";
|
---|
172 | td.style.paddingTop = "0px";
|
---|
173 | td.height = "1%";
|
---|
174 | var form = document.createElement("form");
|
---|
175 | var input = document.createElement("textarea");
|
---|
176 | input.overflow = "auto";
|
---|
177 | input.wrap = "virtual";
|
---|
178 | input.id = "comment";
|
---|
179 | input.value = "enter comment here";
|
---|
180 | input.style.color = "#888";
|
---|
181 | input.style.width = "100%";
|
---|
182 | input.rows = 5;
|
---|
183 | input.title = "Enter a comment. Click somewhere in the calender to store the comment.";
|
---|
184 | input.onchange = function() { pushComment(); };
|
---|
185 | input.onfocus = function() { if (input.value=="enter comment here" && input.style.color!="black") input.value=""; input.style.color="black"; };
|
---|
186 | input.onblur = function() { input.style.color="#888"; if (input.value=="") input.value="enter comment here"; };
|
---|
187 | form.appendChild(input);
|
---|
188 | td.appendChild( form );
|
---|
189 | tr.appendChild( td );
|
---|
190 | tfoot.appendChild(tr);
|
---|
191 |
|
---|
192 | tr = document.createElement("tr");
|
---|
193 |
|
---|
194 | var td = document.createElement("td");
|
---|
195 | td.height="1%";
|
---|
196 | td.colSpan=7;
|
---|
197 | tr.appendChild(td);
|
---|
198 |
|
---|
199 | var tab = document.createElement("table");
|
---|
200 | var tr2 = document.createElement("tr");
|
---|
201 | tab.width="100%";
|
---|
202 | tab.cellSpacing=0;
|
---|
203 | tab.cellPadding=0;
|
---|
204 | tab.style.borderWidth = 0;
|
---|
205 | tab.style.fontSize = "1.5em";
|
---|
206 | tab.style.marginBottom = "2px";
|
---|
207 | td.appendChild(tab);
|
---|
208 | tab.appendChild(tr2);
|
---|
209 |
|
---|
210 | var tm = this.getCell( "td", this.timeTrigger(), "clock" );
|
---|
211 | tm.style.whiteSpace="nowrap";
|
---|
212 | tm.style.paddingLeft = "0px";
|
---|
213 | tm.style.width="33%";
|
---|
214 | tr2.appendChild( tm );
|
---|
215 |
|
---|
216 | var self = this;
|
---|
217 | window.setInterval(function() { tm.firstChild.nodeValue = self.timeTrigger(); }, 500);
|
---|
218 |
|
---|
219 | var td = document.createElement("td");
|
---|
220 | td.style.width="33%";
|
---|
221 | td.style.textAlign="center";
|
---|
222 | var a = document.createElement("a");
|
---|
223 | a.href = "overview.png";
|
---|
224 | a.style.whiteSpace="nowrap";
|
---|
225 | a.appendChild(document.createTextNode("click here for help"));
|
---|
226 | td.appendChild(a);
|
---|
227 | tr2.appendChild( td );
|
---|
228 |
|
---|
229 | td = this.getCell( "td", "logout", "logout");
|
---|
230 | td.style.width="33%";
|
---|
231 | td.onclick = function(e) { logout(); }
|
---|
232 | td.style.paddingRight = "0px";
|
---|
233 | tr2.appendChild( td );
|
---|
234 |
|
---|
235 | tfoot.appendChild( tr );
|
---|
236 |
|
---|
237 | return tfoot;
|
---|
238 | }
|
---|
239 |
|
---|
240 | this.createTableHead = function()
|
---|
241 | {
|
---|
242 | var thead = document.createElement("thead");
|
---|
243 | thead.style.height="1%";
|
---|
244 | var tr = document.createElement("tr");
|
---|
245 | var th = this.getCell( "th", "\u00AB", "prev_month" );
|
---|
246 |
|
---|
247 | th.rowSpan = 2;
|
---|
248 | th.Instanz = this;
|
---|
249 | th.onclick = function() { this.Instanz.switchMonth("prev"); };
|
---|
250 | th.title = this.tooltip[0];
|
---|
251 |
|
---|
252 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
253 | tr.appendChild( th );
|
---|
254 |
|
---|
255 | this.monthCell.Instanz = this;
|
---|
256 | this.monthCell.rowSpan = 2;
|
---|
257 | this.monthCell.colSpan = 4;
|
---|
258 | this.monthCell.onclick = function() { this.Instanz.switchMonth("current"); };
|
---|
259 | this.monthCell.title = this.tooltip[2];
|
---|
260 |
|
---|
261 | try { this.monthCell.style.cursor = "pointer"; } catch(e){ this.monthCell.style.cursor = "hand"; }
|
---|
262 | tr.appendChild( this.monthCell );
|
---|
263 |
|
---|
264 | th = this.getCell( "th", "\u00BB", "next_month" );
|
---|
265 | th.rowSpan = 2;
|
---|
266 | th.Instanz = this;
|
---|
267 | th.onclick = function() { this.Instanz.switchMonth("next"); };
|
---|
268 | th.title = this.tooltip[1];
|
---|
269 |
|
---|
270 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
271 | tr.appendChild( th );
|
---|
272 |
|
---|
273 | th = this.getCell( "th", "\u02c4", "prev_year" );
|
---|
274 | th.Instanz = this;
|
---|
275 | th.onclick = function() { this.Instanz.switchMonth("prev_year"); };
|
---|
276 | th.title = this.tooltip[3];
|
---|
277 |
|
---|
278 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
279 | tr.appendChild( th );
|
---|
280 |
|
---|
281 | thead.appendChild( tr );
|
---|
282 |
|
---|
283 | tr = document.createElement("tr");
|
---|
284 | th = this.getCell( "th", "\u02c5", "next_year" );
|
---|
285 | th.Instanz = this;
|
---|
286 | th.onclick = function() { this.Instanz.switchMonth("next_year"); };
|
---|
287 | th.title = this.tooltip[4];
|
---|
288 |
|
---|
289 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
290 | tr.appendChild( th );
|
---|
291 |
|
---|
292 | thead.appendChild( tr );
|
---|
293 |
|
---|
294 | tr = document.createElement('tr');
|
---|
295 | for (var i=0; i<this.dayname.length; i++)
|
---|
296 | {
|
---|
297 | var th = this.getCell("th", this.dayname[i], "weekday" );
|
---|
298 | th.width=100/7+"%";
|
---|
299 | tr.appendChild( th );
|
---|
300 | }
|
---|
301 |
|
---|
302 | thead.appendChild( tr );
|
---|
303 |
|
---|
304 | return thead;
|
---|
305 | },
|
---|
306 |
|
---|
307 | this.createTableBody = function(height)
|
---|
308 | {
|
---|
309 | var dayspermonth = [31,28,31,30,31,30,31,31,30,31,30,31];
|
---|
310 | var sevendaysaweek = 0;
|
---|
311 | var begin = new Date(this.yy, this.mm, 1);
|
---|
312 | var firstday = begin.getDay()-1;
|
---|
313 | if (firstday < 0)
|
---|
314 | firstday = 6;
|
---|
315 | if ((this.yy%4==0) && ((this.yy%100!=0) || (this.yy%400==0)))
|
---|
316 | dayspermonth[1] = 29;
|
---|
317 |
|
---|
318 | var tbody = document.createElement("tbody");
|
---|
319 | var tr = document.createElement('tr');
|
---|
320 |
|
---|
321 | tbody.height="100%";
|
---|
322 |
|
---|
323 | var height="";//"20%";//100/8+"%";
|
---|
324 |
|
---|
325 | if (firstday == 0)
|
---|
326 | {
|
---|
327 | for (var i=0; i<this.dayname.length; i++)
|
---|
328 | {
|
---|
329 | var prevMonth = (this.mm == 0)?11:this.mm-1;
|
---|
330 | var td = this.getCell( "td", dayspermonth[prevMonth]-6+i, "last_month" );
|
---|
331 | td.style.height=height;
|
---|
332 | tr.appendChild( td );
|
---|
333 | }
|
---|
334 | tbody.appendChild( tr );
|
---|
335 | tr = document.createElement('tr');
|
---|
336 | }
|
---|
337 |
|
---|
338 | for (var i=0; i<firstday; i++, sevendaysaweek++)
|
---|
339 | {
|
---|
340 | var prevMonth = (this.mm == 0)?11:this.mm-1;
|
---|
341 | var td = this.getCell( "td", dayspermonth[prevMonth]-firstday+i+1, "last_month" );
|
---|
342 | td.style.height=height;
|
---|
343 | tr.appendChild( td );
|
---|
344 | }
|
---|
345 |
|
---|
346 | for (var i=1; i<=dayspermonth[this.mm]; i++, sevendaysaweek++)
|
---|
347 | {
|
---|
348 | if (this.dayname.length == sevendaysaweek)
|
---|
349 | {
|
---|
350 | tbody.appendChild( tr );
|
---|
351 | tr = document.createElement('tr');
|
---|
352 | sevendaysaweek = 0;
|
---|
353 | }
|
---|
354 |
|
---|
355 | var td = null;
|
---|
356 | if (i==this.date && this.mm==this.month && this.yy==this.year && (sevendaysaweek == 5 || sevendaysaweek == 6))
|
---|
357 | td = this.getCell( "td", i, "today weekend" );
|
---|
358 | else
|
---|
359 | if (i==this.date && this.mm==this.month && this.yy==this.year)
|
---|
360 | td = this.getCell( "td", i, "today" );
|
---|
361 | else
|
---|
362 | if (sevendaysaweek == 5 || sevendaysaweek == 6)
|
---|
363 | td = this.getCell( "td", i, "weekend" );
|
---|
364 | else
|
---|
365 | td = this.getCell( "td", i, null);
|
---|
366 |
|
---|
367 | td.setDate = this.setDate;
|
---|
368 | td.chooseDate = this.chooseDate;
|
---|
369 | td.dd = i;
|
---|
370 | td.mm = this.mm;
|
---|
371 | td.yy = this.yy;
|
---|
372 | td.id = this.mm+"-"+i;
|
---|
373 | td.title = "Click to select this date.";
|
---|
374 |
|
---|
375 | td.style.height=height;
|
---|
376 |
|
---|
377 | td.onclick = function(e) {
|
---|
378 | this.chooseDate();
|
---|
379 | };
|
---|
380 |
|
---|
381 | var sp = document.createElement("span");
|
---|
382 | sp.appendChild(document.createTextNode("*"));
|
---|
383 | sp.style.color="darkred";
|
---|
384 | sp.style.display="none";
|
---|
385 | td.appendChild(sp);
|
---|
386 |
|
---|
387 | tr.appendChild( td );
|
---|
388 | }
|
---|
389 |
|
---|
390 | var daysNextMonth = 1;
|
---|
391 | for (var i=sevendaysaweek; i<this.dayname.length; i++)
|
---|
392 | tr.appendChild( this.getCell( "td", daysNextMonth++, "next_month" ) );
|
---|
393 |
|
---|
394 | tbody.appendChild( tr );
|
---|
395 |
|
---|
396 | while (tbody.getElementsByTagName("tr").length<6) {
|
---|
397 | tr = document.createElement('tr');
|
---|
398 | for (var i=0; i<this.dayname.length; i++)
|
---|
399 | {
|
---|
400 | var td = this.getCell( "td", daysNextMonth++, "next_month" );
|
---|
401 | td.style.height=height;
|
---|
402 | tr.appendChild( td );
|
---|
403 | }
|
---|
404 | tbody.appendChild( tr );
|
---|
405 | }
|
---|
406 |
|
---|
407 | requestAll(this.yy, this.mm);
|
---|
408 | requestAllComments(this.yy, this.mm);
|
---|
409 | if (this.year==this.yy && this.month==this.mm)
|
---|
410 | requestComment(this.year, this.month, this.date);
|
---|
411 | else
|
---|
412 | {
|
---|
413 | var c = document.getElementById("comment");
|
---|
414 | c.color="#888";
|
---|
415 | c.value="enter comment here";
|
---|
416 | }
|
---|
417 |
|
---|
418 | return tbody;
|
---|
419 | };
|
---|
420 |
|
---|
421 | this.getCalendarWeek = function(j,m,t)
|
---|
422 | {
|
---|
423 | var cwDate = this.now;
|
---|
424 | if (!t)
|
---|
425 | {
|
---|
426 | j = cwDate.getFullYear();
|
---|
427 | m = cwDate.getMonth();
|
---|
428 | t = cwDate.getDate();
|
---|
429 | }
|
---|
430 | cwDate = new Date(j,m,t);
|
---|
431 |
|
---|
432 | var doDat = new Date(cwDate.getTime() + (3-((cwDate.getDay()+6) % 7)) * 86400000);
|
---|
433 | cwYear = doDat.getFullYear();
|
---|
434 |
|
---|
435 | var doCW = new Date(new Date(cwYear,0,4).getTime() + (3-((new Date(cwYear,0,4).getDay()+6) % 7)) * 86400000);
|
---|
436 | cw = Math.floor(1.5+(doDat.getTime()-doCW.getTime())/86400000/7);
|
---|
437 | return cw;
|
---|
438 | };
|
---|
439 |
|
---|
440 | function request(td)
|
---|
441 | {
|
---|
442 | var user = document.getElementById("body").getAttribute("data-user");
|
---|
443 | var uri = "calendar.php?toggle&y="+td.yy+"&m="+td.mm+"&d="+td.dd;
|
---|
444 | if (user!="User")
|
---|
445 | uri += "&u="+user;
|
---|
446 |
|
---|
447 | var xmlHttp = new XMLHttpRequest();
|
---|
448 | xmlHttp.open('POST', uri, true);
|
---|
449 | xmlHttp.onload = function ()
|
---|
450 | {
|
---|
451 | if (xmlHttp.status!=200)
|
---|
452 | {
|
---|
453 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
454 | return;
|
---|
455 | }
|
---|
456 |
|
---|
457 | var lines = xmlHttp.responseText.split('\n');
|
---|
458 | if (lines.length==0)
|
---|
459 | return;
|
---|
460 |
|
---|
461 | while (td.childNodes.length>2)
|
---|
462 | td.removeChild(td.lastChild);
|
---|
463 |
|
---|
464 | for (var i=0; i<lines.length; i++)
|
---|
465 | {
|
---|
466 | var x = lines[i].split('\t');
|
---|
467 | if (x.length!=2)
|
---|
468 | continue;
|
---|
469 |
|
---|
470 | var div = document.createElement("div");
|
---|
471 | div.style.fontWeight="normal";
|
---|
472 | div.appendChild(document.createTextNode(x[1]));
|
---|
473 | td.appendChild(div);
|
---|
474 |
|
---|
475 | for (var j=0; j<institutes.length; j++)
|
---|
476 | if (x[1]==institutes[j])
|
---|
477 | {
|
---|
478 | div.className += " institute";
|
---|
479 | break;
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 | if (td.childNodes.length>2)
|
---|
484 | td.className += " enabled";
|
---|
485 | else
|
---|
486 | td.className = td.className.replace(/enabled/g, "");
|
---|
487 | };
|
---|
488 |
|
---|
489 | xmlHttp.send();
|
---|
490 | }
|
---|
491 |
|
---|
492 | function logout()
|
---|
493 | {
|
---|
494 | var xmlHttp = new XMLHttpRequest();
|
---|
495 | xmlHttp.open('POST', "calendar.php?logout", true);
|
---|
496 | xmlHttp.onload = function ()
|
---|
497 | {
|
---|
498 | if (xmlHttp.status!=200)
|
---|
499 | {
|
---|
500 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
501 | return;
|
---|
502 | }
|
---|
503 | };
|
---|
504 |
|
---|
505 | xmlHttp.send();
|
---|
506 | }
|
---|
507 |
|
---|
508 | function pushComment()
|
---|
509 | {
|
---|
510 | var c = document.getElementById("comment");
|
---|
511 |
|
---|
512 | var y = c.getAttribute("data-y");
|
---|
513 | var m = c.getAttribute("data-m");
|
---|
514 | var d = c.getAttribute("data-d");
|
---|
515 | var v = c.value;
|
---|
516 |
|
---|
517 | var uri = "calendar.php?y="+y+"&m="+m+"&d="+d+"&c="+encodeURIComponent(v);
|
---|
518 |
|
---|
519 | var xmlHttp = new XMLHttpRequest();
|
---|
520 | xmlHttp.open('POST', uri, true);
|
---|
521 | xmlHttp.onload = function()
|
---|
522 | {
|
---|
523 | if (xmlHttp.status!=200)
|
---|
524 | {
|
---|
525 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
526 | return;
|
---|
527 | }
|
---|
528 |
|
---|
529 | alert("Comment inserted successfully.");
|
---|
530 |
|
---|
531 | var td = document.getElementById(m+"-"+d);
|
---|
532 | alert(td.childNodes[1]+"/"+v);
|
---|
533 | if (v=="")
|
---|
534 | {
|
---|
535 | td.childNodes[1].style.display="none";
|
---|
536 | td.title="Click to select this date.";
|
---|
537 | }
|
---|
538 | else
|
---|
539 | {
|
---|
540 | td.childNodes[1].style.display="";
|
---|
541 | td.title=v;
|
---|
542 | }
|
---|
543 |
|
---|
544 | };
|
---|
545 |
|
---|
546 | xmlHttp.send();
|
---|
547 | }
|
---|
548 |
|
---|
549 | function requestComment(yy, mm, dd)
|
---|
550 | {
|
---|
551 | var c = document.getElementById("comment");
|
---|
552 |
|
---|
553 | var y = c.getAttribute("data-y");
|
---|
554 | var m = c.getAttribute("data-m");
|
---|
555 | var d = c.getAttribute("data-d");
|
---|
556 |
|
---|
557 | if (y==yy && m==mm && d==dd)
|
---|
558 | return;
|
---|
559 |
|
---|
560 | var uri = "calendar.php?comment&y="+yy+"&m="+mm+"&d="+dd;
|
---|
561 | var xmlHttp = new XMLHttpRequest();
|
---|
562 | xmlHttp.open('POST', uri, true);
|
---|
563 | xmlHttp.onload = function ()
|
---|
564 | {
|
---|
565 | if (xmlHttp.status!=200)
|
---|
566 | {
|
---|
567 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
568 | return;
|
---|
569 | }
|
---|
570 |
|
---|
571 | var td = document.getElementById(mm+"-"+dd);
|
---|
572 |
|
---|
573 | c.color="#888";
|
---|
574 | if (xmlHttp.responseText=="")
|
---|
575 | {
|
---|
576 | c.value="enter comment here";
|
---|
577 | td.childNodes[1].style.display="none";
|
---|
578 | td.title="";
|
---|
579 | }
|
---|
580 | else
|
---|
581 | {
|
---|
582 | c.value = xmlHttp.responseText;
|
---|
583 | td.childNodes[1].style.display="";
|
---|
584 | td.title=xmlHttp.responseText;
|
---|
585 | }
|
---|
586 |
|
---|
587 | c.setAttribute("data-y", yy);
|
---|
588 | c.setAttribute("data-m", mm);
|
---|
589 | c.setAttribute("data-d", dd);
|
---|
590 | };
|
---|
591 |
|
---|
592 | xmlHttp.send();
|
---|
593 | }
|
---|
594 |
|
---|
595 | function requestAll(yy, mm)
|
---|
596 | {
|
---|
597 | var uri = "calendar.php?y="+yy+"&m="+mm;
|
---|
598 | var xmlHttp = new XMLHttpRequest();
|
---|
599 | xmlHttp.open('POST', uri, true);
|
---|
600 | xmlHttp.onload = function ()
|
---|
601 | {
|
---|
602 | if (xmlHttp.status!=200)
|
---|
603 | {
|
---|
604 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
605 | return;
|
---|
606 | }
|
---|
607 |
|
---|
608 | var lines = xmlHttp.responseText.split('\n');
|
---|
609 | if (lines.length==0)
|
---|
610 | return;
|
---|
611 |
|
---|
612 | for (var i=0; i<lines.length; i++)
|
---|
613 | {
|
---|
614 | var x = lines[i].split('\t');
|
---|
615 | if (x.length!=2)
|
---|
616 | continue;
|
---|
617 |
|
---|
618 | var td = document.getElementById(mm+"-"+x[0]);
|
---|
619 |
|
---|
620 | var div = document.createElement("div");
|
---|
621 | div.style.fontWeight="normal";
|
---|
622 | div.appendChild(document.createTextNode(x[1]));
|
---|
623 | td.appendChild(div);
|
---|
624 |
|
---|
625 | for (var j=0; j<institutes.length; j++)
|
---|
626 | if (x[1]==institutes[j])
|
---|
627 | {
|
---|
628 | div.className += " institute";
|
---|
629 | break;
|
---|
630 | }
|
---|
631 |
|
---|
632 | td.className += " enabled";
|
---|
633 | }
|
---|
634 | };
|
---|
635 |
|
---|
636 | xmlHttp.send();
|
---|
637 | }
|
---|
638 |
|
---|
639 | function requestAllComments(yy, mm)
|
---|
640 | {
|
---|
641 | var uri = "calendar.php?comment&y="+yy+"&m="+mm;
|
---|
642 | var xmlHttp = new XMLHttpRequest();
|
---|
643 | xmlHttp.open('POST', uri, true);
|
---|
644 | xmlHttp.onload = function ()
|
---|
645 | {
|
---|
646 | if (xmlHttp.status!=200)
|
---|
647 | {
|
---|
648 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
649 | return;
|
---|
650 | }
|
---|
651 |
|
---|
652 | if (xmlHttp.responseText<4)
|
---|
653 | return;
|
---|
654 |
|
---|
655 | var pos = 6;
|
---|
656 |
|
---|
657 | while (pos<xmlHttp.responseText.length)
|
---|
658 | {
|
---|
659 | var len = parseInt(xmlHttp.responseText.substr(pos-6, 4), 10);
|
---|
660 | var dd = parseInt(xmlHttp.responseText.substr(pos-2, 2), 10);
|
---|
661 | var com = xmlHttp.responseText.substr(pos, len);
|
---|
662 | pos += len+6;
|
---|
663 |
|
---|
664 | if (com!="")
|
---|
665 | {
|
---|
666 | var td = document.getElementById(mm+"-"+dd);
|
---|
667 | td.childNodes[1].style.display="";
|
---|
668 | td.title=com;
|
---|
669 | }
|
---|
670 | }
|
---|
671 | };
|
---|
672 |
|
---|
673 | xmlHttp.send();
|
---|
674 | }
|
---|
675 |
|
---|
676 | this.setDate = function()
|
---|
677 | {
|
---|
678 | request(this);
|
---|
679 | };
|
---|
680 |
|
---|
681 | this.changeUser = function()
|
---|
682 | {
|
---|
683 | var sib = this.nextSibling;
|
---|
684 | while (sib)
|
---|
685 | {
|
---|
686 | sib.style.backgroundColor = "";
|
---|
687 | sib = sib.nextSibling;
|
---|
688 | }
|
---|
689 |
|
---|
690 | sib = this.previousSibling;
|
---|
691 | while (sib)
|
---|
692 | {
|
---|
693 | sib.style.backgroundColor = "";
|
---|
694 | sib = sib.previousSibling;
|
---|
695 | }
|
---|
696 |
|
---|
697 | this.style.backgroundColor = "yellow";
|
---|
698 |
|
---|
699 | document.getElementById("body").setAttribute("data-user", this.firstChild.textContent);
|
---|
700 | };
|
---|
701 |
|
---|
702 | this.chooseDate = function()
|
---|
703 | {
|
---|
704 | while (document.getElementsByClassName("choosen")[0])
|
---|
705 | {
|
---|
706 | var e = document.getElementsByClassName("choosen")[0];
|
---|
707 | e.title = "Click to select this date.";
|
---|
708 | e.className = e.className.replace(/choosen/g, "");
|
---|
709 | e.onclick = function() {
|
---|
710 | this.chooseDate();
|
---|
711 | };
|
---|
712 | }
|
---|
713 |
|
---|
714 | this.className += " choosen";
|
---|
715 | this.title = "Click again to add or remove your name.";
|
---|
716 |
|
---|
717 | requestComment(this.yy, this.mm, this.dd);
|
---|
718 |
|
---|
719 | this.onclick = function() {
|
---|
720 | this.setDate();
|
---|
721 | };
|
---|
722 | };
|
---|
723 |
|
---|
724 | this.timeTrigger = function()
|
---|
725 | {
|
---|
726 | var now = new Date();
|
---|
727 | var ss = (now.getSeconds()<10)?"0"+now.getSeconds():now.getSeconds();
|
---|
728 | var mm = (now.getMinutes()<10)?"0"+now.getMinutes():now.getMinutes();
|
---|
729 | var hh = (now.getHours() <10)?"0"+now.getHours() :now.getHours();
|
---|
730 |
|
---|
731 | var kw = "KW" + this.getCalendarWeek(this.year, this.month, this.date);
|
---|
732 | var str = hh+":"+mm+":"+ss+"\u00a0["+kw+"]";
|
---|
733 | return str;
|
---|
734 | };
|
---|
735 |
|
---|
736 | this.getCell = function(tag, str, cssClass)
|
---|
737 | {
|
---|
738 | var El = document.createElement( tag );
|
---|
739 | El.appendChild(document.createTextNode( str ));
|
---|
740 | if (cssClass != null)
|
---|
741 | El.className = cssClass;
|
---|
742 | return El;
|
---|
743 | },
|
---|
744 |
|
---|
745 | this.switchMonth = function( s )
|
---|
746 | {
|
---|
747 | switch (s)
|
---|
748 | {
|
---|
749 | case "prev":
|
---|
750 | this.yy = (this.mm == 0) ? this.yy-1 : this.yy;
|
---|
751 | this.mm = (this.mm == 0) ? 11 : this.mm-1;
|
---|
752 | break;
|
---|
753 |
|
---|
754 | case "next":
|
---|
755 | this.yy = (this.mm == 11) ? this.yy+1 : this.yy;
|
---|
756 | this.mm = (this.mm == 11) ? 0 : this.mm+1;
|
---|
757 | break;
|
---|
758 |
|
---|
759 | case "prev_year":
|
---|
760 | this.yy = this.yy-1;
|
---|
761 | break;
|
---|
762 |
|
---|
763 | case "next_year":
|
---|
764 | this.yy = this.yy+1;
|
---|
765 | break;
|
---|
766 |
|
---|
767 | case "current":
|
---|
768 | this.yy = this.year;
|
---|
769 | this.mm = this.month;
|
---|
770 | break;
|
---|
771 | }
|
---|
772 | this.show();
|
---|
773 | }
|
---|
774 | }
|
---|
775 |
|
---|
776 | var DOMContentLoaded = false;
|
---|
777 | function addContentLoadListener (func)
|
---|
778 | {
|
---|
779 | if (document.addEventListener)
|
---|
780 | {
|
---|
781 | var DOMContentLoadFunction = function ()
|
---|
782 | {
|
---|
783 | window.DOMContentLoaded = true;
|
---|
784 | func();
|
---|
785 | };
|
---|
786 |
|
---|
787 | document.addEventListener("DOMContentLoaded", DOMContentLoadFunction, false);
|
---|
788 | }
|
---|
789 |
|
---|
790 | var oldfunc = (window.onload || new Function());
|
---|
791 |
|
---|
792 | window.onload = function ()
|
---|
793 | {
|
---|
794 | if (!window.DOMContentLoaded)
|
---|
795 | {
|
---|
796 | oldfunc();
|
---|
797 | func();
|
---|
798 | }
|
---|
799 | };
|
---|
800 | }
|
---|
801 |
|
---|
802 | addContentLoadListener( function() {
|
---|
803 | new CalendarJS().init("calendar");
|
---|
804 | //new CalendarJS().init("calendar", new Date(2009, 1, 15));
|
---|
805 | } ); |
---|