Merged from Widget Iframe
authorUnai Martirena <unai.martirena@openbravo.com>
Fri, 13 May 2016 09:33:08 +0200
changeset 29640 02e361a6af80
parent 29639 5776bfd165d5 (current diff)
parent 28949 10b8bedd8b8e (diff)
child 29641 f345a264432d
Merged from Widget Iframe
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-view-manager.js
src/index.jsp
src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Fri May 13 09:33:08 2016 +0200
@@ -2086,6 +2086,18 @@
 <!--FAF1675F98A248C39469E132D1B0E2DE-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--FAF1675F98A248C39469E132D1B0E2DE--></AD_MESSAGE>
 
+<!--FB42B1902BBC4F2A8ECAAC0584773F08--><AD_MESSAGE>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <AD_MESSAGE_ID><![CDATA[FB42B1902BBC4F2A8ECAAC0584773F08]]></AD_MESSAGE_ID>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <VALUE><![CDATA[OBUIAPP_Timeout]]></VALUE>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <MSGTEXT><![CDATA[Timeout]]></MSGTEXT>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--FB42B1902BBC4F2A8ECAAC0584773F08--></AD_MESSAGE>
+
 <!--FBA2F11416C4413F8E2D554119461964--><AD_MESSAGE>
 <!--FBA2F11416C4413F8E2D554119461964-->  <AD_MESSAGE_ID><![CDATA[FBA2F11416C4413F8E2D554119461964]]></AD_MESSAGE_ID>
 <!--FBA2F11416C4413F8E2D554119461964-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-calendar.js	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-calendar.js	Fri May 13 09:33:08 2016 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2013-2015 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -187,6 +187,12 @@
               calendar.OBEventEditor.closeClick();
             }
           }
+          if (typeof calendar.customFinishLoad === 'function') {
+            window.setTimeout(function () {
+              calendar.customFinishLoad();
+            }, 500);
+          }
+
           return this.Super('transformResponse', arguments);
         },
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-multicalendar.js	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/calendar/ob-multicalendar.js	Fri May 13 09:33:08 2016 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2013 Openbravo SLU
+ * All portions are Copyright (C) 2013-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -385,6 +385,7 @@
   defaultLayoutAlign: 'center',
   filter: null,
   dateChooser: null,
+  button: null,
   legend: null,
   getFilterValueMap: function () {
     var filterObj = {},
@@ -467,7 +468,7 @@
         height: 8
       });
     }
