blob: 0f4ff3b639a11d1a1730266fc4ab325658a16376 [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)
Rushabh Mehtaa44b66e2012-11-23 16:34:42 +0530267 .attr("title", doc.description)
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530268 .css({"cursor":"pointer"})
269 .attr("data-event", doc.name)
270 .click(function() {
271 var doc = locals["Event"][$(this).attr("data-event")];
272 cal.show_event(doc, me);
273 })
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530274
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530275 this.show = function(vu) {
276 me.body
277 .html(me.doc.description)
278 .css({"width": ($(vu.body).width()-10)})
279 .appendTo(vu.body)
280 .removeClass("label-success").removeClass("label-info")
281 .addClass(me.doc.event_type=="Public" ? "label-success" : "label-info")
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530282 }
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() {
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530298 this.body.style.display = 'block';
299 this.get_events(); this.refresh();
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530300}
301
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530302Calendar.View.prototype.hide=function() {
303 this.body.style.display = 'none';
304}
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530305
306Calendar.View.prototype.next = function() {
307 var s = this.cal.selected_date;
308 this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() + this.monthstep, s.getDate() + this.daystep);
309 this.get_events(); this.refresh();
310}
311
312Calendar.View.prototype.prev = function() {
313 var s = this.cal.selected_date;
314 this.cal.selected_date = new Date(s.getFullYear(), s.getMonth() - this.monthstep, s.getDate() - this.daystep);
315 this.get_events(); this.refresh();
316}
317
318Calendar.View.prototype.get_events = function() {
319 this.cal.get_month_events();
320}
321Calendar.View.prototype.add_unit = function(vu) {
322 this.viewunits[this.viewunits.length] = vu;
323}
324Calendar.View.prototype.refresh_units = function() {
325 // load the events
326 if(locals['Event']) {
327 for(var name in locals['Event']) {
328 this.cal.set_event(locals['Event'][name]);
329 }
330 }
331
332
333 for(var r in this.table.rows) {
334 for(var c in this.table.rows[r].cells) {
335 if(this.table.rows[r].cells[c].viewunit) {
336 this.table.rows[r].cells[c].viewunit.refresh();
337 }
338 }
339 }
340}
341
342// ................. Month View..........................
343Calendar.MonthView = function(cal) { this.init(cal); this.monthstep = 1; this.rows = 5; this.cells = 7; }
344Calendar.MonthView.prototype=new Calendar.View();
345Calendar.MonthView.prototype.create_table = function() {
346
347 // create head
348 this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
349
350 // create headers
351 this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
352 var r = this.headtable.insertRow(0);
353 for(var j=0;j<7;j++) {
354 var cell = r.insertCell(j);
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530355 cell.innerHTML = erpnext.calendar.weekdays[j];
356 $w(cell, (100 / 7) + '%');
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530357 }
358
359 this.main = $a(this.body, 'div', 'cal_month_body');
360 this.table = $a(this.main, 'table', 'cal_month_table');
361 var me = this;
362
363 // create body
364 for(var i=0;i<5;i++) {
365 var r = this.table.insertRow(i);
366 for(var j=0;j<7;j++) {
367 var cell = r.insertCell(j);
368 cell.viewunit = new Calendar.MonthViewUnit(cell);
369 }
370 }
371}
372
373Calendar.MonthView.prototype.refresh = function() {
374 var c =this.cal.selected_date;
375 var me=this;
376 // fill other days
377
378 var cur_row = 0;
379
380 var cur_month = c.getMonth();
381 var cur_year = c.getFullYear();
382
383 var d = new Date(cur_year, cur_month, 1);
384 var day = 1 - d.getDay();
385
386
387 // set day headers
388 var d = new Date(cur_year, cur_month, day);
389
390 this.cal.view_title.innerHTML = month_list_full[cur_month] + ' ' + cur_year;
391
392 for(var i=0;i<6;i++) {
393 if((i<5) || cur_month==d.getMonth()) { // if this month
394 for(var j=0;j<7;j++) {
395 var cell = this.table.rows[cur_row].cells[j];
396
397 if((i<5) || cur_month==d.getMonth()) { // if this month
398 cell.viewunit.day = d;
399 cell.viewunit.hour = 8;
400 if(cur_month == d.getMonth()) {
401 cell.viewunit.is_disabled = false;
402
403 if(same_day(this.cal.todays_date, d))
404 cell.viewunit.is_today = true;
405 else
406 cell.viewunit.is_today = false;
407
408 } else {
409 cell.viewunit.is_disabled = true;
410 }
411 }
412 // new date
413 day++;
414 d = new Date(cur_year, cur_month, day);
415 }
416 }
417 cur_row++;
418 if(cur_row == 5) {cur_row = 0;} // back to top
419 }
420 this.refresh_units();
421
422}
423 // ................. Daily View..........................
424Calendar.DayView=function(cal){ this.init(cal); this.daystep = 1; }
425Calendar.DayView.prototype=new Calendar.View();
426Calendar.DayView.prototype.create_table = function() {
427
428 // create body
429 this.main = $a(this.body, 'div', 'cal_day_body');
430 this.table = $a(this.main, 'table', 'cal_day_table');
431 var me = this;
432
433 for(var i=0;i<24;i++) {
434 var r = this.table.insertRow(i);
435 for(var j=0;j<2;j++) {
436 var cell = r.insertCell(j);
437 if(j==0) {
438 var tmp = time_to_ampm((i)+':00');
439 cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
440 $w(cell, '10%');
441 } else {
442 cell.viewunit = new Calendar.DayViewUnit(cell);
443 cell.viewunit.hour = i;
444 $w(cell, '90%');
445 if((i>=7)&&(i<=20)) {
446 cell.viewunit.is_daytime = true;
447 }
448 }
449 }
450 }
451 }
452
453Calendar.DayView.prototype.refresh = function() {
454 var c =this.cal.selected_date;
455
456 // fill other days
457 var me=this;
458
459 this.cal.view_title.innerHTML = erpnext.calendar.weekdays[c.getDay()] + ', '
460 + c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear();
461
462 // headers
463 var d = c;
464
465 for(var i=0;i<24;i++) {
466 var cell = this.table.rows[i].cells[1];
467 if(same_day(this.cal.todays_date, d)) cell.viewunit.is_today = true;
468 else cell.viewunit.is_today = false;
469 cell.viewunit.day = d;
470 }
471 this.refresh_units();
472}
473
474// ................. Weekly View..........................
475Calendar.WeekView=function(cal) { this.init(cal); this.daystep = 7; }
476Calendar.WeekView.prototype=new Calendar.View();
477Calendar.WeekView.prototype.create_table = function() {
478
479 // create head
480 this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
481
482 // day headers
483 this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
484 var r = this.headtable.insertRow(0);
485 for(var j=0;j<8;j++) {
486 var cell = r.insertCell(j);
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530487 }
488
489 // hour header
490
491 // create body
492 this.main = $a(this.body, 'div', 'cal_week_body');
493 this.table = $a(this.main, 'table', 'cal_week_table');
494 var me = this;
495
496 for(var i=0;i<24;i++) {
497 var r = this.table.insertRow(i);
498 for(var j=0;j<8;j++) {
499 var cell = r.insertCell(j);
500 if(j==0) {
501 var tmp = time_to_ampm(i+':00');
502 cell.innerHTML = tmp[0]+':'+tmp[1]+' '+tmp[2];
503
504 $w(cell, '10%');
505 } else {
506 cell.viewunit = new Calendar.WeekViewUnit(cell);
507 cell.viewunit.hour = i;
508 if((i>=7)&&(i<=20)) {
509 cell.viewunit.is_daytime = true;
510 }
511 }
512 }
513 }
514}
515
516Calendar.WeekView.prototype.refresh = function() {
517 var c =this.cal.selected_date;
518 // fill other days
519 var me=this;
520
521 this.cal.view_title.innerHTML = month_list_full[c.getMonth()] + ' ' + c.getFullYear();
522
523 // headers
524 var d = new Date(c.getFullYear(), c.getMonth(), c.getDate() - c.getDay());
525
526 for (var k=1;k<8;k++) {
527 this.headtable.rows[0].cells[k].innerHTML = erpnext.calendar.weekdays[d.getDay()] + ' ' + d.getDate();
528
529 for(var i=0;i<24;i++) {
530 var cell = this.table.rows[i].cells[k];
531 if(same_day(this.cal.todays_date, d))
532 cell.viewunit.is_today = true;
533 else cell.viewunit.is_today = false;
534
535 cell.viewunit.day = d;
536 //cell.viewunit.refresh();
537 }
538 d=new Date(d.getFullYear(),d.getMonth(),d.getDate() + 1);
539
540 }
541
542 this.refresh_units();
543}
544
545//------------------------------------------------------.
546
547Calendar.ViewUnit = function() {}
548Calendar.ViewUnit.prototype.init = function(parent) {
549 parent.style.border = "1px solid #CCC" ;
550 this.body = $a(parent, 'div', this.default_class);
551 this.parent = parent;
552
553 var me = this;
554 this.body.onclick = function() {
555 erpnext.calendar.selected_date = me.day;
556 erpnext.calendar.selected_hour = me.hour;
557
558 if(erpnext.calendar.cur_vu && erpnext.calendar.cur_vu!=me){
559 erpnext.calendar.cur_vu.deselect();
560 me.select();
561 erpnext.calendar.cur_vu = me;
562 }
563 }
564 this.body.ondblclick = function() {
565 erpnext.calendar.add_event();
566 }
567}
568
569Calendar.ViewUnit.prototype.set_header=function(v) {
570 this.header.innerHTML = v;
571}
572
573Calendar.ViewUnit.prototype.set_today = function() {
574 this.is_today = true;
575 this.set_display();
576}
577
578Calendar.ViewUnit.prototype.clear = function() {
579 if(this.header)this.header.innerHTML = '';
580
581 // clear body
582 while(this.body.childNodes.length)
583 this.body.removeChild(this.body.childNodes[0]);
584}
585
586Calendar.ViewUnit.prototype.set_display = function() {
587 var cn = '#FFF';
588
589 // colors
590 var col_tod_sel = '#EEE';
591 var col_tod = '#FFF';
592 var col_sel = '#EEF';
593
594 if(this.is_today) {
595 if(this.selected) cn = col_tod_sel;
596 else cn = col_tod;
597 } else
598 if(this.selected) cn = col_sel;
599
600 if(this.header) {
601 if(this.is_disabled) {
602 this.body.className = this.default_class + ' cal_vu_disabled';
603 this.header.style.color = '#BBB';
604 } else {
605 this.body.className = this.default_class;
606 this.header.style.color = '#000';
607 }
608
609 if(this.day&&this.day.getDay()==0)
610 this.header.style.backgroundColor = '#FEE';
611 else
612 this.header.style.backgroundColor = '';
613 }
614 this.parent.style.backgroundColor = cn;
615}
616
617Calendar.ViewUnit.prototype.is_selected = function() {
618 return (same_day(this.day, erpnext.calendar.selected_date)
619 && this.hour==erpnext.calendar.selected_hour)
620}
621
622Calendar.ViewUnit.prototype.get_event_list = function() {
623 var y = this.day.getFullYear();
624 var m = this.day.getMonth();
625 var d = this.day.getDate();
626 if(erpnext.calendar.events[y] && erpnext.calendar.events[y][m] &&
627 erpnext.calendar.events[y][m][d] &&
628 erpnext.calendar.events[y][m][d][this.hour]) {
629 return erpnext.calendar.events[y][m][d][this.hour];
630 } else
631 return [];
632}
633
634Calendar.ViewUnit.prototype.refresh = function() {
635 this.clear();
636
637 if(this.is_selected()) {
638 if(erpnext.calendar.cur_vu)erpnext.calendar.cur_vu.deselect();
639 this.selected = true;
640 erpnext.calendar.cur_vu = this;
641 }
642 this.set_display();
643 this.el = this.get_event_list();
644 if(this.onrefresh)this.onrefresh();
645
646 for(var i in this.el) {
647 this.el[i].show(this);
648 }
649
650 var me = this;
651}
652
653Calendar.ViewUnit.prototype.select=function() { this.selected = true; this.set_display(); }
654Calendar.ViewUnit.prototype.deselect=function() { this.selected = false; this.set_display(); }
655Calendar.ViewUnit.prototype.setevent=function() { }
656
657Calendar.MonthViewUnit=function(parent) {
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530658 var me = this;
659 this.header = $("<div class='cal_month_date'></div>")
660 .appendTo(parent)
661 .css({"cursor":"pointer"})
662 .click(function() {
663 me.body.onclick();
664 })
665 .bind("dblclick", function() {
666 me.body.ondblclick();
667 })
668 .get(0);
669
670 this.default_class = "cal_month_unit";
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530671 this.init(parent);
672
673 this.onrefresh = function() {
674 this.header.innerHTML = this.day.getDate();
Rushabh Mehta2e593fa2012-11-23 16:24:56 +0530675 }
Rushabh Mehtab73fa492012-02-24 15:07:39 +0530676}
677Calendar.MonthViewUnit.prototype = new Calendar.ViewUnit();
678Calendar.MonthViewUnit.prototype.is_selected = function() {
679 return same_day(this.day, erpnext.calendar.selected_date)
680}
681
682Calendar.MonthViewUnit.prototype.get_event_list = function() {
683 return erpnext.calendar.get_daily_event_list(this.day);
684}
685
686Calendar.DayViewUnit= function(parent) {
687 this.default_class = "cal_day_unit"; this.init(parent);
688}
689Calendar.DayViewUnit.prototype = new Calendar.ViewUnit();
690Calendar.DayViewUnit.prototype.onrefresh = function() {
691 if(this.el.length<3)
692 this.body.style.height = '30px';
693 else this.body.style.height = '';
694}
695
696Calendar.WeekViewUnit=function(parent) {
697 this.default_class = "cal_week_unit"; this.init(parent);
698}
699Calendar.WeekViewUnit.prototype = new Calendar.ViewUnit();
700Calendar.WeekViewUnit.prototype.onrefresh = function() {
701 if(this.el.length<3) this.body.style.height = '30px';
702 else this.body.style.height = '';
703}