Fixes issue 22730: Tab appears blank when it has a view defined
authorMartin Taal <martin.taal@openbravo.com>
Mon, 28 Jan 2013 16:11:12 +0100
changeset 19486 3dff248e9297
parent 19485 9e98aa726bba
child 19487 e035b2855377
Fixes issue 22730: Tab appears blank when it has a view defined
Prevent javascript errors with preset filters in child tabs
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Mon Jan 28 14:27:22 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Mon Jan 28 16:11:12 2013 +0100
@@ -148,7 +148,7 @@
   },
 
   focusInFirstFilterEditor: function () {
-    if (this.getFilterEditor()) { // there is a filter editor
+    if (this.getFilterEditor() && this.getFilterEditor().getEditForm()) { // there is a filter editor
       var object = this.getFilterEditor().getEditForm(),
           items, item, i, length;
 
@@ -386,7 +386,7 @@
       var prop, fullPropName;
       // make a copy so that we don't change the object
       // which is maybe used somewhere else
-      criteria = isc.clone(criteria);
+      criteria = criteria ? isc.clone(criteria) : {};
       // If a criterion has been added to include the selected record, remove it
       // See issue https://issues.openbravo.com/view.php?id=20722
       criteria = this.removeSpecificIdFilter(criteria);
@@ -511,15 +511,21 @@
       delete this.filterClause;
     }
     this.forceRefresh = true;
-    this.filterEditor.getEditForm().clearValues();
+    if (this.filterEditor) {
+      if (this.filterEditor.getEditForm()) {
+        this.filterEditor.getEditForm().clearValues();
 
-    // clear the date values in a different way
-    length = this.filterEditor.getEditForm().getFields().length;
+        // clear the date values in a different way
+        length = this.filterEditor.getEditForm().getFields().length;
 
-    for (i = 0; i < length; i++) {
-      fld = this.filterEditor.getEditForm().getFields()[i];
-      if (fld.clearDateValues) {
-        fld.clearDateValues();
+        for (i = 0; i < length; i++) {
+          fld = this.filterEditor.getEditForm().getFields()[i];
+          if (fld.clearDateValues) {
+            fld.clearDateValues();
+          }
+        }
+      } else {
+        this.filterEditor.setValuesAsCriteria(null);
       }
     }
     if (!noPerformAction) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Mon Jan 28 14:27:22 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Mon Jan 28 16:11:12 2013 +0100
@@ -1062,6 +1062,12 @@
 
     // and no additional filter clauses passed in
     if (localState.filter && this.view.tabId !== this.view.standardWindow.additionalCriteriaTabId && this.view.tabId !== this.view.standardWindow.additionalFilterTabId) {
+      // a filtereditor but no editor yet
+      // set it in the initialcriteria of the filterEditro
+      if (this.filterEditor && !this.filterEditor.getEditForm()) {
+        this.filterEditor.setValuesAsCriteria(localState.filter);
+      }
+      
       this.setCriteria(localState.filter);
     }
   },
@@ -1438,6 +1444,8 @@
     this.resetEmptyMessage();
     this.view.updateTabTitle();
 
+    delete this.initialCriteria;
+    
     // do not refresh if the parent is not selected and we have no data
     // anyway
     if (this.view.parentProperty && (!this.data || !this.data.getLength || this.data.getLength() === 0)) {
@@ -2010,7 +2018,23 @@
     if (!this.view) {
       this.emptyMessage = this.noDataEmptyMessage;
     } else if (this.isGridFiltered(criteria)) {
-      this.emptyMessage = this.filterNoRecordsEmptyMessage;
+      // there can be some initial filters, but still no parent selected
+      if (this.view.parentView) {
+        selectedValues = this.view.parentView.viewGrid.getSelectedRecords();
+        parentIsNew = this.view.parentView.isShowingForm && this.view.parentView.viewForm.isNew;
+        parentIsNew = parentIsNew || (selectedValues.length === 1 && selectedValues[0]._new);
+        if (parentIsNew) {
+          this.emptyMessage = '<span class="' + this.emptyMessageStyle + '">' + OB.I18N.getLabel('OBUIAPP_ParentIsNew') + '</span>';
+        } else if (!selectedValues || selectedValues.length === 0) {
+          this.emptyMessage = '<span class="' + this.emptyMessageStyle + '">' + OB.I18N.getLabel('OBUIAPP_NoParentSelected') + '</span>';
+        } else if (selectedValues.length > 1) {
+          this.emptyMessage = '<span class="' + this.emptyMessageStyle + '">' + OB.I18N.getLabel('OBUIAPP_MultipleParentsSelected') + '</span>';
+        } else {
+          this.emptyMessage = this.filterNoRecordsEmptyMessage;
+        }
+      } else {
+        this.emptyMessage = this.filterNoRecordsEmptyMessage;
+      }
     } else if (this.view.isRootView) {
       this.emptyMessage = this.noDataEmptyMessage;
     } else {