Added new utility for direct opening using just tabId and recordId
authorMartin Taal <martin.taal@openbravo.com>
Tue, 08 Mar 2011 15:26:12 +0100
changeset 11098 44a28572b42c
parent 11097 5e3b48c5dec6
child 11099 f7e47cafe51c
Added new utility for direct opening using just tabId and recordId
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Tue Mar 08 15:25:13 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Tue Mar 08 15:26:12 2011 +0100
@@ -24,10 +24,27 @@
 // ** {{{OB.Utilities.createLoadingLayout}}} **
 // Creates a layout with the loading image.
 OB.Utilities.createLoadingLayout = function(){
-  var mainLayout = isc.HLayout.create({styleName: OB.LoadingPrompt.mainLayoutStyleName, width: '100%', height: '100%', align: 'center', defaultLayoutAlign: 'center'});
-  var loadingLayout = isc.HLayout.create({styleName: OB.LoadingPrompt.loadingLayoutStyleName, width: 1, height: 1, overflow: 'visible'});
+  var mainLayout = isc.HLayout.create({
+    styleName: OB.LoadingPrompt.mainLayoutStyleName,
+    width: '100%',
+    height: '100%',
+    align: 'center',
+    defaultLayoutAlign: 'center'
+  });
+  var loadingLayout = isc.HLayout.create({
+    styleName: OB.LoadingPrompt.loadingLayoutStyleName,
+    width: 1,
+    height: 1,
+    overflow: 'visible'
+  });
   mainLayout.addMember(loadingLayout);
-  loadingLayout.addMember(isc.Label.create({contents: OB.I18N.getLabel('OBUIAPP_LOADING'), styleName: 'OBLoadingPromptLabel', width: 1, height: 1, overflow: 'visible'}));
+  loadingLayout.addMember(isc.Label.create({
+    contents: OB.I18N.getLabel('OBUIAPP_LOADING'),
+    styleName: 'OBLoadingPromptLabel',
+    width: 1,
+    height: 1,
+    overflow: 'visible'
+  }));
   loadingLayout.addMember(isc.Img.create(OB.LoadingPrompt.loadingImage));
   return mainLayout;
 };
@@ -79,30 +96,30 @@
 // If action is null/undefined then nothing is done and undefined is returned.
 // When the action is called the result of the action is returned.
 OB.Utilities.callAction = function(action){
-  function IEApplyHack(method, object, parameters) {
+  function IEApplyHack(method, object, parameters){
     if (!object) {
       object = window;
     }
     if (!parameters) {
       parameters = [];
     }
-
+    
     object.customApplyMethod = method;
-
+    
     var argsString = [];
-    for(var i = 0; i < parameters.length; i++) {
+    for (var i = 0; i < parameters.length; i++) {
       argsString[i] = 'parameters[' + i + ']';
     }
-
+    
     var argsList = argsString.join(",");
-
+    
     var result = eval('object.customApplyMethod(' + argsList + ');');
-
+    
     delete object.customApplyMethod;
-
+    
     return result;
   }
-
+  
   if (!action) {
     return;
   }
@@ -147,6 +164,37 @@
   return false;
 };
 
+// ** {{{OB.Utilities.openDirectTab}}} **
+// 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){
+  var callback = function(response, data, request){
+    command = command || 'DEFAULT';
+    var view = {
+      viewId: '_' + data.windowId,
+      tabTitle: data.tabTitle,
+      windowId: data.windowId,
+      tabId: data.tabId,
+      command: command
+    };
+    // new is only supported for the top tab
+    if (command !== 'NEW') {
+      view.targetTabId = tabId;
+    }
+      
+    if (recordId) {
+      view.targetRecordId = recordId;
+    }
+    OB.Layout.ViewManager.openView(view.viewId, view);
+  };
+  
+  OB.RemoteCallManager.call('org.openbravo.client.application.ComputeWindowActionHandler', {}, {
+    'tabId': tabId,
+    'recordId': recordId
+  }, callback);
+};
+
 // ** {{{OB.Utilities.openView}}} **
 // 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.
@@ -233,6 +281,21 @@
   }
   return msgString;
 };
+// ** {{{OB.Utilities.getUrlParameters}}} **
+// Returns the url parameters as a javascript object. Note works for simple cases
+// where no & is used for character encoding, this is fine for most cases.
+OB.Utilities.getUrlParameters = function(){
+  var vars = {}, hash, href = window.location.href, hashes = href.slice(href.indexOf('?') + 1).split('&');
+  
+  for (var i = 0; i < hashes.length; i++) {
+    hash = hashes[i].split('=');
+    if (hash[i] && hash[i].contains('#')) {
+      hash[i] = hash[i].substring(0, hash[i].indexOf('#'));
+    }
+    vars[hash[0]] = hash[1];
+  }
+  return vars;
+};
 
 // ** {{{OB.Utilities.hasUrlParameter}}} **
 // Returns true if the url has a certain parameter with a certain value.
@@ -552,11 +615,11 @@
 //
 // Parameters:
 // * {{{currentValues}}}: array of values
-OB.Utilities.fixNull250 = function (currentValues){
+OB.Utilities.fixNull250 = function(currentValues){
   var i;
-  for(i in currentValues) { 
-    if(currentValues.hasOwnProperty(i) && 
-       currentValues[i] === null) {
+  for (i in currentValues) {
+    if (currentValues.hasOwnProperty(i) &&
+    currentValues[i] === null) {
       currentValues[i] = '';
     }
   }
@@ -567,11 +630,11 @@
 //
 // Parameters:
 // * {{{url}}}: String url
-OB.Utilities.isValidURL = function(url) {
+OB.Utilities.isValidURL = function(url){
   // Validation based on: http://view.jquery.com/trunk/plugins/validate/jquery.validate.js
   // Note: http://localhost is not a valid URL, http://localhost.localdomain is a valid one
-  if(!url) {
+  if (!url) {
     return false;
   }
   return (/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i).test(url);
-};
\ No newline at end of file
+};