-    button = isc.OBFormButton.create({
+    this.button = isc.OBFormButton.create({
       width: 180,
       title: this.multiCalendar.addEventButtonName,
       click: function () {
@@ -516,7 +517,7 @@
     this.legend.updateMembers(leftControls.getLegendValueMap());
     this.addMembers([this.filter]);
     if (this.multiCalendar.canCreateEvents) {
-      this.addMembers([button]);
+      this.addMembers([this.button]);
     }
     this.addMembers([this.dateChooser, this.customFiltersContainer, label, this.legend]);
   }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js	Fri May 13 09:33:08 2016 +0200
@@ -543,8 +543,8 @@
 
   for (i = 0; i < length; i++) {
     hash = hashes[i].split('=');
-    if (hash[i] && hash[i].contains('#')) {
-      hash[i] = hash[i].substring(0, hash[i].indexOf('#'));
+    if (hash[1] && hash[1].contains('#')) {
+      hash[1] = hash[1].substring(0, hash[1].indexOf('#'));
     }
     vars[hash[0]] = hash[1];
   }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-view-manager.js	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-view-manager.js	Fri May 13 09:33:08 2016 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2013 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -478,14 +478,15 @@
     //
     restoreState: function (newState, data) {
 
-      var viewId, tabSet = OB.MainView.TabSet,
-          tabsLength, i, tabObject, hasChanged = false,
+      var viewId, tabSet, tabsLength, i, tabObject, hasChanged = false,
           stateData, requestViewsRestoreState;
 
-      if (vmgr.inStateHandling) {
+      if (vmgr.inStateHandling || !OB.MainView) {
         return;
       }
 
+      tabSet = OB.MainView.TabSet;
+
       vmgr.inStateHandling = true;
 
       // create an empty layout
@@ -608,8 +609,10 @@
     },
 
     createAddStartTab: function () {
-      var error, historyId = isc.History.getCurrentHistoryId();
-      if (historyId) {
+      var error, historyId = isc.History.getCurrentHistoryId(),
+          urlParams = OB.Utilities.getUrlParameters();
+
+      if (historyId && !urlParams.urlMode) {
         try {
           OB.Layout.HistoryManager.restoreHistory(historyId, isc.History.getHistoryData(historyId));
           return;
@@ -618,30 +621,32 @@
         }
       }
 
-      // todo: this call in a way assumes that there is a myob module installed
-      // it is nicer to somehow set the page to load in a different way
-      // this can be done if an smartclient problem has been solved
-      // see this forum post:
-      // http://forums.smartclient.com/showthread.php?p=53077
-      var viewId = 'OBMyOpenbravoImplementation';
-      var viewParams = {
-        tabTitle: OB.I18N.getLabel('OBUIAPP_MyOpenbravo'),
-        myOB: true,
-        canClose: false
-      };
-      // check if there is already a start page, only open it if not
-      var viewTabId = this.views.getViewTabID(viewId, viewParams);
-      if (!viewTabId) {
-        this.openView(viewId, viewParams, null);
+      if (OB && OB.MainView && OB.MainView.TabSet) {
+        // todo: this call in a way assumes that there is a myob module installed
+        // it is nicer to somehow set the page to load in a different way
+        // this can be done if an smartclient problem has been solved
+        // see this forum post:
+        // http://forums.smartclient.com/showthread.php?p=53077
+        var viewId = 'OBMyOpenbravoImplementation';
+        var viewParams = {
+          tabTitle: OB.I18N.getLabel('OBUIAPP_MyOpenbravo'),
+          myOB: true,
+          canClose: false
+        };
+        // check if there is already a start page, only open it if not
+        var viewTabId = this.views.getViewTabID(viewId, viewParams);
+        if (!viewTabId) {
+          this.openView(viewId, viewParams, null);
+        }
       }
 
       // check if a tabId was passed as a url param
       // only do this if there is no other history
-      if (!historyId) {
-        var urlParams = OB.Utilities.getUrlParameters();
-        if (urlParams.tabId) {
-          OB.Utilities.openDirectTab(urlParams.tabId, urlParams.recordId, urlParams.command);
-        }
+      if (!historyId && urlParams.tabId) {
+        OB.Utilities.openDirectTab(urlParams.tabId, urlParams.recordId, urlParams.command);
+      }
+      if (urlParams.urlMode && OB.UrlModes[urlParams.urlMode]) {
+        OB.UrlModes[urlParams.urlMode].action(urlParams);
       }
     }
   };
--- a/modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_MESSAGE.xml	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_MESSAGE.xml	Fri May 13 09:33:08 2016 +0200
@@ -24,6 +24,18 @@
 <!--03D018ABB0414D18A1B60782C0DD1389-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--03D018ABB0414D18A1B60782C0DD1389--></AD_MESSAGE>
 
+<!--046915CEE05D4573AF787D442628C453--><AD_MESSAGE>
+<!--046915CEE05D4573AF787D442628C453-->  <AD_MESSAGE_ID><![CDATA[046915CEE05D4573AF787D442628C453]]></AD_MESSAGE_ID>
+<!--046915CEE05D4573AF787D442628C453-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--046915CEE05D4573AF787D442628C453-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--046915CEE05D4573AF787D442628C453-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--046915CEE05D4573AF787D442628C453-->  <VALUE><![CDATA[OBKMO_ContactSystemAdmin]]></VALUE>
+<!--046915CEE05D4573AF787D442628C453-->  <MSGTEXT><![CDATA[Please contact your System Administrator.]]></MSGTEXT>
+<!--046915CEE05D4573AF787D442628C453-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--046915CEE05D4573AF787D442628C453-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
+<!--046915CEE05D4573AF787D442628C453-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--046915CEE05D4573AF787D442628C453--></AD_MESSAGE>
+
 <!--06E9344CB05A46F0BFEF458B0407002C--><AD_MESSAGE>
 <!--06E9344CB05A46F0BFEF458B0407002C-->  <AD_MESSAGE_ID><![CDATA[06E9344CB05A46F0BFEF458B0407002C]]></AD_MESSAGE_ID>
 <!--06E9344CB05A46F0BFEF458B0407002C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -420,6 +432,30 @@
 <!--E3D1B923F8E04C779E7D21999B43D709-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--E3D1B923F8E04C779E7D21999B43D709--></AD_MESSAGE>
 
+<!--E42923564BAD4EE2853E19DA0729E742--><AD_MESSAGE>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <AD_MESSAGE_ID><![CDATA[E42923564BAD4EE2853E19DA0729E742]]></AD_MESSAGE_ID>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <VALUE><![CDATA[OBKMO_ProblemLoadingWidget]]></VALUE>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <MSGTEXT><![CDATA[There has been a problem loading the widget with ID '%0'.]]></MSGTEXT>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
+<!--E42923564BAD4EE2853E19DA0729E742-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--E42923564BAD4EE2853E19DA0729E742--></AD_MESSAGE>
+
+<!--E67521112A4C4E25AD44125E51E55D9E--><AD_MESSAGE>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <AD_MESSAGE_ID><![CDATA[E67521112A4C4E25AD44125E51E55D9E]]></AD_MESSAGE_ID>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <VALUE><![CDATA[OBKMO_WidgetNotAvailableUserRole]]></VALUE>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <MSGTEXT><![CDATA[The widget is not available for the user '%0' with role '%1'.]]></MSGTEXT>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
+<!--E67521112A4C4E25AD44125E51E55D9E-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--E67521112A4C4E25AD44125E51E55D9E--></AD_MESSAGE>
+
 <!--F074D98ECE654C8A9D8D9B39AA81CFD3--><AD_MESSAGE>
 <!--F074D98ECE654C8A9D8D9B39AA81CFD3-->  <AD_MESSAGE_ID><![CDATA[F074D98ECE654C8A9D8D9B39AA81CFD3]]></AD_MESSAGE_ID>
 <!--F074D98ECE654C8A9D8D9B39AA81CFD3-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-calendar-widget.js	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-calendar-widget.js	Fri May 13 09:33:08 2016 +0200
@@ -29,6 +29,11 @@
     if (!this.calendarProps.isMultiCalendar && this.parameters.legendId) {
       this.calendarProps.legendId = this.parameters.legendId;
     }
+
+    // If there are parameters passed standalone (for example: widget loaded directly from url with "&restoredDefaultViewName=week"), add them too to the calendarProps
+    isc.addProperties(this.calendarProps, this.parameters);
+    delete this.calendarProps.calendarProps;
+
     calendarProps = this.calendarProps;
 
     if (!calendarProps) {
@@ -64,7 +69,11 @@
   },
 
   refresh: function () {
-    this.members[1].members[0].members[0].initComponents();
+    if (this.members[1]) {
+      this.members[1].members[0].members[0].initComponents();
+    } else if (this.members[0]) {
+      this.members[0].members[0].members[0].initComponents();
+    }
   },
 
   maximize: function () {
@@ -102,7 +111,7 @@
         canDelete: false
       }));
       this.addPortlet(widgetInstance);
-    } else {
+    } else if (OB.MainView) {
       //If the instance doesn't exist, just close the tab
       for (i = 0; i < OB.MainView.TabSet.tabs.length; i++) {
         if (OB.MainView.TabSet.tabs[i].title === 'OBCalendarWidgetView') {
--- a/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-myopenbravo.js	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-myopenbravo.js	Fri May 13 09:33:08 2016 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2014 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -417,8 +417,10 @@
 
 
   initWidget: function (args) {
-    this.createLeftColumnLayout();
-    this.createPortalLayout();
+    if (this.drawItems !== false) {
+      this.createLeftColumnLayout();
+      this.createPortalLayout();
+    }
 
     this.Super('initWidget', args);
 
@@ -431,6 +433,8 @@
       this.portalLayout.members[1].colNum = 1;
       this.portalLayout.sendEvents = true;
       this.reloadWidgets();
+    } else if (this.drawItems === false && OB.Application.licenseType !== 'C') {
+      this.reloadWidgets();
     }
   },
 
@@ -597,24 +601,34 @@
     }
   },
 
-  // ** {{{ OBMyOpenbravo.addWidget(widgetProperties) }}} **
+  // ** {{{ OBMyOpenbravo.createWidgetInstance(widgetProperties) }}} **
   //
   // Will check if the widget class is already present, if so then
-  // it is instantiated. If not then the widgetClass is loaded from the
-  // server and when loaded, the instance is created.
+  // its instance is returned. If not then the widgetClass is loaded from the
+  // server and when loaded, the instance is returned.
   //
   // Parameters:
   // * {{{widgetProperties}}}: properties used to create an instance of the widget
   // like the widgetClassName, height and title 
-  addWidget: function (widgetProperties) {
+  // * {{{callback}}}: callback function to execute if the widget is not loaded yet
+  createWidgetInstance: function (widgetProperties, callback) {
     var i, widgetInstance;
 
+    if (widgetProperties.widgetClassId && !widgetProperties.widgetClassName) {
+      for (i = 0; i < this.availableWidgetClasses.length; i++) {
+        if (this.availableWidgetClasses[i].widgetClassId === widgetProperties.widgetClassId) {
+          widgetProperties.widgetClassName = this.availableWidgetClasses[i].widgetClassName;
+          break;
+        }
+      }
+    }
+
     // if not there yet load it
-    if (!isc.ClassFactory.getClass(widgetProperties.widgetClassName)) {
+    if (!isc.ClassFactory.getClass(widgetProperties.widgetClassName) && typeof callback === 'function') {
       var rpcMgr = isc.RPCManager;
       var reqObj = {
         data: isc.JSONEncoder.create({}).encode(widgetProperties),
-        callback: this.widgetLoadCallback,
+        callback: callback,
         evalResult: true,
         clientContext: {
           widgetManager: this,
@@ -635,24 +649,39 @@
           if (!localWidgetProperties.aboutFieldDefinitions) {
             localWidgetProperties.aboutFieldDefinitions = this.availableWidgetClasses[i].aboutFieldDefinitions;
           }
-          if (!localWidgetProperties.parameters) {
-            localWidgetProperties.parameters = isc.addProperties({}, widgetProperties.parameters);
-          }
+          localWidgetProperties.parameters = isc.addProperties({}, this.availableWidgetClasses[i].parameters, widgetProperties.parameters);
           break;
         }
       }
       widgetInstance = isc.ClassFactory.newInstance(widgetProperties.widgetClassName, localWidgetProperties);
-      widgetInstance.widgetManager = this;
-      this.portalLayout.addPortlet(widgetInstance, localWidgetProperties.colNum, localWidgetProperties.rowNum);
+      if (widgetInstance) {
+        widgetInstance.widgetManager = this;
+      }
+      return widgetInstance;
     }
   },
 
-  // ** {{{ OBMyOpenbravo.widgetLoadCallback(rpcResponse, data, rpcRequest) }}} **
+
+  // ** {{{ OBMyOpenbravo.addWidget(widgetProperties) }}} **
+  //
+  // Will add to the Workspace the widget defined in the
+  // widgetProperties parameter.
+  //
+  // Parameters:
+  // * {{{widgetProperties}}}: properties used to add the widget to the Workspace
+  addWidget: function (widgetProperties) {
+    if (this.portalLayout) {
+      var widgetInstance = this.createWidgetInstance(widgetProperties, this.addWidgetLoadCallback);
+      this.portalLayout.addPortlet(widgetInstance, widgetInstance.colNum, widgetInstance.rowNum);
+    }
+  },
+
+  // ** {{{ OBMyOpenbravo.addWidgetLoadCallback(rpcResponse, data, rpcRequest) }}} **
   //
   // Is called when the widget class has been loaded from the backend, method
   // will call the addWidget method again (as now the class is loaded).
   //
-  widgetLoadCallback: function (rpcResponse, data, rpcRequest) {
+  addWidgetLoadCallback: function (rpcResponse, data, rpcRequest) {
     var widgetProperties = rpcRequest.clientContext.widgetProperties;
     var widgetManager = rpcRequest.clientContext.widgetManager;
 
@@ -708,7 +737,9 @@
       }
 
       this.isReloading = false;
-      this.portalLayout.sendEvents = !this.adminMode;
+      if (this.portalLayout) {
+        this.portalLayout.sendEvents = !this.adminMode;
+      }
 
       this.notifyEvent('WIDGET_MOVED');
     }
@@ -789,9 +820,12 @@
   // The widgets cache is refreshed before sending the event notification to the backend
   //
   updateWidgetsCache: function (eventType, responseWidgets) {
-    var columns = this.portalLayout.getMembers(),
+    var columns = [],
         i, j, k, newWidget, col, rows, row, widget, newObj;
 
+    if (this.portalLayout) {
+      columns = this.portalLayout.getMembers();
+    }
     this.widgets = []; // clear cache
     if (eventType === 'RELOAD_WIDGETS' && isc.isAn.Array(responseWidgets)) {
       this.widgets = responseWidgets.duplicate();
@@ -902,7 +936,9 @@
         levelLabel, levelValueLabel;
 
     this.adminMode = true;
-    this.portalLayout.sendEvents = false;
+    if (this.portalLayout) {
+      this.portalLayout.sendEvents = false;
+    }
     this.adminLevel = level.getValue();
     this.adminLevelValue = levelValue.getValue ? levelValue.getValue() : '';
 
@@ -944,7 +980,9 @@
 
     this.reloadWidgets();
 
-    this.portalLayout.sendEvents = true;
+    if (this.portalLayout) {
+      this.portalLayout.sendEvents = true;
+    }
   },
 
   reloadWidgets: function () {
@@ -953,10 +991,12 @@
       return;
     }
 
-    this.portalLayout.sendEvents = false;
+    if (this.portalLayout) {
+      this.portalLayout.sendEvents = false;
+      this.portalLayout.getMembers()[0].removeAllRows();
+      this.portalLayout.getMembers()[1].removeAllRows();
+    }
     this.isReloading = true;
-    this.portalLayout.getMembers()[0].removeAllRows();
-    this.portalLayout.getMembers()[1].removeAllRows();
     this.notifyEvent('RELOAD_WIDGETS');
   }
 });
--- a/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-widget.js	Wed May 11 17:18:45 2016 +0200
+++ b/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-widget.js	Fri May 13 09:33:08 2016 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2015 Openbravo SLU
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -522,4 +522,94 @@
     }
     this.switchMode();
   }
-});
\ No newline at end of file
+});
+
+
+OB.UrlModes = OB.UrlModes || {};
+OB.UrlModes.OBKMOWidget = OB.UrlModes.OBKMOWidget || {};
+
+OB.UrlModes.OBKMOWidget.customLayout = true;
+OB.UrlModes.OBKMOWidget.action = function (urlParams) {
+  var widgetClassId, inWidgetInFormMode, renderWidget;
+
+  widgetClassId = urlParams.widgetClassId;
+  delete urlParams.widgetClassId;
+
+  if (urlParams.inWidgetInFormMode === null || typeof urlParams.inWidgetInFormMode === 'undefined' || urlParams.inWidgetInFormMode === 'true' || urlParams.inWidgetInFormMode === true) {
+    inWidgetInFormMode = true;
+    isc.OBWidget.addProperties({
+      edgeSize: 0,
+      edgeTop: 0,
+      edgeBottom: 0,
+      edgeOffsetTop: 0,
+      edgeOffsetRight: 0,
+      edgeOffsetBottom: 0,
+      edgeOffsetLeft: 0
+    });
+  } else {
+    inWidgetInFormMode = false;
+  }
+  delete urlParams.inWidgetInFormMode;
+
+  var widgetProperties = {
+    widgetClassId: widgetClassId,
+    bodyColor: 'white',
+    inWidgetInFormMode: inWidgetInFormMode,
+    parameters: urlParams
+  };
+  var layout = isc.Layout.create({
+    width: '100%',
+    height: '100%',
+    members: []
+  });
+  OB.Layout.addMember(layout);
+  if (OB && !OB.MyOB) {
+    isc.OBMyOpenbravo.create({
+      drawItems: false
+    });
+  }
+  renderWidget = function (count) {
+    var showErrorMsg = function (text) {
+        isc.warn(text, function () {
+          return true;
+        }, {
+          icon: '[SKINIMG]Dialog/error.png',
+          title: OB.I18N.getLabel('OBUIAPP_Error')
+        });
+        };
+    var callback = function (rpcResponse, data, rpcRequest) {
+        widgetProperties = rpcRequest.clientContext.widgetProperties;
+        if (!isc.ClassFactory.getClass(widgetProperties.widgetClassName)) {
+          showErrorMsg(OB.I18N.getLabel('OBKMO_ProblemLoadingWidget', [widgetProperties.widgetClassId]) + '<br />' + OB.I18N.getLabel('OBKMO_WidgetNotAvailableUserRole', [OB.User.userName, OB.User.roleName]) + '<br />' + OB.I18N.getLabel('OBKMO_ContactSystemAdmin'));
+          return;
+        }
+        renderWidget(count + 1);
+        };
+    if (!count) {
+      count = 0;
+    } else if (count >= 150) {
+      showErrorMsg(OB.I18N.getLabel('OBKMO_ProblemLoadingWidget', [widgetProperties.widgetClassId]) + '<br />' + OB.I18N.getLabel('OBUIAPP_Timeout') + '<br />' + OB.I18N.getLabel('OBKMO_ContactSystemAdmin'));
+      return;
+    }
+
+    if (OB && OB.MyOB && OB.MyOB.createWidgetInstance) {
+      if (!OB.MyOB.availableWidgetClasses || OB.MyOB.availableWidgetClasses.length === 0) {
+        OB.MyOB.notifyEvent('RELOAD_WIDGETS');
+      } else {
+        var widgetInstance = OB.MyOB.createWidgetInstance(widgetProperties, callback);
+        if (widgetInstance) {
+          layout.addMember(widgetInstance);
+          return true;
+        } else {
+          showErrorMsg(OB.I18N.getLabel('OBKMO_ProblemLoadingWidget', [widgetProperties.widgetClassId]) + '<br />' + OB.I18N.getLabel('OBKMO_WidgetNotAvailableUserRole', [OB.User.userName, OB.User.roleName]) + '<br />' + OB.I18N.getLabel('OBKMO_ContactSystemAdmin'));
+          return;
+        }
+      }
+    }
+    setTimeout(function () {
+      renderWidget(count + 1);
+    }, 100);
+    return;
+  };
+  renderWidget();
+};
\ No newline at end of file
--- a/src/index.jsp	Wed May 11 17:18:45 2016 +0200
+++ b/src/index.jsp	Fri May 13 09:33:08 2016 +0200
@@ -249,7 +249,16 @@
   OBContext.restorePreviousMode();
 }
 %>
