Fixes issue 24015: Improved standard view handling in the saved view feature
authorAugusto Mauch <augusto.mauch@openbravo.com>
Wed, 21 Aug 2013 10:26:58 +0200
changeset 21003 7fb360627360
parent 21002 19b6e84d11da
child 21004 6ca87037847e
Fixes issue 24015: Improved standard view handling in the saved view feature

Now:
- When the standard view is reapplied, the original filter clause is not lost
- The Standard Views appeas as a selectable option in the Set Default View combo
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/personalization/ob-manage-views-popups.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Tue Aug 20 16:13:37 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Wed Aug 21 10:26:58 2013 +0200
@@ -992,6 +992,8 @@
       }
     }
 
+    state.filterClause = this.filterClause;
+
     // set summary information, can not be stored in the field state
     // because smartclient does not provide a nice override point
     // when setting the fieldstate back to also set the summary function
@@ -1074,6 +1076,8 @@
       if (this.view.messageBar) {
         this.view.messageBar.hide();
       }
+    } else if (localState.filterClause) {
+      this.filterClause = localState.filterClause;
     }
 
     // and no additional filter clauses passed in
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js	Tue Aug 20 16:13:37 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js	Wed Aug 21 10:26:58 2013 +0200
@@ -500,43 +500,6 @@
     if (this.getClass().personalization.views) {
       views = this.getClass().personalization.views;
       length = views.length;
-      if (persDefaultValue) {
-        for (i = 0; i < length; i++) {
-          if (persDefaultValue === views[i].personalizationId) {
-            defaultView = views[i];
-            break;
-          }
-        }
-      }
-      if (!defaultView) {
-        for (i = 0; i < length; i++) {
-          if (views[i].viewDefinition && views[i].viewDefinition.isDefault) {
-            defaultView = views[i];
-            break;
-          }
-        }
-      }
-
-      // apply the default view
-      // maybe do this in a separate thread
-      if (defaultView) {
-        OB.Personalization.applyViewDefinition(defaultView.personalizationId, defaultView.viewDefinition, this);
-      } else {
-        // only apply the default form/grid if there are no views
-        // otherwise you get strange interference
-        // check the default form and grid viewstates
-        length = this.views.length;
-        for (i = 0; i < length; i++) {
-          if (personalization.forms && personalization.forms[this.views[i].tabId]) {
-            this.lastViewApplied = true;
-            OB.Personalization.personalizeForm(personalization.forms[this.views[i].tabId], this.views[i].viewForm);
-          }
-          if (this.viewState && this.viewState[this.views[i].tabId]) {
-            this.lastViewApplied = true;
-            this.views[i].viewGrid.setViewState(this.viewState[this.views[i].tabId]);
-          }
-        }
-      }
 
       this.getClass().personalization.views.sort(function (v1, v2) {
         var t1 = v1.viewDefinition.name,
@@ -548,6 +511,46 @@
         }
         return 1;
       });
+
+      if (persDefaultValue !== 'dummyId') {
+        if (persDefaultValue) {
+          for (i = 0; i < length; i++) {
+            if (persDefaultValue === views[i].personalizationId) {
+              defaultView = views[i];
+              break;
+            }
+          }
+        }
+        if (!defaultView) {
+          for (i = 0; i < length; i++) {
+            if (views[i].viewDefinition && views[i].viewDefinition.isDefault) {
+              defaultView = views[i];
+              break;
+            }
+          }
+        }
+
+        // apply the default view
+        // maybe do this in a separate thread
+        if (defaultView) {
+          OB.Personalization.applyViewDefinition(defaultView.personalizationId, defaultView.viewDefinition, this);
+        } else {
+          // only apply the default form/grid if there are no views
+          // otherwise you get strange interference
+          // check the default form and grid viewstates
+          length = this.views.length;
+          for (i = 0; i < length; i++) {
+            if (personalization.forms && personalization.forms[this.views[i].tabId]) {
+              this.lastViewApplied = true;
+              OB.Personalization.personalizeForm(personalization.forms[this.views[i].tabId], this.views[i].viewForm);
+            }
+            if (this.viewState && this.viewState[this.views[i].tabId]) {
+              this.lastViewApplied = true;
+              this.views[i].viewGrid.setViewState(this.viewState[this.views[i].tabId]);
+            }
+          }
+        }
+      }
     }
 
     // restore focus as the focusitem may have been hidden now
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/personalization/ob-manage-views-popups.js	Tue Aug 20 16:13:37 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/personalization/ob-manage-views-popups.js	Wed Aug 21 10:26:58 2013 +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) 2011-2012 Openbravo SLU
+ * All portions are Copyright (C) 2011-2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s): ___________
  ************************************************************************
@@ -139,13 +139,14 @@
         valueMap = {},
         flds = [],
         standardWindow = this.standardWindow,
-        length;
+        length, originalView = standardWindow.getClass().originalView;
 
     if (views) {
       length = views.length;
       for (i = 0; i < length; i++) {
         valueMap[views[i].personalizationId] = views[i].viewDefinition.name;
       }
+      valueMap[originalView.personalizationId] = originalView.viewDefinition.name;
     }
 
     flds[0] = isc.addProperties({
@@ -155,7 +156,6 @@
       editorType: 'select',
       addUnknownValues: false,
       required: true,
-      allowEmptyValue: true,
       changed: function () {
         // enable the save button when there is a change
         this.form.saveButton.setDisabled(false);
@@ -166,8 +166,10 @@
 
     // set the value
     value = OB.PropertyStore.get('OBUIAPP_DefaultSavedView', this.standardWindow.windowId);
-    if (value) {
+    if (value && flds[0].valueMap[value]) {
       flds[0].value = value;
+    } else {
+      flds[0].value = 'dummyId';
     }
 
     return flds;