'
- + erpnext.calendar.weekdays[c.getDay()] + ', ' + c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear()
- + ' - '+this.ev.event_hour+'
';
-
- // set
- this.widgets['Description'].value = cstr(this.ev.description);
-
- this.widgets['Public Event'].checked = false;
- this.widgets['Cancelled Event'].checked = false;
-
- if(this.ev.event_type=='Public')
- this.widgets['Public Event'].checked = true;
-
- this.widgets['Event Link'].innerHTML = '';
- this.widgets['Ref Link'].innerHTML = '';
-
- if(this.ev.ref_type) {
- $(repl('').appendTo($(wrapper).find('.layout-main')).fullCalendar({
+ header: {
+ left: 'prev,next today',
+ center: 'title',
+ right: 'month,agendaWeek,agendaDay'
+ },
+ editable: true,
+ selectable: true,
+ selectHelper: true,
+ events: function(start, end, callback) {
+ wn.call({
+ method: 'utilities.page.calendar.calendar.get_events',
+ type: "GET",
+ args: {
+ start: dateutil.obj_to_str(start),
+ end: dateutil.obj_to_str(end),
+ company: wn.user.get_default("company")[0],
+ employee: wn.user.get_default("employee")[0]
+ },
+ callback: function(r) {
+ var events = r.message;
+ $.each(events, function(i, d) {
+ d.editable = d.owner==user;
+ var options = erpnext.calendar.event_options[d.doctype];
+ if(options && options.prepare)
+ options.prepare(d);
+ });
+ callback(events);
}
- }
- // new date
- day++;
- d = new Date(cur_year, cur_month, day);
- }
- }
- cur_row++;
- if(cur_row == 5) {cur_row = 0;} // back to top
- }
- this.refresh_units();
-
-}
- // ................. Daily View..........................
-Calendar.DayView=function(cal){ this.init(cal); this.daystep = 1; }
-Calendar.DayView.prototype=new Calendar.View();
-Calendar.DayView.prototype.create_table = function() {
-
- // create body
- this.main = $a(this.body, 'div', 'cal_day_body');
- this.table = $a(this.main, 'table', 'cal_day_table');
- var me = this;
-
- for(var i=0;i<24;i++) {
- var r = this.table.insertRow(i);
- for(var j=0;j<2;j++) {
- var cell = r.insertCell(j);
- if(j==0) {
- cell.innerHTML = i+':00:00';
- $w(cell, '10%');
- } else {
- cell.viewunit = new Calendar.DayViewUnit(cell);
- cell.viewunit.hour = i;
- $w(cell, '90%');
- if((i>=7)&&(i<=20)) {
- cell.viewunit.is_daytime = true;
- }
+ })
+ },
+ eventClick: function(event, jsEvent, view) {
+ // edit event description or delete
+ var options = erpnext.calendar.event_options[event.doctype];
+ if(options && options.click)
+ options.click(event);
+ },
+ eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
+ erpnext.calendar.update_event(event);
+ },
+ eventResize: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
+ erpnext.calendar.update_event(event);
+ },
+ select: function(startDate, endDate, allDay, jsEvent, view) {
+ if(jsEvent.day_clicked && view.name=="month")
+ return;
+ var event = wn.model.get_new_doc("Event");
+ event.starts_on = wn.datetime.get_datetime_as_string(startDate);
+ event.ends_on = wn.datetime.get_datetime_as_string(endDate);
+ event.all_day = allDay ? 1 : 0;
+ wn.set_route("Form", "Event", event.name);
+ },
+ dayClick: function(date, allDay, jsEvent, view) {
+ jsEvent.day_clicked = true;
+ $("#fullcalendar").fullCalendar("gotoDate", date)
+ return false;
}
- }
- }
- }
+ });
+ });
-Calendar.DayView.prototype.refresh = function() {
- var c =this.cal.selected_date;
-
- // fill other days
- var me=this;
-
- this.cal.view_title.innerHTML = erpnext.calendar.weekdays[c.getDay()] + ', '
- + c.getDate() + ' ' + month_list_full[c.getMonth()] + ' ' + c.getFullYear();
-
- // headers
- var d = c;
-
- for(var i=0;i<24;i++) {
- var cell = this.table.rows[i].cells[1];
- if(same_day(this.cal.todays_date, d)) cell.viewunit.is_today = true;
- else cell.viewunit.is_today = false;
- cell.viewunit.day = d;
- }
- this.refresh_units();
+ wrapper.setup_complete = true;
+
}
-// ................. Weekly View..........................
-Calendar.WeekView=function(cal) { this.init(cal); this.daystep = 7; }
-Calendar.WeekView.prototype=new Calendar.View();
-Calendar.WeekView.prototype.create_table = function() {
-
- // create head
- this.head_wrapper = $a(this.body, 'div', 'cal_month_head');
-
- // day headers
- this.headtable = $a(this.head_wrapper, 'table', 'cal_month_headtable');
- var r = this.headtable.insertRow(0);
- for(var j=0;j<8;j++) {
- var cell = r.insertCell(j);
- }
-
- // hour header
-
- // create body
- this.main = $a(this.body, 'div', 'cal_week_body');
- this.table = $a(this.main, 'table', 'cal_week_table');
- var me = this;
-
- for(var i=0;i<24;i++) {
- var r = this.table.insertRow(i);
- for(var j=0;j<8;j++) {
- var cell = r.insertCell(j);
- if(j==0) {
- cell.innerHTML = i+':00:00';
- $w(cell, '10%');
- } else {
- cell.viewunit = new Calendar.WeekViewUnit(cell);
- cell.viewunit.hour = i;
- if((i>=7)&&(i<=20)) {
- cell.viewunit.is_daytime = true;
- }
+erpnext.calendar.update_event = function(event) {
+ wn.model.remove_from_locals("Event", event.id);
+ wn.call({
+ module: "utilities",
+ page: "calendar",
+ method: "update_event",
+ args: {
+ "start": wn.datetime.get_datetime_as_string(event.start),
+ "end": wn.datetime.get_datetime_as_string(event.end),
+ "all_day": event.allDay,
+ "name": event.id
+ },
+ callback: function(r) {
+ if(r.exc) {
+ show_alert("Unable to update event.")
}
- }
- }
-}
-
-Calendar.WeekView.prototype.refresh = function() {
- var c =this.cal.selected_date;
- // fill other days
- var me=this;
-
- this.cal.view_title.innerHTML = month_list_full[c.getMonth()] + ' ' + c.getFullYear();
-
- // headers
- var d = new Date(c.getFullYear(), c.getMonth(), c.getDate() - c.getDay());
-
- for (var k=1;k<8;k++) {
- this.headtable.rows[0].cells[k].innerHTML = erpnext.calendar.weekdays[d.getDay()] + ' ' + d.getDate();
-
- for(var i=0;i<24;i++) {
- var cell = this.table.rows[i].cells[k];
- if(same_day(this.cal.todays_date, d))
- cell.viewunit.is_today = true;
- else cell.viewunit.is_today = false;
-
- cell.viewunit.day = d;
- //cell.viewunit.refresh();
}
- d=new Date(d.getFullYear(),d.getMonth(),d.getDate() + 1);
-
- }
-
- this.refresh_units();
+ });
}
-//------------------------------------------------------.
-
-Calendar.ViewUnit = function() {}
-Calendar.ViewUnit.prototype.init = function(parent) {
- parent.style.border = "1px solid #CCC" ;
- this.body = $a(parent, 'div', this.default_class);
- this.parent = parent;
-
- var me = this;
- this.body.onclick = function() {
- erpnext.calendar.selected_date = me.day;
- erpnext.calendar.selected_hour = me.hour;
-
- if(erpnext.calendar.cur_vu && erpnext.calendar.cur_vu!=me){
- erpnext.calendar.cur_vu.deselect();
- me.select();
- erpnext.calendar.cur_vu = me;
+erpnext.calendar.event_options = {
+ "Leave Block List Date": {
+ prepare: function(d) {
+ d.color = "#aaa";
+ }
+ },
+ "Event": {
+ prepare: function(d) {
+ if(d.event_type=="Public") {
+ d.color = "#57AF5B";
+ }
+ },
+ click: function(event) {
+ wn.set_route("Form", "Event", event.id);
+ }
+ },
+ "Leave Application": {
+ prepare: function(d) {
+ d.color = "#4F9F96";
+ },
+ click: function(event) {
+ if(event.employee==wn.user.get_default("employee")[0]) {
+ wn.set_route("Form", "Leave Application", event.id);
+ }
}
}
- this.body.ondblclick = function() {
- erpnext.calendar.add_event();
- }
}
-Calendar.ViewUnit.prototype.set_header=function(v) {
- this.header.innerHTML = v;
-}
-
-Calendar.ViewUnit.prototype.set_today = function() {
- this.is_today = true;
- this.set_display();
-}
-
-Calendar.ViewUnit.prototype.clear = function() {
- if(this.header)this.header.innerHTML = '';
-
- // clear body
- while(this.body.childNodes.length)
- this.body.removeChild(this.body.childNodes[0]);
-}
-
-Calendar.ViewUnit.prototype.set_display = function() {
- var cn = '#FFF';
-
- // colors
- var col_tod_sel = '#EEE';
- var col_tod = '#FFF';
- var col_sel = '#EEF';
-
- if(this.is_today) {
- if(this.selected) cn = col_tod_sel;
- else cn = col_tod;
- } else
- if(this.selected) cn = col_sel;
-
- if(this.header) {
- if(this.is_disabled) {
- this.body.className = this.default_class + ' cal_vu_disabled';
- this.header.style.color = '#BBB';
- } else {
- this.body.className = this.default_class;
- this.header.style.color = '#000';
- }
-
- if(this.day&&this.day.getDay()==0)
- this.header.style.backgroundColor = '#FEE';
- else
- this.header.style.backgroundColor = '';
- }
- this.parent.style.backgroundColor = cn;
-}
-
-Calendar.ViewUnit.prototype.is_selected = function() {
- return (same_day(this.day, erpnext.calendar.selected_date)
- && this.hour==erpnext.calendar.selected_hour)
-}
-
-Calendar.ViewUnit.prototype.get_event_list = function() {
- var y = this.day.getFullYear();
- var m = this.day.getMonth();
- var d = this.day.getDate();
- if(erpnext.calendar.events[y] && erpnext.calendar.events[y][m] &&
- erpnext.calendar.events[y][m][d] &&
- erpnext.calendar.events[y][m][d][this.hour]) {
- return erpnext.calendar.events[y][m][d][this.hour];
- } else
- return [];
-}
-
-Calendar.ViewUnit.prototype.refresh = function() {
- this.clear();
-
- if(this.is_selected()) {
- if(erpnext.calendar.cur_vu)erpnext.calendar.cur_vu.deselect();
- this.selected = true;
- erpnext.calendar.cur_vu = this;
- }
- this.set_display();
- this.el = this.get_event_list();
- if(this.onrefresh)this.onrefresh();
-
- for(var i in this.el) {
- this.el[i].show(this);
- }
-
- var me = this;
-}
-
-Calendar.ViewUnit.prototype.select=function() { this.selected = true; this.set_display(); }
-Calendar.ViewUnit.prototype.deselect=function() { this.selected = false; this.set_display(); }
-Calendar.ViewUnit.prototype.setevent=function() { }
-
-Calendar.MonthViewUnit=function(parent) {
- var me = this;
- this.header = $("
")
- .appendTo(parent)
- .css({"cursor":"pointer"})
- .click(function() {
- me.body.onclick();
- })
- .bind("dblclick", function() {
- me.body.ondblclick();
- })
- .get(0);
-
- this.default_class = "cal_month_unit";
- this.init(parent);
-
- this.onrefresh = function() {
- this.header.innerHTML = this.day.getDate();
- }
-}
-Calendar.MonthViewUnit.prototype = new Calendar.ViewUnit();
-Calendar.MonthViewUnit.prototype.is_selected = function() {
- return same_day(this.day, erpnext.calendar.selected_date)
-}
-
-Calendar.MonthViewUnit.prototype.get_event_list = function() {
- return erpnext.calendar.get_daily_event_list(this.day);
-}
-
-Calendar.DayViewUnit= function(parent) {
- this.default_class = "cal_day_unit"; this.init(parent);
-}
-Calendar.DayViewUnit.prototype = new Calendar.ViewUnit();
-Calendar.DayViewUnit.prototype.onrefresh = function() {
- if(this.el.length<3)
- this.body.style.height = '30px';
- else this.body.style.height = '';
-}
-
-Calendar.WeekViewUnit=function(parent) {
- this.default_class = "cal_week_unit"; this.init(parent);
-}
-Calendar.WeekViewUnit.prototype = new Calendar.ViewUnit();
-Calendar.WeekViewUnit.prototype.onrefresh = function() {
- if(this.el.length<3) this.body.style.height = '30px';
- else this.body.style.height = '';
-}
diff --git a/utilities/page/calendar/calendar.py b/utilities/page/calendar/calendar.py
index baffc48825..06d4385569 100644
--- a/utilities/page/calendar/calendar.py
+++ b/utilities/page/calendar/calendar.py
@@ -1 +1,85 @@
from __future__ import unicode_literals
+
+import webnotes
+from webnotes import _
+
+@webnotes.whitelist()
+def get_events(start, end, employee=None, company=None):
+ roles = webnotes.get_roles()
+ events = webnotes.conn.sql("""select name as `id`, subject as title,
+ starts_on as `start`, ends_on as `end`, "Event" as doctype, owner,
+ all_day as allDay, event_type
+ from tabEvent where (
+ (starts_on between %s and %s)
+ or (ends_on between %s and %s)
+ )
+ and (event_type='Public' or owner=%s
+ or exists(select * from `tabEvent User` where
+ `tabEvent User`.parent=tabEvent.name and person=%s)
+ or exists(select * from `tabEvent Role` where
+ `tabEvent Role`.parent=tabEvent.name
+ and `tabEvent Role`.role in ('%s')))""" % ('%s', '%s', '%s', '%s', '%s', '%s',
+ "', '".join(roles)), (start, end, start, end,
+ webnotes.session.user, webnotes.session.user), as_dict=1)
+
+
+ if employee:
+ add_block_dates(events, start, end, employee, company)
+ add_department_leaves(events, start, end, employee, company)
+
+ return events
+
+def add_department_leaves(events, start, end, employee, company):
+ department = webnotes.conn.get_value("Employee", employee, "department")
+
+ if not department:
+ return
+
+ # department leaves
+ department_employees = webnotes.conn.sql_list("select name from tabEmployee where department=%s",
+ department)
+
+ for d in webnotes.conn.sql("""select name, from_date, to_date, employee_name, half_day,
+ status, employee
+ from `tabLeave Application` where
+ (from_date between %s and %s or to_date between %s and %s)
+ and docstatus < 2
+ and status!="Rejected"
+ and employee in ('%s')""" % ("%s", "%s", "%s", "%s", "', '".join(department_employees)),
+ (start, end, start, end), as_dict=True):
+ events.append({
+ "id": d.name,
+ "employee": d.employee,
+ "doctype": "Leave Application",
+ "start": d.from_date,
+ "end": d.to_date,
+ "allDay": True,
+ "status": d.status,
+ "title": _("Leave by") + " " + d.employee_name + \
+ (d.half_day and _(" (Half Day)") or "")
+ })
+
+
+def add_block_dates(events, start, end, employee, company):
+ # block days
+ from hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates
+
+ cnt = 0
+ block_dates = get_applicable_block_dates(start, end, employee, company, all_lists=True)
+
+ for block_date in block_dates:
+ events.append({
+ "doctype": "Leave Block List Date",
+ "start": block_date.block_date,
+ "title": _("Leave Blocked") + ": " + block_date.reason,
+ "id": "_" + str(cnt),
+ "allDay": True
+ })
+ cnt+=1
+
+
+@webnotes.whitelist()
+def update_event(name, start, end):
+ webnotes.conn.sql("""update tabEvent set starts_on=%s, ends_on=%s where
+ name=%s""", (start, end, name))
+
\ No newline at end of file