# HG changeset patch
# User Shankar Balachandran <shankar.balachandran@openbravo.com>
# Date 1385629989 -19800
# Node ID 639ffe50e3809c9ed44b1ee001b7d1e23ee781e4
# Parent  68197384f3d3187770d57ffa54c50e9e57b0c904
Fixes Issue 25161,25159,25136 : openDirectTab and openView optimization

Modifications in OB.Utilities.openDirectTab
* Added a new parameter direct that would enable only to fetch the particular record alone.
* By default it is set to true if recordId argument is present.
* If all data needs to be fetched, the argument should be passed as false.

diff -r 68197384f3d3 -r 639ffe50e380 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js	Wed Nov 27 14:44:13 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities.js	Thu Nov 28 14:43:09 2013 +0530
@@ -343,14 +343,14 @@
 // Open a view using a tab id and record id. The tab can be a child tab. If the record id
 // is not set then the tab is opened in grid mode. If command is not set then default is
 // used.
-OB.Utilities.openDirectTab = function (tabId, recordId, command, position, criteria) {
+OB.Utilities.openDirectTab = function (tabId, recordId, command, position, criteria, direct) {
 
   tabId = OB.Utilities.removeFragment(tabId);
   recordId = OB.Utilities.removeFragment(recordId);
   command = OB.Utilities.removeFragment(command);
 
   var urlParams = OB.Utilities.getUrlParameters(),
-      callback;
+      callback, isDirect = direct;
 
   //added to have the additional filter clause and tabid. Mallikarjun M
   callback = function (response, data, request) {
@@ -360,6 +360,7 @@
       tabTitle: data.tabTitle,
       windowId: data.windowId,
       tabId: data.tabId,
+      id: data.tabId,
       command: command,
       tabPosition: position
     };
@@ -370,6 +371,9 @@
 
     if (recordId) {
       view.targetRecordId = recordId;
+      if (direct !== false) {
+        isDirect = true;
+      }
     }
 
     //// Begins-added to have the additional filter clause and tabid..Mallikarjun M
@@ -392,7 +396,7 @@
       view.additionalCriteria = criteria;
     }
     ////Ends..
-    OB.Layout.ViewManager.openView(view.viewId, view);
+    OB.Layout.ViewManager.openView(view.viewId, view, null, isDirect);
   };
 
   OB.RemoteCallManager.call('org.openbravo.client.application.ComputeWindowActionHandler', {}, {
@@ -418,9 +422,17 @@
 // Open a view taking into account if a specific window should be opened in classic mode or not.
 // Returns the object used to open the window.
 OB.Utilities.openView = function (windowId, tabId, tabTitle, recordId, command, icon, readOnly, singleRecord, direct, editOrDeleteOnly) {
-  var isClassicEnvironment = OB.Utilities.useClassicMode(windowId);
-
-  var openObject;
+  var isClassicEnvironment = OB.Utilities.useClassicMode(windowId),
+      openObject, isDirect = direct,
+      isSingleRecord;
+  if (recordId) {
+    if (direct !== false) {
+      isDirect = true;
+    }
+    if (singleRecord !== false) {
+      isSingleRecord = true;
+    }
+  }
   if (isClassicEnvironment) {
     if (recordId) {
       OB.Layout.ClassicOBCompatibility.openLinkedItem(tabId, recordId);
@@ -444,7 +456,7 @@
       tabTitle: tabTitle,
       windowId: windowId,
       readOnly: readOnly,
-      singleRecord: singleRecord,
+      singleRecord: isSingleRecord,
       editOrDeleteOnly: editOrDeleteOnly
     };
   } else {
@@ -456,14 +468,14 @@
       windowId: windowId,
       icon: icon,
       readOnly: readOnly,
-      singleRecord: singleRecord,
+      singleRecord: isSingleRecord,
       editOrDeleteOnly: editOrDeleteOnly
     };
   }
   if (command) {
     openObject.command = command;
   }
-  OB.Layout.ViewManager.openView(openObject.viewId, openObject, null, direct);
+  OB.Layout.ViewManager.openView(openObject.viewId, openObject, null, isDirect);
   return openObject;
 };
 
