# HG changeset patch
# User Shankar Balachandran <shankar.balachandran@openbravo.com>
# Date 1352369698 -3600
# Node ID e2f9023de570b75d8c6f5c7af8b5d2575e55ba10
# Parent  842c35bdcc07a7f206763d6878d2444cd6558477
0022131: AD_Tab_Access for inactive tabs is causing javascript errors

If we mark as inactive a tab that is included in the tab_access for a particular role causes the following error when accessing to the window that includes the tab: "Cannot read property 'viewForm' of null". Added not null validation before accessing objects of view.

diff --git a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js
@@ -425,39 +425,41 @@
         tab = data.tabs[t];
         view = this.getView(tab.tabId);
         disabledFields = [];
-        for (i = 0; i < view.viewForm.getFields().length; i++) {
-          field = view.viewForm.getFields()[i];
-          if (tab.fields[field.name] !== undefined) {
-            field.updatable = tab.fields[field.name];
-            field.disabled = !tab.fields[field.name];
-            if (!tab.fields[field.name]) {
-              disabledFields.push(field.name);
+        if (view !== null) {
+          for (i = 0; i < view.viewForm.getFields().length; i++) {
+            field = view.viewForm.getFields()[i];
+            if (tab.fields[field.name] !== undefined) {
+              field.updatable = tab.fields[field.name];
+              field.disabled = !tab.fields[field.name];
+              if (!tab.fields[field.name]) {
+                disabledFields.push(field.name);
+              }
             }
           }
-        }
-        view.disabledFields = disabledFields;
-        for (i = 0; i < view.viewGrid.getFields().length; i++) {
-          field = view.viewGrid.getFields()[i];
-          if (tab.fields[field.name] !== undefined) {
-            field.editorProperties.updatable = tab.fields[field.name];
-            field.editorProperties.disabled = !tab.fields[field.name];
+          view.disabledFields = disabledFields;
+          for (i = 0; i < view.viewGrid.getFields().length; i++) {
+            field = view.viewGrid.getFields()[i];
+            if (tab.fields[field.name] !== undefined) {
+              field.editorProperties.updatable = tab.fields[field.name];
+              field.editorProperties.disabled = !tab.fields[field.name];
+            }
           }
-        }
-        for (i = 0; i < view.toolBar.rightMembers.length; i++) {
-          button = view.toolBar.rightMembers[i];
-          if (tab.tabId === button.contextView.tabId && button.property && !tab.fields[button.property]) {
-            button.readOnlyIf = alwaysReadOnly;
-            // looking for this button in subtabs
-            for (st = 0; st < this.views.length; st++) {
-              stView = this.views[st];
-              if (stView === view) {
-                continue;
-              }
-              for (stBtns = 0; stBtns < stView.toolBar.rightMembers.length; stBtns++) {
-                stBtn = stView.toolBar.rightMembers[stBtns];
-                if (stBtn.contextView === button.contextView && stBtn.property && !tab.fields[stBtn.property]) {
-                  stBtn.readOnlyIf = alwaysReadOnly;
-                  break;
+          for (i = 0; i < view.toolBar.rightMembers.length; i++) {
+            button = view.toolBar.rightMembers[i];
+            if (tab.tabId === button.contextView.tabId && button.property && !tab.fields[button.property]) {
+              button.readOnlyIf = alwaysReadOnly;
+              // looking for this button in subtabs
+              for (st = 0; st < this.views.length; st++) {
+                stView = this.views[st];
+                if (stView === view) {
+                  continue;
+                }
+                for (stBtns = 0; stBtns < stView.toolBar.rightMembers.length; stBtns++) {
+                  stBtn = stView.toolBar.rightMembers[stBtns];
+                  if (stBtn.contextView === button.contextView && stBtn.property && !tab.fields[stBtn.property]) {
+                    stBtn.readOnlyIf = alwaysReadOnly;
+                    break;
+                  }
                 }
               }
             }
