details:   https://code.openbravo.com/erp/devel/pi/rev/2fbfd19afbbf
changeset: 19810:2fbfd19afbbf
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Feb 27 14:09:36 2013 +0100
summary:   fixed issue 23182: Extend calendar to execute callback after data 
change

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-calendar.js
 |  78 +++++++--
 1 files changed, 55 insertions(+), 23 deletions(-)

diffs (208 lines):

diff -r 6549f19a33f2 -r 2fbfd19afbbf 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-calendar.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-calendar.js
  Wed Feb 27 13:46:25 2013 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-calendar.js
  Wed Feb 27 14:09:36 2013 +0100
@@ -17,7 +17,6 @@
  ************************************************************************
  */
 
-
 // == OBCalendar_EventDialogBridge ==
 // Hack to allow the OBCalendar open its own full customizable EventDialog 
(OBEventEditor)
 isc.ClassFactory.defineClass('OBCalendar_EventDialogBridge', isc.Window);
@@ -53,7 +52,6 @@
 // Extends Calendar, with some customizations (most of them styling related)
 isc.ClassFactory.defineClass('OBCalendar', isc.Calendar);
 
-
 isc.OBCalendar.addProperties({
   autoFetchData: true,
   initWidget: function () {
@@ -106,9 +104,12 @@
         type: "datetime"
       }],
 
-      // these are read extra from the server with the events
+      // these are read extra from the server with the
+      // events
       additionalProperties: this.dataSourceProps.additionalProperties,
 
+      dataSourceProps: this.dataSourceProps,
+
       transformRequest: function (dsRequest) {
         dsRequest.params = dsRequest.params || {};
         dsRequest.params._extraProperties = this.additionalProperties;
@@ -140,7 +141,9 @@
           if (records) {
             for (i = 0; i < records.getLength(); i++) {
               if (typeof records[i][calendar.nameField] === 'undefined') {
-                //To avoid the event displays 'undefined' when no name has 
been set
+                // To avoid the event displays
+                // 'undefined' when no name has
+                // been set
                 records[i][calendar.nameField] = '';
               }
               if (typeof records[i][calendar.descriptionField] === 
'undefined') {
@@ -150,12 +153,14 @@
                 records[i].eventWindowStyle = 
multiCalendar.eventStyles[records[i][calendar.legendIdField]] + ' ' + 
OB.Styles.OBCalendar.eventWindowStyle;
               }
               if (typeof calendar.customTransformResponse === 'function') {
-                records[i] = calendar.customTransformResponse(records[i], 
calendar);
+                records[i] = calendar.customTransformResponse(
+                records[i], calendar);
               }
               if (multiCalendar && 
multiCalendar.calendarData.hasCustomFilters) {
                 for (j = 0; j < 
multiCalendar.calendarData.customFilters.length; j++) {
                   if (typeof 
multiCalendar.calendarData.customFilters[j].handler.transformResponse === 
'function') {
-                    records[i] = 
multiCalendar.calendarData.customFilters[j].handler.transformResponse(records[i],
 calendar, multiCalendar.calendarData.customFilters[j]);
+                    records[i] = 
multiCalendar.calendarData.customFilters[j].handler.transformResponse(
+                    records[i], calendar, 
multiCalendar.calendarData.customFilters[j]);
                   }
                 }
               }
@@ -165,43 +170,62 @@
         return this.Super('transformResponse', arguments);
       },
 
-      // override the addData, updateData and removeData to wrap
-      // the calendar callback to prevent adding events in cased
+      // override the addData, updateData and removeData
+      // to wrap
+      // the calendar callback to prevent adding events in
+      // cased
       // of errors
       addData: function (newRecord, callback, requestProperties) {
-        var newCallBack = function (dsResponse, data, dsRequest) {
+        var dataSourceProps = this.dataSourceProps,
+            newCallBack = function (dsResponse, data, dsRequest) {
             // don't call if there is an error
             if (dsResponse.status < 0) {
               return;
             }
             callback(dsResponse, data, dsRequest);
+            if (dataSourceProps.addEventCallback) {
+              dataSourceProps.addEventCallback(newRecord, requestProperties);
+            }
             };
         return this.Super('addData', [newRecord, newCallBack, 
requestProperties]);
       },
       updateData: function (updatedRecord, callback, requestProperties) {
-        var newCallBack = function (dsResponse, data, dsRequest) {
+        var dataSourceProps = this.dataSourceProps,
+            newCallBack = function (dsResponse, data, dsRequest) {
             // don't call if there is an error
             if (dsResponse.status < 0) {
               return;
             }
             callback(dsResponse, data, dsRequest);
+            if (dataSourceProps.updateEventCallback) {
+              dataSourceProps.updateEventCallback(updatedRecord, 
requestProperties);
+            }
             };
-        return this.Super('updateData', [updatedRecord, newCallBack, 
requestProperties]);
+        return this.Super('updateData', [
+        updatedRecord, newCallBack, requestProperties]);
       },
       removeData: function (recordKeys, callback, requestProperties) {
-        var newCallBack = function (dsResponse, data, dsRequest) {
+        var dataSourceProps = this.dataSourceProps,
+            newCallBack = function (dsResponse, data, dsRequest) {
             // don't call if there is an error
             if (dsResponse.status < 0) {
               return;
             }
             callback(dsResponse, data, dsRequest);
+            if (dataSourceProps.removeEventCallback) {
+              dataSourceProps.removeEventCallback(recordKeys, 
requestProperties);
+            }
             };
         return this.Super('removeData', [recordKeys, newCallBack, 
requestProperties]);
       }
     });
     this.Super('initWidget', arguments);
-    this.controlsBar.reorderMember(4, 1); // Moves the 'next' button to the 
second position
-    this.controlsBar.reorderMember(2, 4); // Moves the 'displayed date' to 
last position
+    this.controlsBar.reorderMember(4, 1); // Moves the 'next'
+    // button to the second
+    // position
+    this.controlsBar.reorderMember(2, 4); // Moves the 'displayed
+    // date' to last
+    // position
     if (this.defaultViewName && ((this.showDayView !== false && 
this.showWeekView !== false) || (this.showDayView !== false && 
this.showMonthView !== false) || (this.showWeekView !== false && 
this.showMonthView !== false))) {
       this.setCurrentViewName(this.defaultViewName);
     }
@@ -241,9 +265,11 @@
           calendar.eventDialog.currentEnd = event[calendar.endDateField];
           calendar.eventDialog.calendar = calendar;
           try {
-            //To avoid js error due to conflicts with Smartclient default 
EventDialog
+            // To avoid js error due to conflicts with
+            // Smartclient default EventDialog
             if (event.canEdit === false && event.canDelete === false) {
-              isc.warn(OB.I18N.getLabel('OBUIAPP_CalendarCanNotUpdateEvent'), 
function () {
+              isc.warn(
+              OB.I18N.getLabel('OBUIAPP_CalendarCanNotUpdateEvent'), function 
() {
                 return true;
               }, {
                 icon: '[SKINIMG]Dialog/error.png',
@@ -272,7 +298,8 @@
       this.eventDialog.currentEnd = newDate;
       this.eventDialog.calendar = this;
       try {
-        //To avoid js error due to conflicts with Smartclient default 
EventDialog
+        // To avoid js error due to conflicts with Smartclient
+        // default EventDialog
         this.eventDialog.show();
       } catch (e) {}
     } else {
@@ -282,16 +309,18 @@
   eventMoved: function (newDate, event) {
     newDate.setSeconds(0);
     if (this.showEventDialogOnEventMove) {
-      //Event duration
+      // Event duration
       var dateDiff = event[this.endDateField] - event[this.startDateField],
-          newEndDate = newDate.getTime() + dateDiff; //Add the event duration 
to the new startDate
+          newEndDate = newDate.getTime() + dateDiff; // Add the event duration 
to the new
+      // startDate
       newEndDate = new Date(newEndDate);
       this.eventDialog.event = event;
       this.eventDialog.currentStart = newDate;
       this.eventDialog.currentEnd = newEndDate;
       this.eventDialog.calendar = this;
       try {
-        //To avoid js error due to conflicts with Smartclient default 
EventDialog
+        // To avoid js error due to conflicts with Smartclient
+        // default EventDialog
         this.eventDialog.show();
       } catch (e) {}
     } else {
@@ -305,7 +334,8 @@
       this.eventDialog.currentEnd = event[this.endDateField];
       this.eventDialog.calendar = this;
       try {
-        //To avoid js error due to conflicts with Smartclient default 
EventDialog
+        // To avoid js error due to conflicts with Smartclient
+        // default EventDialog
         this.eventDialog.show();
       } catch (e) {}
       return false;
@@ -389,7 +419,8 @@
     if (this.multiCalendar && 
this.multiCalendar.calendarData.hasCustomFilters) {
       for (i = 0; i < this.multiCalendar.calendarData.customFilters.length; 
i++) {
         if (typeof 
this.multiCalendar.calendarData.customFilters[i].handler.filterCriteria === 
'function') {
-          
criteria.criteria.push(this.multiCalendar.calendarData.customFilters[i].handler.filterCriteria(this,
 this.multiCalendar.calendarData.customFilters[i]));
+          
criteria.criteria.push(this.multiCalendar.calendarData.customFilters[i].handler.filterCriteria(
+          this, this.multiCalendar.calendarData.customFilters[i]));
         }
       }
     }
@@ -409,7 +440,8 @@
         calendar = this;
     ret = this.Super('draw', arguments);
 
-    // If change filter/legend parameters in day/week view and you switch to 
the other one,
+    // If change filter/legend parameters in day/week view and you
+    // switch to the other one,
     // data needs to be refreshed in order to show changes
     if (this.multiCalendar && this.mainView && typeof this.mainView.selectTab 
=== 'function') {
       this.mainView.tabSelected = function () {

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to