[calendar] Added canCreateEvent (by Event) logic
authorDavid Baz Fayos <david.baz@openbravo.com>
Wed, 23 Jan 2013 11:23:30 +0100
changeset 19515 9099bfe9ed8f
parent 19514 bab1d0b4d187
child 19516 76fd8a0d8eee
[calendar] Added canCreateEvent (by Event) logic
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-multicalendar.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-multicalendar.js	Tue Jan 22 11:31:19 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-multicalendar.js	Wed Jan 23 11:23:30 2013 +0100
@@ -241,7 +241,7 @@
   showCustomEventsBgColor: true,
 
   parseCalendarData: function (calendarData) {
-    var i;
+    var canCreateEvents, i;
     if (calendarData.filters) {
       calendarData.hasFilter = true;
     } else {
@@ -255,6 +255,16 @@
         calendarData.calendars[i].color = OB.Utilities.generateOBColor(
         null, null, null, 100, calendarData.calendars[i].id);
       }
+      if (i === 0 && typeof calendarData.calendars[i].canCreateEvents !== 'undefined') {
+        canCreateEvents = false;
+      }
+      if (typeof calendarData.calendars[i].canCreateEvents !== 'undefined' && canCreateEvents === false && calendarData.calendars[i].canCreateEvents === true) {
+        canCreateEvents = true;
+      }
+      if (canCreateEvents === false && i === calendarData.calendars.length - 1) {
+        this.canCreateEvents = false;
+        this.calendarProps.canCreateEvents = false;
+      }
     }
     return calendarData;
   },
@@ -305,8 +315,6 @@
     }
     if (typeof this.calendarProps.canCreateEvents !== 'undefined') {
       this.canCreateEvents = this.calendarProps.canCreateEvents;
-    } else {
-      this.showCustomEventsBgColor = true;
     }
     this.addMembers([OB.Utilities.createLoadingLayout()]);
     callback = function (rpcResponse, data, rpcRequest) {
@@ -323,6 +331,10 @@
     this.Super('initWidget', arguments);
   },
   drawComponents: function () {
+    if (this.canCreateEvents) {
+      this.showCustomEventsBgColor = true;
+    }
+
     this.leftControls = isc.OBMultiCalendarLeftControls.create({
       multiCalendar: this
     });