Fixes issue 25558: Fixes callout of manual forms
authorAugusto Mauch <augusto.mauch@openbravo.com>
Tue, 18 Mar 2014 17:23:09 +0100
changeset 22729 05acae86769b
parent 22728 e7467e149bb0
child 22730 01545189968e
Fixes issue 25558: Fixes callout of manual forms

The code that applies the response of the manual forms callout was taking for granted that there one only one frame called appFrame. This was true in Openbravo 2.50, but in Openbravo 3.0 many manual windows can be opened at the same time, so there may be several frames called appFrame in one given moment.

This has been fixed by storing the active manual frame (the one whose tab is focused), and using that frame when applying the response of the callout.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/classic/ob-classic-window.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-tab.js
src/org/openbravo/erpCommon/security/Login.html
src/org/openbravo/erpCommon/security/Login_F1.html
web/js/callOut.js
web/js/utils.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/classic/ob-classic-window.js	Tue Mar 18 20:52:07 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/classic/ob-classic-window.js	Tue Mar 18 17:23:09 2014 +0100
@@ -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-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -124,6 +124,8 @@
       this.contentsURL = this.contentsURL + '&hideMenu=true';
     }
 
+    this.setAsActiveIFrame();
+
     this.Super('initWidget', args);
   },
 
@@ -329,6 +331,31 @@
         appFrame.location.href = result.redirect;
       }
     }