-  OB.Layout.initialize();
+  var urlParams, customLayout = false;
+  if (OB.Utilities && OB.Utilities.getUrlParameters() && OB.Utilities.getUrlParameters()) {
+    urlParams = OB.Utilities.getUrlParameters();
+  }
+  if (urlParams && urlParams.urlMode && OB.UrlModes && OB.UrlModes[urlParams.urlMode] && OB.UrlModes[urlParams.urlMode].customLayout) {
+    customLayout = true;
+  }
+  if (!customLayout) {
+    OB.Layout.initialize();
+  }
   OB.Layout.draw();
   OB.Layout.ViewManager.createAddStartTab();
   // get rid of the loading stuff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceOrderHook.java	Fri May 13 09:33:08 2016 +0200
@@ -0,0 +1,18 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2016 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+
+package org.openbravo.erpCommon.businessUtility;
+
+import org.openbravo.model.common.order.Order;
+
+public abstract class CancelAndReplaceOrderHook {
+
+  public abstract void exec(Boolean triggersDisabled, Order oldOrder, Order newOrder)
+      throws Exception;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceOrderHookCaller.java	Fri May 13 09:33:08 2016 +0200
@@ -0,0 +1,37 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2016 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+package org.openbravo.erpCommon.businessUtility;
+
+import java.util.Iterator;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.openbravo.model.common.order.Order;
+
+public class CancelAndReplaceOrderHookCaller {
+  @Inject
+  @Any
+  private Instance<CancelAndReplaceOrderHook> cancelAndReplaceOrderHookProcesses;
+
+  public void executeHook(boolean triggersDisabled, Order oldOrder, Order newOrder)
+      throws Exception {
+    executeHooks(triggersDisabled, oldOrder, newOrder);
+  }
+
+  protected void executeHooks(boolean triggersDisabled, Order oldOrder, Order newOrder)
+      throws Exception {
+    for (Iterator<CancelAndReplaceOrderHook> processIterator = cancelAndReplaceOrderHookProcesses
+        .iterator(); processIterator.hasNext();) {
+      CancelAndReplaceOrderHook process = processIterator.next();
+      process.exec(triggersDisabled, oldOrder, newOrder);
+    }
+  }
+}
--- a/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Wed May 11 17:18:45 2016 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Fri May 13 09:33:08 2016 +0200
@@ -329,6 +329,10 @@
       createPayments(oldOrder, newOrder, inverseOrder, jsonorder, useOrderDocumentNoForRelatedDocs,
           replaceOrder, triggersDisabled);
 
+     //Calling Cancelandreplaceorderhook
+     WeldUtils.getInstanceFromStaticBeanManager(CancelAndReplaceOrderHookCaller.class)
+          .executeHook(triggersDisabled, oldOrder, newOrder);
+
     } catch (Exception e1) {
       try {
         OBDal.getInstance().getConnection().rollback();