blob: a9429f2ecdd31b9a6ffc57aee49f96b82396ef0a [file] [log] [blame]
Rushabh Mehtab73fa492012-02-24 15:07:39 +05301// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
2//
3// MIT License (MIT)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
17// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21//
22
23pscript.onload_calendar = function(wrapper) {
24 if(!erpnext.calendar) {
25 erpnext.calendar = new Calendar();
26 erpnext.calendar.init(wrapper);
Rushabh Mehta9b1afe12012-03-20 14:37:44 +053027
28 var me = this;
29 $(document).bind('rename', function(event, dt, old_name, new_name) {
30 erpnext.calendar.rename_notify(dt, old_name, new_name)
31 });
Rushabh Mehtab73fa492012-02-24 15:07:39 +053032 }
33}
34
35///// CALENDAR
36
37Calendar=function() {
38 this.views=[];
39 this.events = {};
Rushabh Mehtab73fa492012-02-24 15:07:39 +053040 this.events_by_name = {};
41 this.weekdays = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
42}
43
44Calendar.prototype.init=function (parent) {
45
46 this.wrapper = parent;
47 this.body = $('.cal_body').get(0);
48
49 //this.make_head_buttons();
50 //this.make_header();
51 this.view_title = $('.cal_view_title').get(0);
52
53 this.todays_date = new Date();
54 this.selected_date = this.todays_date;
55 this.selected_hour = 8;
56
57 // Create views
58 this.views['Month'] = new Calendar.MonthView(this);
59 this.views['Week'] = new Calendar.WeekView(this);
60 this.views['Day'] = new Calendar.DayView(this);
61
62 // Month view as initial
Rushabh Mehtaaa999df2012-02-27 12:54:04 +053063 this.cur_view = this.views['Month'];
64 this.views['Month'].show();
Rushabh Mehtab73fa492012-02-24 15:07:39 +053065
66}
67
68Calendar.prototype.rename_notify = function(dt, old_name, new_name) {
69 // calendar
Rushabh Mehta9b1afe12012-03-20 14:37:44 +053070 if(dt = 'Event'){
Rushabh Mehtaaa999df2012-02-27 12:54:04 +053071 if(this.events_by_name[old_name]) {
72 delete this.events_by_name[old_name];
73 }
74 }
Rushabh Mehtab73fa492012-02-24 15:07:39 +053075}
76
77//------------------------------------------------------
78
79Calendar.prototype.show_event = function(ev, cal_ev) {
80 var me = this;
81 if(!this.event_dialog) {
82 var d = new Dialog(400, 400, 'Calendar Event');
83 d.make_body([
84 ['HTML','Heading']
85 ,['Text','Description']
Rushabh Mehta586c6f32012-08-07 16:36:40 +053086 ,['HTML', 'Ref Link']
Rushabh Mehtab73fa492012-02-24 15:07:39 +053087 ,['Check', 'Public Event']
88 ,['Check', 'Cancel Event']
89 ,['HTML', 'Event Link']
90 ,['Button', 'Save']
91 ])
92
93 // show the event when the dialog opens
94 d.onshow = function() {
95 // heading
96 var c = me.selected_date;
97 var tmp = time_to_ampm(this.ev.event_hour);
98 tmp = tmp[0]+':'+tmp[1]+' '+tmp[2];
99
100 this.widgets['Heading'].innerHTML =
101 '<div style="text-align: center; padding:4px; font-size: 14px">'
102 + erpnext.calendar.weekdays[c.getDay()] + ', ' + c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear()
103 + ' - <b>'+tmp+'</b></div>';
104
105 // set
106 this.widgets['Description'].value = cstr(this.ev.description);
107
108 this.widgets['Public Event'].checked = false;
109 this.widgets['Cancel Event'].checked = false;
110
111 if(this.ev.event_type=='Public')
112 this.widgets['Public Event'].checked = true;
113
114 this.widgets['Event Link'].innerHTML = '';
Rushabh Mehta586c6f32012-08-07 16:36:40 +0530115 this.widgets['Ref Link'].innerHTML = '';
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530116
Rushabh Mehta586c6f32012-08-07 16:36:40 +0530117 if(this.ev.ref_type) {
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530118 $(repl('<table style="width: 100%;"><tr>\
119 <td style="width: 30%"><b>Reference:</b></td>\
120 <td><a href="#Form/%(ref_type)s/%(ref_name)s" \
121 onclick="cur_dialog.hide()">%(ref_type)s: %(ref_name)s</a></td>\
122 </tr></table>', this.ev))
Rushabh Mehta586c6f32012-08-07 16:36:40 +0530123 .appendTo(this.widgets['Ref Link'])
124 }
125
126 $(repl('<a href="#Form/Event/%(name)s" \
127 onclick="cur_dialog.hide()">More Options</a>', this.ev))
128 .appendTo(this.widgets['Event Link'])
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530129 }
130
131 // event save
132 d.widgets['Save'].onclick = function() {
133 var d = me.event_dialog;
134
135 // save values
136 d.ev.description = d.widgets['Description'].value;
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530137 if(d.widgets['Cancel Event'].checked)
138 d.ev.event_type='Cancel';
139 else if(d.widgets['Public Event'].checked)
140 d.ev.event_type='Public';
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530141
142 me.event_dialog.hide();
143
144 // if new event
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530145 me.save_event(d.ev);
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530146 }
147 this.event_dialog = d;
148 }
149 this.event_dialog.ev = ev;
150 this.event_dialog.cal_ev = cal_ev ? cal_ev : null;
151 this.event_dialog.show();
152
153}
154
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530155Calendar.prototype.save_event = function(doc) {
156 var me = this;
157 save_doclist('Event', doc.name, 'Save', function(r) {
158 var doc = locals['Event'][r.docname];
159 var cal = erpnext.calendar;
160 cal.cur_view.refresh();
161
162 // if cancelled, hide
163 if(doc.event_type=='Cancel') {
164 $(cal.events_by_name[doc.name].body).toggle(false);
165 }
166 });
167}
168
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530169//------------------------------------------------------
170
171Calendar.prototype.add_event = function() {
172
173 var ev = LocalDB.create('Event');
174 ev = locals['Event'][ev];
175
176 ev.event_date = dateutil.obj_to_str(this.selected_date);
177 ev.event_hour = this.selected_hour+':00';
178 ev.event_type = 'Private';
179
180 this.show_event(ev);
181}
182//------------------------------------------------------
183
184Calendar.prototype.get_month_events = function(call_back) {
185 // ret fn
186 var me = this;
187 var f = function(r, rt) {
188 if(me.cur_view) me.cur_view.refresh();
189 if(call_back)call_back();
190 }
191
192 //load
193 var y=this.selected_date.getFullYear(); var m = this.selected_date.getMonth();
194 if(!this.events[y] || !this.events[y][m]) {
195 $c('webnotes.widgets.event.load_month_events', args = {
196 'month': m + 1,
197 'year' : y},
198 f);
199 }
200}
201//------------------------------------------------------
202
203Calendar.prototype.get_daily_event_list=function(day) {
204 var el = [];
205 var d = day.getDate(); var m = day.getMonth(); var y = day.getFullYear()
206 if(this.events[y] && this.events[y][m] &&
207 this.events[y][m][d]) {
208 var l = this.events[y][m][d]
209 for(var i in l) {
210 for(var j in l[i]) el[el.length] = l[i][j];
211 }
212 return el;
213 }
214 else return [];
215}
216//------------------------------------------------------
217
218Calendar.prototype.set_event = function(ev) {
219 // don't duplicate
220 if(this.events_by_name[ev.name]) {
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530221 return this.events_by_name[ev.name];
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530222 }
223
224 var dt = dateutil.str_to_obj(ev.event_date);
225 var m = dt.getMonth();
226 var d = dt.getDate();
227 var y = dt.getFullYear();
228
229 if(!this.events[y]) this.events[y] = [];
230 if(!this.events[y][m]) this.events[y][m] = [];
231 if(!this.events[y][m][d]) this.events[y][m][d] = [];
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530232 if(!this.events[y][m][d][cint(ev.event_hour)])
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530233 this.events[y][m][d][cint(ev.event_hour)] = [];
234
235 var cal_ev = new Calendar.CalEvent(ev, this);
236 this.events[y][m][d][cint(ev.event_hour)].push(cal_ev);
237 this.events_by_name[ev.name] = cal_ev;
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530238
239 return cal_ev;
240}
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530241
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530242//------------------------------------------------------
243
244Calendar.prototype.refresh = function(viewtype){//Sets the viewtype of the Calendar and Calls the View class based on the viewtype
245 if(viewtype)
246 this.viewtype = viewtype;
247 // switch view if reqd
248 if(this.cur_view.viewtype!=this.viewtype) {
249 this.cur_view.hide();
250 this.cur_view = this.views[this.viewtype];
251 this.cur_view.in_home = false; // for home page
252 this.cur_view.show();
253 }
254 else{
255 this.cur_view.refresh(this);
256 }
257}
258
259//------------------------------------------------------
260
261Calendar.CalEvent= function(doc, cal) {
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530262 var me = this;
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530263 me.doc = doc;
264
265 this.body = $("<div class='label cal_event'></div>")
266 .html(doc.description)
267 .css({"cursor":"pointer"})
268 .attr("data-event", doc.name)
269 .click(function() {
270 var doc = locals["Event"][$(this).attr("data-event")];
271 cal.show_event(doc, me);
272 })
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530273
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530274 this.show = function(vu) {
275 me.body
276 .html(me.doc.description)
277 .css({"width": ($(vu.body).width()-10)})
278 .appendTo(vu.body)
279 .removeClass("label-success").removeClass("label-info")
280 .addClass(me.doc.event_type=="Public" ? "label-success" : "label-info")
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530281 }
282}
283
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530284
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530285// ----------
286
287Calendar.View =function() { this.daystep = 0; this.monthstep = 0; }
288Calendar.View.prototype.init=function(cal) {
289 this.cal = cal;
290 this.body = $a(cal.body, 'div', 'cal_view_body');
291 this.body.style.display = 'none';
292 this.create_table();
293}
294
295
296Calendar.View.prototype.show=function() {
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530297 this.body.style.display = 'block';
298 this.get_events(); this.refresh();
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530299}
300
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530301Calendar.View.prototype.hide=function() {
302 this.body.style.display = 'none';
303}
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530304
305Calendar.View.prototype.next = function() {
306 var s = this.cal.selected_date;
307 this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() + this.monthstep, s.getDate() + this.daystep);
308 this.get_events(); this.refresh();
309}
310
311Calendar.View.prototype.prev = function() {
312 var s = this.cal.selected_date;
313 this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() - this.monthstep, s.getDate() - this.daystep);
314 this.get_events(); this.refresh();
315}
316
317Calendar.View.prototype.get_events = function() {
318 this.cal.get_month_events();
319}
320Calendar.View.prototype.add_unit = function(vu) {
321 this.viewunits[this.viewunits.length] = vu;
322}
323Calendar.View.prototype.refresh_units = function() {
324 // load the events
325 if(locals['Event']) {
326 for(var name in locals['Event']) {
327 this.cal.set_event(locals['Event'][name]);
328 }
329 }
330
331
332 for(var r in this.table.rows) {
333 for(var c in this.table.rows[r].cells) {
334 if(this.table.rows[r].cells[c].viewunit) {
335 this.table.rows[r].cells[c].viewunit.refresh();
336 }
337 }
338 }
339}
340
341// ................. Month View..........................
342Calendar.MonthView = function(cal) { this.init(cal); this.monthstep = 1; this.rows = 5; this.cells = 7; }
343Calendar.MonthView.prototype=new Calendar.View();
344Calendar.MonthView.prototype.create_table = function() {
345
346 // create head
347 this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
348
349 // create headers
350 this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
351 var r = this.headtable.insertRow(0);
352 for(var j=0;j<7;j++) {
353 var cell = r.insertCell(j);
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530354 cell.innerHTML = erpnext.calendar.weekdays[j];
355 $w(cell, (100 / 7) + '%');
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530356 }
357
358 this.main = $a(this.body, 'div', 'cal_month_body');
359 this.table = $a(this.main, 'table', 'cal_month_table');
360 var me = this;
361
362 // create body
363 for(var i=0;i<5;i++) {
364 var r = this.table.insertRow(i);
365 for(var j=0;j<7;j++) {
366 var cell = r.insertCell(j);
367 cell.viewunit = new Calendar.MonthViewUnit(cell);
368 }
369 }
370}
371
372Calendar.MonthView.prototype.refresh = function() {
373 var c =this.cal.selected_date;
374 var me=this;
375 // fill other days
376
377 var cur_row = 0;
378
379 var cur_month = c.getMonth();
380 var cur_year = c.getFullYear();
381
382 var d = new Date(cur_year, cur_month, 1);
383 var day = 1 - d.getDay();
384
385
386 // set day headers
387 var d = new Date(cur_year, cur_month, day);
388
389 this.cal.view_title.innerHTML = month_list_full[cur_month] + ' ' + cur_year;
390
391 for(var i=0;i<6;i++) {
392 if((i<5) || cur_month==d.getMonth()) { // if this month
393 for(var j=0;j<7;j++) {
394 var cell = this.table.rows[cur_row].cells[j];
395
396 if((i<5) || cur_month==d.getMonth()) { // if this month
397 cell.viewunit.day = d;
398 cell.viewunit.hour = 8;
399 if(cur_month == d.getMonth()) {
400 cell.viewunit.is_disabled = false;
401
402 if(same_day(this.cal.todays_date, d))
403 cell.viewunit.is_today = true;
404 else
405 cell.viewunit.is_today = false;
406
407 } else {
408 cell.viewunit.is_disabled = true;
409 }
410 }
411 // new date
412 day++;
413 d = new Date(cur_year, cur_month, day);
414 }
415 }
416 cur_row++;
417 if(cur_row == 5) {cur_row = 0;} // back to top
418 }
419 this.refresh_units();
420
421}
422 // ................. Daily View..........................
423Calendar.DayView=function(cal){ this.init(cal); this.daystep = 1; }
424Calendar.DayView.prototype=new Calendar.View();
425Calendar.DayView.prototype.create_table = function() {
426
427 // create body
428 this.main = $a(this.body, 'div', 'cal_day_body');
429 this.table = $a(this.main, 'table', 'cal_day_table');
430 var me = this;
431
432 for(var i=0;i<24;i++) {
433 var r = this.table.insertRow(i);
434 for(var j=0;j<2;j++) {
435 var cell = r.insertCell(j);
436 if(j==0) {
437 var tmp = time_to_ampm((i)+':00');
438 cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
439 $w(cell, '10%');
440 } else {
441 cell.viewunit = new Calendar.DayViewUnit(cell);
442 cell.viewunit.hour = i;
443 $w(cell, '90%');
444 if((i>=7)&&(i<=20)) {
445 cell.viewunit.is_daytime = true;
446 }
447 }
448 }
449 }
450 }
451
452Calendar.DayView.prototype.refresh = function() {
453 var c =this.cal.selected_date;
454
455 // fill other days
456 var me=this;
457
458 this.cal.view_title.innerHTML = erpnext.calendar.weekdays[c.getDay()] + ', '
459 + c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear();
460
461 // headers
462 var d = c;
463
464 for(var i=0;i<24;i++) {
465 var cell = this.table.rows[i].cells[1];
466 if(same_day(this.cal.todays_date, d)) cell.viewunit.is_today = true;
467 else cell.viewunit.is_today = false;
468 cell.viewunit.day = d;
469 }
470 this.refresh_units();
471}
472
473// ................. Weekly View..........................
474Calendar.WeekView=function(cal) { this.init(cal); this.daystep = 7; }
475Calendar.WeekView.prototype=new Calendar.View();
476Calendar.WeekView.prototype.create_table = function() {
477
478 // create head
479 this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
480
481 // day headers
482 this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
483 var r = this.headtable.insertRow(0);
484 for(var j=0;j<8;j++) {
485 var cell = r.insertCell(j);
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530486 }
487
488 // hour header
489
490 // create body
491 this.main = $a(this.body, 'div', 'cal_week_body');
492 this.table = $a(this.main, 'table', 'cal_week_table');
493 var me = this;
494
495 for(var i=0;i<24;i++) {
496 var r = this.table.insertRow(i);
497 for(var j=0;j<8;j++) {
498 var cell = r.insertCell(j);
499 if(j==0) {
500 var tmp = time_to_ampm(i+':00');
501 cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
502
503 $w(cell, '10%');
504 } else {
505 cell.viewunit = new Calendar.WeekViewUnit(cell);
506 cell.viewunit.hour = i;
507 if((i>=7)&&(i<=20)) {
508 cell.viewunit.is_daytime = true;
509 }
510 }
511 }
512 }
513}
514
515Calendar.WeekView.prototype.refresh = function() {
516 var c =this.cal.selected_date;
517 // fill other days
518 var me=this;
519
520 this.cal.view_title.innerHTML = month_list_full[c.getMonth()] + ' ' + c.getFullYear();
521
522 // headers
523 var d = new Date(c.getFullYear(), c.getMonth(), c.getDate() - c.getDay());
524
525 for (var k=1;k<8;k++) {
526 this.headtable.rows[0].cells[k].innerHTML = erpnext.calendar.weekdays[d.getDay()] + ' ' + d.getDate();
527
528 for(var i=0;i<24;i++) {
529 var cell = this.table.rows[i].cells[k];
530 if(same_day(this.cal.todays_date, d))
531 cell.viewunit.is_today = true;
532 else cell.viewunit.is_today = false;
533
534 cell.viewunit.day = d;
535 //cell.viewunit.refresh();
536 }
537 d=new Date(d.getFullYear(),d.getMonth(),d.getDate() + 1);
538
539 }
540
541 this.refresh_units();
542}
543
544//------------------------------------------------------.
545
546Calendar.ViewUnit = function() {}
547Calendar.ViewUnit.prototype.init = function(parent) {
548 parent.style.border = "1px solid #CCC" ;
549 this.body = $a(parent, 'div', this.default_class);
550 this.parent = parent;
551
552 var me = this;
553 this.body.onclick = function() {
554 erpnext.calendar.selected_date = me.day;
555 erpnext.calendar.selected_hour = me.hour;
556
557 if(erpnext.calendar.cur_vu && erpnext.calendar.cur_vu!=me){
558 erpnext.calendar.cur_vu.deselect();
559 me.select();
560 erpnext.calendar.cur_vu = me;
561 }
562 }
563 this.body.ondblclick = function() {
564 erpnext.calendar.add_event();
565 }
566}
567
568Calendar.ViewUnit.prototype.set_header=function(v) {
569 this.header.innerHTML = v;
570}
571
572Calendar.ViewUnit.prototype.set_today = function() {
573 this.is_today = true;
574 this.set_display();
575}
576
577Calendar.ViewUnit.prototype.clear = function() {
578 if(this.header)this.header.innerHTML = '';
579
580 // clear body
581 while(this.body.childNodes.length)
582 this.body.removeChild(this.body.childNodes[0]);
583}
584
585Calendar.ViewUnit.prototype.set_display = function() {
586 var cn = '#FFF';
587
588 // colors
589 var col_tod_sel = '#EEE';
590 var col_tod = '#FFF';
591 var col_sel = '#EEF';
592
593 if(this.is_today) {
594 if(this.selected) cn = col_tod_sel;
595 else cn = col_tod;
596 } else
597 if(this.selected) cn = col_sel;
598
599 if(this.header) {
600 if(this.is_disabled) {
601 this.body.className = this.default_class + ' cal_vu_disabled';
602 this.header.style.color = '#BBB';
603 } else {
604 this.body.className = this.default_class;
605 this.header.style.color = '#000';
606 }
607
608 if(this.day&&this.day.getDay()==0)
609 this.header.style.backgroundColor = '#FEE';
610 else
611 this.header.style.backgroundColor = '';
612 }
613 this.parent.style.backgroundColor = cn;
614}
615
616Calendar.ViewUnit.prototype.is_selected = function() {
617 return (same_day(this.day, erpnext.calendar.selected_date)
618 && this.hour==erpnext.calendar.selected_hour)
619}
620
621Calendar.ViewUnit.prototype.get_event_list = function() {
622 var y = this.day.getFullYear();
623 var m = this.day.getMonth();
624 var d = this.day.getDate();
625 if(erpnext.calendar.events[y] && erpnext.calendar.events[y][m] &&
626 erpnext.calendar.events[y][m][d] &&
627 erpnext.calendar.events[y][m][d][this.hour]) {
628 return erpnext.calendar.events[y][m][d][this.hour];
629 } else
630 return [];
631}
632
633Calendar.ViewUnit.prototype.refresh = function() {
634 this.clear();
635
636 if(this.is_selected()) {
637 if(erpnext.calendar.cur_vu)erpnext.calendar.cur_vu.deselect();
638 this.selected = true;
639 erpnext.calendar.cur_vu = this;
640 }
641 this.set_display();
642 this.el = this.get_event_list();
643 if(this.onrefresh)this.onrefresh();
644
645 for(var i in this.el) {
646 this.el[i].show(this);
647 }
648
649 var me = this;
650}
651
652Calendar.ViewUnit.prototype.select=function() { this.selected = true; this.set_display(); }
653Calendar.ViewUnit.prototype.deselect=function() { this.selected = false; this.set_display(); }
654Calendar.ViewUnit.prototype.setevent=function() { }
655
656Calendar.MonthViewUnit=function(parent) {
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530657 var me = this;
658 this.header = $("<div class='cal_month_date'></div>")
659 .appendTo(parent)
660 .css({"cursor":"pointer"})
661 .click(function() {
662 me.body.onclick();
663 })
664 .bind("dblclick", function() {
665 me.body.ondblclick();
666 })
667 .get(0);
668
669 this.default_class = "cal_month_unit";
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530670 this.init(parent);
671
672 this.onrefresh = function() {
673 this.header.innerHTML = this.day.getDate();
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530674 }
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530675}
676Calendar.MonthViewUnit.prototype = new Calendar.ViewUnit();
677Calendar.MonthViewUnit.prototype.is_selected = function() {
678 return same_day(this.day, erpnext.calendar.selected_date)
679}
680
681Calendar.MonthViewUnit.prototype.get_event_list = function() {
682 return erpnext.calendar.get_daily_event_list(this.day);
683}
684
685Calendar.DayViewUnit= function(parent) {
686 this.default_class = "cal_day_unit"; this.init(parent);
687}
688Calendar.DayViewUnit.prototype = new Calendar.ViewUnit();
689Calendar.DayViewUnit.prototype.onrefresh = function() {
690 if(this.el.length<3)
691 this.body.style.height = '30px';
692 else this.body.style.height = '';
693}
694
695Calendar.WeekViewUnit=function(parent) {
696 this.default_class = "cal_week_unit"; this.init(parent);
697}
698Calendar.WeekViewUnit.prototype = new Calendar.ViewUnit();
699Calendar.WeekViewUnit.prototype.onrefresh = function() {
700 if(this.el.length<3) this.body.style.height = '30px';
701 else this.body.style.height = '';
702}