+  },
+
+  // Waits until the iFrame has been loaded, and sets it as activeFrame
+  // See issue https://issues.openbravo.com/view.php?id=25558
+  setAsActiveIFrame: function (nCalls) {
+    var iFrame, me = this,
+        parentFrame;
+    if (!nCalls) {
+      nCalls = 0;
+    } else if (nCalls > 20) {
+      // Prevent infinite recursion
+      return;
+    }
+    iFrame = this.getAppFrameWindow();
+    if (!iFrame) {
+      setTimeout(function () {
+        me.setAsActiveIFrame(nCalls++);
+      }, 500);
+    } else {
+      parentFrame = iFrame.parent;
+      while (parentFrame.name !== '') {
+        parentFrame = parentFrame.parent;
+      }
+      parentFrame.activeFrame = iFrame;
+    }
   }
 });
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-tab.js	Tue Mar 18 20:52:07 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-tab.js	Tue Mar 18 17:23:09 2014 +0100
@@ -77,6 +77,7 @@
   }),
 
   tabSelected: function (tabNum, tabPane, ID, tab) {
+    var appFrame;
     if (navigator.userAgent.indexOf('Trident') !== -1 && navigator.userAgent.indexOf('Trident/5.0') === -1) {
       // To fix a problem with Internet Explorer 10 and classic OB windows: http://forums.smartclient.com/showthread.php?t=27389
       if (tabPane.viewId === 'OBClassicWindow' || tabPane.viewId === 'ClassicOBHelp') {
@@ -89,12 +90,20 @@
     if (tabPane.tabSelected) { //Redirect if tabPane has its own tabSelected handler
       tabPane.tabSelected(tabNum, tabPane, ID, tab);
     }
-
+    // Set the active classic frame as activeFrame
+    // See https://issues.openbravo.com/view.php?id=25558
+    if (tabPane.viewId === 'OBClassicWindow') {
+      appFrame = tabPane.appFrameWindow || tabPane.getAppFrameWindow();
+      if (appFrame && appFrame.parent && appFrame.parent.parent) {
+        appFrame.parent.parent.activeFrame = appFrame;
+      }
+    }
     // update the document title
     document.title = OB.Constants.WINTITLE + ' - ' + tab.title;
   },
 
   tabDeselected: function (tabNum, tabPane, ID, tab, newTab) {
+	var appFrame;
     if (navigator.userAgent.indexOf('Trident') !== -1 && navigator.userAgent.indexOf('Trident/5.0') === -1) {
       // To fix a problem with Internet Explorer 10 and classic OB windows: http://forums.smartclient.com/showthread.php?t=27389
       if (tabPane.viewId === 'OBClassicWindow' || tabPane.viewId === 'ClassicOBHelp') {
@@ -104,6 +113,12 @@
     if (tabPane.tabDeselected) { //Redirect if tabPane has its own tabDeselected handler
       tabPane.tabDeselected(tabNum, tabPane, ID, tab, newTab);
     }
+    if (tabPane.viewId === 'OBClassicWindow') {
+      appFrame = tabPane.appFrameWindow || tabPane.getAppFrameWindow();
+      if (appFrame && appFrame.parent && appFrame.parent.parent) {
+        delete appFrame.parent.parent.activeFrame;
+      }
+    }
   },
 
   closeClick: function (tab) {
--- a/src/org/openbravo/erpCommon/security/Login.html	Tue Mar 18 20:52:07 2014 +0100
+++ b/src/org/openbravo/erpCommon/security/Login.html	Tue Mar 18 17:23:09 2014 +0100
@@ -406,7 +406,7 @@
     }
     catch (e) { }
 
-    if ((!revisionControl('21897')) || (isOpsInstance() != isOpsInstanceCached())) {
+    if ((!revisionControl('22716')) || (isOpsInstance() != isOpsInstanceCached())) {
       maskLoginWindow(cacheMsg);
       setLoginMessage('Warning', '', cacheMsg);
     }
--- a/src/org/openbravo/erpCommon/security/Login_F1.html	Tue Mar 18 20:52:07 2014 +0100
+++ b/src/org/openbravo/erpCommon/security/Login_F1.html	Tue Mar 18 17:23:09 2014 +0100
@@ -126,7 +126,7 @@
       clearForm();
     } catch (e) {}
     setWindowElementFocus('firstElement');
-    if ((!revisionControl('21897')) || (isOpsInstance() != isOpsInstanceCached())) {
+    if ((!revisionControl('22716')) || (isOpsInstance() != isOpsInstanceCached())) {
       alert(cacheMsg);
     }
 
--- a/web/js/callOut.js	Tue Mar 18 20:52:07 2014 +0100
+++ b/web/js/callOut.js	Tue Mar 18 17:23:09 2014 +0100
@@ -11,17 +11,17 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2014 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
-*/
+ */
 
 /**
-* @fileoverview Contains a function returnReponse that is called upon load 
-* of a callout template (eg. CallOut.html) and fills specified form fields
-* with specified values.
-*/
+ * @fileoverview Contains a function returnReponse that is called upon load
+ * of a callout template (eg. CallOut.html) and fills specified form fields
+ * with specified values.
+ */
 
 var frameDefault = "appFrame";
 
@@ -30,8 +30,13 @@
 }
 
 function setgWaitingCallOut(state, frameName) {
-  if (frameName==null || frameName=="") frameName=frameDefault;
-  objFrame = eval("parent." + frameName);
+  if (frameName == null || frameName == "") frameName = frameDefault;
+  // If there is an active appFrame in the window, pick it
+  if (frameName === 'appFrame' && parent.parent.activeFrame) {
+    objFrame = parent.parent.activeFrame;
+  } else {
+    objFrame = eval("parent." + frameName);
+  }
   if (!objFrame) {
     // working in 3.0 modal window
     objFrame = parent;
@@ -47,9 +52,14 @@
     frameName = 'appFrame';
   }
   setgWaitingCallOut(false, frameName);
-  if (arrResponse==null && (calloutName==null || calloutName=="")) return false;
-  if (frameName==null || frameName=="") frameName=frameDefault;
-  objFrame = eval("parent." + frameName);
+  if (arrResponse == null && (calloutName == null || calloutName == "")) return false;
+  if (frameName == null || frameName == "") frameName = frameDefault;
+  // If there is an active appFrame in the window, pick it
+  if (frameName === 'appFrame' && parent.parent.activeFrame) {
+    objFrame = parent.parent.activeFrame;
+  } else {
+    objFrame = eval("parent." + frameName);
+  }
   if (!objFrame) {
     // working in 3.0 modal window
     objFrame = parent;
@@ -63,4 +73,4 @@
       objFrame.displayLogic();
     } catch (ignored) {}
   }
-}
+}
\ No newline at end of file
--- a/web/js/utils.js	Tue Mar 18 20:52:07 2014 +0100
+++ b/web/js/utils.js	Tue Mar 18 17:23:09 2014 +0100
@@ -101,7 +101,7 @@
 * Return a number that would be checked at the Login screen to know if the file is cached with the correct version
 */
 function getCurrentRevision() {
-  var number = '21897';
+  var number = '22716';
   return number;
 }