blob: 3d3519b40224e5d0a86e0ff43c87ad1c3eddf2d4 [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) {
118 $(repl('<span>Reference: <a href="#Form/%(ref_type)s/%(ref_name)s" \
119 onclick="cur_dialog.hide()">%(ref_type)s: %(ref_name)s</a></span>', this.ev))
120 .appendTo(this.widgets['Ref Link'])
121 }
122
123 $(repl('<a href="#Form/Event/%(name)s" \
124 onclick="cur_dialog.hide()">More Options</a>', this.ev))
125 .appendTo(this.widgets['Event Link'])
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530126 }
127
128 // event save
129 d.widgets['Save'].onclick = function() {
130 var d = me.event_dialog;
131
132 // save values
133 d.ev.description = d.widgets['Description'].value;
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530134 if(d.widgets['Cancel Event'].checked)
135 d.ev.event_type='Cancel';
136 else if(d.widgets['Public Event'].checked)
137 d.ev.event_type='Public';
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530138
139 me.event_dialog.hide();
140
141 // if new event
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530142 me.save_event(d.ev);
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530143 }
144 this.event_dialog = d;
145 }
146 this.event_dialog.ev = ev;
147 this.event_dialog.cal_ev = cal_ev ? cal_ev : null;
148 this.event_dialog.show();
149
150}
151
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530152Calendar.prototype.save_event = function(doc) {
153 var me = this;
154 save_doclist('Event', doc.name, 'Save', function(r) {
155 var doc = locals['Event'][r.docname];
156 var cal = erpnext.calendar;
157 cal.cur_view.refresh();
158
159 // if cancelled, hide
160 if(doc.event_type=='Cancel') {
161 $(cal.events_by_name[doc.name].body).toggle(false);
162 }
163 });
164}
165
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530166//------------------------------------------------------
167
168Calendar.prototype.add_event = function() {
169
170 var ev = LocalDB.create('Event');
171 ev = locals['Event'][ev];
172
173 ev.event_date = dateutil.obj_to_str(this.selected_date);
174 ev.event_hour = this.selected_hour+':00';
175 ev.event_type = 'Private';
176
177 this.show_event(ev);
178}
179//------------------------------------------------------
180
181Calendar.prototype.get_month_events = function(call_back) {
182 // ret fn
183 var me = this;
184 var f = function(r, rt) {
185 if(me.cur_view) me.cur_view.refresh();
186 if(call_back)call_back();
187 }
188
189 //load
190 var y=this.selected_date.getFullYear(); var m = this.selected_date.getMonth();
191 if(!this.events[y] || !this.events[y][m]) {
192 $c('webnotes.widgets.event.load_month_events', args = {
193 'month': m + 1,
194 'year' : y},
195 f);
196 }
197}
198//------------------------------------------------------
199
200Calendar.prototype.get_daily_event_list=function(day) {
201 var el = [];
202 var d = day.getDate(); var m = day.getMonth(); var y = day.getFullYear()
203 if(this.events[y] && this.events[y][m] &&
204 this.events[y][m][d]) {
205 var l = this.events[y][m][d]
206 for(var i in l) {
207 for(var j in l[i]) el[el.length] = l[i][j];
208 }
209 return el;
210 }
211 else return [];
212}
213//------------------------------------------------------
214
215Calendar.prototype.set_event = function(ev) {
216 // don't duplicate
217 if(this.events_by_name[ev.name]) {
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530218 return this.events_by_name[ev.name];
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530219 }
220
221 var dt = dateutil.str_to_obj(ev.event_date);
222 var m = dt.getMonth();
223 var d = dt.getDate();
224 var y = dt.getFullYear();
225
226 if(!this.events[y]) this.events[y] = [];
227 if(!this.events[y][m]) this.events[y][m] = [];
228 if(!this.events[y][m][d]) this.events[y][m][d] = [];
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530229 if(!this.events[y][m][d][cint(ev.event_hour)])
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530230 this.events[y][m][d][cint(ev.event_hour)] = [];
231
232 var cal_ev = new Calendar.CalEvent(ev, this);
233 this.events[y][m][d][cint(ev.event_hour)].push(cal_ev);
234 this.events_by_name[ev.name] = cal_ev;
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530235
236 return cal_ev;
237}
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530238
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530239//------------------------------------------------------
240
241Calendar.prototype.refresh = function(viewtype){//Sets the viewtype of the Calendar and Calls the View class based on the viewtype
242 if(viewtype)
243 this.viewtype = viewtype;
244 // switch view if reqd
245 if(this.cur_view.viewtype!=this.viewtype) {
246 this.cur_view.hide();
247 this.cur_view = this.views[this.viewtype];
248 this.cur_view.in_home = false; // for home page
249 this.cur_view.show();
250 }
251 else{
252 this.cur_view.refresh(this);
253 }
254}
255
256//------------------------------------------------------
257
258Calendar.CalEvent= function(doc, cal) {
259 this.body = document.createElement('div');
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530260 this.link = $a(this.body, 'a', '', {}, locals['Event'][doc.name].description || '');
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530261 this.doc = doc;
262 var me = this;
263
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530264 this.link.onclick = function() {
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530265 if(me.doc.name) {
266 cal.show_event(me.doc, me);
267 }
268 }
269}
270
271Calendar.CalEvent.prototype.show = function(vu) {
272
273 var t = this.doc.event_type;
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530274 this.my_class = 'cal_event_'+ t;
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530275
276 if(this.body.parentNode)
277 this.body.parentNode.removeChild(this.body);
278 vu.body.appendChild(this.body);
279
280 // refresh
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530281 this.link.innerHTML = this.doc.description || '';
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530282 this.body.className = this.my_class;
283}
284
Rushabh Mehtaaa999df2012-02-27 12:54:04 +0530285
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530286// ----------
287
288Calendar.View =function() { this.daystep = 0; this.monthstep = 0; }
289Calendar.View.prototype.init=function(cal) {
290 this.cal = cal;
291 this.body = $a(cal.body, 'div', 'cal_view_body');
292 this.body.style.display = 'none';
293 this.create_table();
294}
295
296
297Calendar.View.prototype.show=function() {
298 this.get_events(); this.refresh(); this.body.style.display = 'block';
299}
300
301Calendar.View.prototype.hide=function() { this.body.style.display = 'none';}
302
303Calendar.View.prototype.next = function() {
304 var s = this.cal.selected_date;
305 this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() + this.monthstep, s.getDate() + this.daystep);
306 this.get_events(); this.refresh();
307}
308
309Calendar.View.prototype.prev = function() {
310 var s = this.cal.selected_date;
311 this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() - this.monthstep, s.getDate() - this.daystep);
312 this.get_events(); this.refresh();
313}
314
315Calendar.View.prototype.get_events = function() {
316 this.cal.get_month_events();
317}
318Calendar.View.prototype.add_unit = function(vu) {
319 this.viewunits[this.viewunits.length] = vu;
320}
321Calendar.View.prototype.refresh_units = function() {
322 // load the events
323 if(locals['Event']) {
324 for(var name in locals['Event']) {
325 this.cal.set_event(locals['Event'][name]);
326 }
327 }
328
329
330 for(var r in this.table.rows) {
331 for(var c in this.table.rows[r].cells) {
332 if(this.table.rows[r].cells[c].viewunit) {
333 this.table.rows[r].cells[c].viewunit.refresh();
334 }
335 }
336 }
337}
338
339// ................. Month View..........................
340Calendar.MonthView = function(cal) { this.init(cal); this.monthstep = 1; this.rows = 5; this.cells = 7; }
341Calendar.MonthView.prototype=new Calendar.View();
342Calendar.MonthView.prototype.create_table = function() {
343
344 // create head
345 this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
346
347 // create headers
348 this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
349 var r = this.headtable.insertRow(0);
350 for(var j=0;j<7;j++) {
351 var cell = r.insertCell(j);
352 cell.innerHTML = erpnext.calendar.weekdays[j]; $w(cell, (100 / 7) + '%');
353 }
354
355 this.main = $a(this.body, 'div', 'cal_month_body');
356 this.table = $a(this.main, 'table', 'cal_month_table');
357 var me = this;
358
359 // create body
360 for(var i=0;i<5;i++) {
361 var r = this.table.insertRow(i);
362 for(var j=0;j<7;j++) {
363 var cell = r.insertCell(j);
364 cell.viewunit = new Calendar.MonthViewUnit(cell);
365 }
366 }
367}
368
369Calendar.MonthView.prototype.refresh = function() {
370 var c =this.cal.selected_date;
371 var me=this;
372 // fill other days
373
374 var cur_row = 0;
375
376 var cur_month = c.getMonth();
377 var cur_year = c.getFullYear();
378
379 var d = new Date(cur_year, cur_month, 1);
380 var day = 1 - d.getDay();
381
382
383 // set day headers
384 var d = new Date(cur_year, cur_month, day);
385
386 this.cal.view_title.innerHTML = month_list_full[cur_month] + ' ' + cur_year;
387
388 for(var i=0;i<6;i++) {
389 if((i<5) || cur_month==d.getMonth()) { // if this month
390 for(var j=0;j<7;j++) {
391 var cell = this.table.rows[cur_row].cells[j];
392
393 if((i<5) || cur_month==d.getMonth()) { // if this month
394 cell.viewunit.day = d;
395 cell.viewunit.hour = 8;
396 if(cur_month == d.getMonth()) {
397 cell.viewunit.is_disabled = false;
398
399 if(same_day(this.cal.todays_date, d))
400 cell.viewunit.is_today = true;
401 else
402 cell.viewunit.is_today = false;
403
404 } else {
405 cell.viewunit.is_disabled = true;
406 }
407 }
408 // new date
409 day++;
410 d = new Date(cur_year, cur_month, day);
411 }
412 }
413 cur_row++;
414 if(cur_row == 5) {cur_row = 0;} // back to top
415 }
416 this.refresh_units();
417
418}
419 // ................. Daily View..........................
420Calendar.DayView=function(cal){ this.init(cal); this.daystep = 1; }
421Calendar.DayView.prototype=new Calendar.View();
422Calendar.DayView.prototype.create_table = function() {
423
424 // create body
425 this.main = $a(this.body, 'div', 'cal_day_body');
426 this.table = $a(this.main, 'table', 'cal_day_table');
427 var me = this;
428
429 for(var i=0;i<24;i++) {
430 var r = this.table.insertRow(i);
431 for(var j=0;j<2;j++) {
432 var cell = r.insertCell(j);
433 if(j==0) {
434 var tmp = time_to_ampm((i)+':00');
435 cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
436 $w(cell, '10%');
437 } else {
438 cell.viewunit = new Calendar.DayViewUnit(cell);
439 cell.viewunit.hour = i;
440 $w(cell, '90%');
441 if((i>=7)&&(i<=20)) {
442 cell.viewunit.is_daytime = true;
443 }
444 }
445 }
446 }
447 }
448
449Calendar.DayView.prototype.refresh = function() {
450 var c =this.cal.selected_date;
451
452 // fill other days
453 var me=this;
454
455 this.cal.view_title.innerHTML = erpnext.calendar.weekdays[c.getDay()] + ', '
456 + c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear();
457
458 // headers
459 var d = c;
460
461 for(var i=0;i<24;i++) {
462 var cell = this.table.rows[i].cells[1];
463 if(same_day(this.cal.todays_date, d)) cell.viewunit.is_today = true;
464 else cell.viewunit.is_today = false;
465 cell.viewunit.day = d;
466 }
467 this.refresh_units();
468}
469
470// ................. Weekly View..........................
471Calendar.WeekView=function(cal) { this.init(cal); this.daystep = 7; }
472Calendar.WeekView.prototype=new Calendar.View();
473Calendar.WeekView.prototype.create_table = function() {
474
475 // create head
476 this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
477
478 // day headers
479 this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
480 var r = this.headtable.insertRow(0);
481 for(var j=0;j<8;j++) {
482 var cell = r.insertCell(j);
483 $w(cell, (100 / 8) + '%');
484 }
485
486 // hour header
487
488 // create body
489 this.main = $a(this.body, 'div', 'cal_week_body');
490 this.table = $a(this.main, 'table', 'cal_week_table');
491 var me = this;
492
493 for(var i=0;i<24;i++) {
494 var r = this.table.insertRow(i);
495 for(var j=0;j<8;j++) {
496 var cell = r.insertCell(j);
497 if(j==0) {
498 var tmp = time_to_ampm(i+':00');
499 cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
500
501 $w(cell, '10%');
502 } else {
503 cell.viewunit = new Calendar.WeekViewUnit(cell);
504 cell.viewunit.hour = i;
505 if((i>=7)&&(i<=20)) {
506 cell.viewunit.is_daytime = true;
507 }
508 }
509 }
510 }
511}
512
513Calendar.WeekView.prototype.refresh = function() {
514 var c =this.cal.selected_date;
515 // fill other days
516 var me=this;
517
518 this.cal.view_title.innerHTML = month_list_full[c.getMonth()] + ' ' + c.getFullYear();
519
520 // headers
521 var d = new Date(c.getFullYear(), c.getMonth(), c.getDate() - c.getDay());
522
523 for (var k=1;k<8;k++) {
524 this.headtable.rows[0].cells[k].innerHTML = erpnext.calendar.weekdays[d.getDay()] + ' ' + d.getDate();
525
526 for(var i=0;i<24;i++) {
527 var cell = this.table.rows[i].cells[k];
528 if(same_day(this.cal.todays_date, d))
529 cell.viewunit.is_today = true;
530 else cell.viewunit.is_today = false;
531
532 cell.viewunit.day = d;
533 //cell.viewunit.refresh();
534 }
535 d=new Date(d.getFullYear(),d.getMonth(),d.getDate() + 1);
536
537 }
538
539 this.refresh_units();
540}
541
542//------------------------------------------------------.
543
544Calendar.ViewUnit = function() {}
545Calendar.ViewUnit.prototype.init = function(parent) {
546 parent.style.border = "1px solid #CCC" ;
547 this.body = $a(parent, 'div', this.default_class);
548 this.parent = parent;
549
550 var me = this;
551 this.body.onclick = function() {
552 erpnext.calendar.selected_date = me.day;
553 erpnext.calendar.selected_hour = me.hour;
554
555 if(erpnext.calendar.cur_vu && erpnext.calendar.cur_vu!=me){
556 erpnext.calendar.cur_vu.deselect();
557 me.select();
558 erpnext.calendar.cur_vu = me;
559 }
560 }
561 this.body.ondblclick = function() {
562 erpnext.calendar.add_event();
563 }
564}
565
566Calendar.ViewUnit.prototype.set_header=function(v) {
567 this.header.innerHTML = v;
568}
569
570Calendar.ViewUnit.prototype.set_today = function() {
571 this.is_today = true;
572 this.set_display();
573}
574
575Calendar.ViewUnit.prototype.clear = function() {
576 if(this.header)this.header.innerHTML = '';
577
578 // clear body
579 while(this.body.childNodes.length)
580 this.body.removeChild(this.body.childNodes[0]);
581}
582
583Calendar.ViewUnit.prototype.set_display = function() {
584 var cn = '#FFF';
585
586 // colors
587 var col_tod_sel = '#EEE';
588 var col_tod = '#FFF';
589 var col_sel = '#EEF';
590
591 if(this.is_today) {
592 if(this.selected) cn = col_tod_sel;
593 else cn = col_tod;
594 } else
595 if(this.selected) cn = col_sel;
596
597 if(this.header) {
598 if(this.is_disabled) {
599 this.body.className = this.default_class + ' cal_vu_disabled';
600 this.header.style.color = '#BBB';
601 } else {
602 this.body.className = this.default_class;
603 this.header.style.color = '#000';
604 }
605
606 if(this.day&&this.day.getDay()==0)
607 this.header.style.backgroundColor = '#FEE';
608 else
609 this.header.style.backgroundColor = '';
610 }
611 this.parent.style.backgroundColor = cn;
612}
613
614Calendar.ViewUnit.prototype.is_selected = function() {
615 return (same_day(this.day, erpnext.calendar.selected_date)
616 && this.hour==erpnext.calendar.selected_hour)
617}
618
619Calendar.ViewUnit.prototype.get_event_list = function() {
620 var y = this.day.getFullYear();
621 var m = this.day.getMonth();
622 var d = this.day.getDate();
623 if(erpnext.calendar.events[y] && erpnext.calendar.events[y][m] &&
624 erpnext.calendar.events[y][m][d] &&
625 erpnext.calendar.events[y][m][d][this.hour]) {
626 return erpnext.calendar.events[y][m][d][this.hour];
627 } else
628 return [];
629}
630
631Calendar.ViewUnit.prototype.refresh = function() {
632 this.clear();
633
634 if(this.is_selected()) {
635 if(erpnext.calendar.cur_vu)erpnext.calendar.cur_vu.deselect();
636 this.selected = true;
637 erpnext.calendar.cur_vu = this;
638 }
639 this.set_display();
640 this.el = this.get_event_list();
641 if(this.onrefresh)this.onrefresh();
642
643 for(var i in this.el) {
644 this.el[i].show(this);
645 }
646
647 var me = this;
648}
649
650Calendar.ViewUnit.prototype.select=function() { this.selected = true; this.set_display(); }
651Calendar.ViewUnit.prototype.deselect=function() { this.selected = false; this.set_display(); }
652Calendar.ViewUnit.prototype.setevent=function() { }
653
654Calendar.MonthViewUnit=function(parent) {
655 this.header = $a(parent, 'div' , "cal_month_date");
656 this.default_class = "cal_month_unit";
657
658 this.init(parent);
659
660 this.onrefresh = function() {
661 this.header.innerHTML = this.day.getDate();
662 }
663}
664Calendar.MonthViewUnit.prototype = new Calendar.ViewUnit();
665Calendar.MonthViewUnit.prototype.is_selected = function() {
666 return same_day(this.day, erpnext.calendar.selected_date)
667}
668
669Calendar.MonthViewUnit.prototype.get_event_list = function() {
670 return erpnext.calendar.get_daily_event_list(this.day);
671}
672
673Calendar.DayViewUnit= function(parent) {
674 this.default_class = "cal_day_unit"; this.init(parent);
675}
676Calendar.DayViewUnit.prototype = new Calendar.ViewUnit();
677Calendar.DayViewUnit.prototype.onrefresh = function() {
678 if(this.el.length<3)
679 this.body.style.height = '30px';
680 else this.body.style.height = '';
681}
682
683Calendar.WeekViewUnit=function(parent) {
684 this.default_class = "cal_week_unit"; this.init(parent);
685}
686Calendar.WeekViewUnit.prototype = new Calendar.ViewUnit();
687Calendar.WeekViewUnit.prototype.onrefresh = function() {
688 if(this.el.length<3) this.body.style.height = '30px';
689 else this.body.style.height = '';
690}