[Tree Extension] Defines OBTreeFilterSelectItem, adds mapValueToDisplay
authorAugusto Mauch <augusto.mauch@openbravo.com>
Thu, 06 Feb 2014 10:48:14 +0100
changeset 22505 470f9cbb581d
parent 22504 aa96c53ec27d
child 22506 c852439d2ef1
[Tree Extension] Defines OBTreeFilterSelectItem, adds mapValueToDisplay
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBTreeReferenceComponent.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-tree.js
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBTreeReferenceComponent.java	Thu Feb 06 10:41:03 2014 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBTreeReferenceComponent.java	Thu Feb 06 10:48:14 2014 +0100
@@ -412,7 +412,7 @@
     public String getFilterEditorProperties() {
       if (getUIDefinition() != null) {
         if (getUIDefinition() instanceof FKComboUIDefinition) {
-          return ", canFilter:true, required: false, filterEditorType: 'OBSelectorFilterSelectItem', filterEditorProperties: {entity: '"
+          return ", canFilter:true, required: false, filterEditorType: 'OBTreeFilterSelectItem', filterEditorProperties: {entity: '"
               + getEntityName() + "'}";
         }
         return getUIDefinition().getFilterEditorProperties(null);
@@ -621,4 +621,8 @@
       return null;
     }
   }
+
+  public String getReferencedTableId() {
+    return referencedTree.getTable().getId();
+  }
 }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-tree.js	Thu Feb 06 10:41:03 2014 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-tree.js	Thu Feb 06 10:48:14 2014 +0100
@@ -180,6 +180,28 @@
       this.form.focusInNextItem(this.name);
     }
     delete this._notUpdatingManually;
+  },
+
+  mapValueToDisplay: function (value) {
+    var ret = this.Super('mapValueToDisplay', arguments);
+    if (ret === value && this.isDisabled()) {
+      return '';
+    }
+    // if value is null then don't set it in the valueMap, this results 
+    // in null being displayed in the combobox
+    if (ret === value && value) {
+      if (!this.valueMap) {
+        this.valueMap = {};
+        this.valueMap[value] = '';
+        return '';
+      } else if (!this.valueMap[value] && OB.Utilities.isUUID(value)) {
+        return '';
+      }
+    }
+    if (value && value !== '' && ret === '' && !OB.Utilities.isUUID(value)) {
+      this.savedEnteredValue = value;
+    }
+    return ret;
   }
 
 });
@@ -350,6 +372,8 @@
       }
     });
 
+    this.setFilterEditorProperties(this.treeGridFields);
+
     OB.Utilities.applyDefaultValues(this.treeGridFields, this.defaultTreeGridField);
 
     for (i = 0; i < this.treeGridFields.length; i++) {
@@ -537,6 +561,15 @@
     this.Super('initWidget', arguments);
   },
 
+  setFilterEditorProperties: function (gridFields) {
+    var i, gridField;
+    for (i = 0; i < gridFields.length; i++) {
+      gridField = gridFields[i];
+      gridField.filterEditorProperties = gridField.filterEditorProperties || {};
+      gridFields[i].filterEditorProperties.treeWindow = this;
+    }
+  },
+
   destroy: function () {
     var i;
     for (i = 0; i < this.items.length; i++) {
@@ -598,4 +631,25 @@
     this.treeItem.setValueFromRecord(record);
     this.hide();
   }
+});
+
+isc.ClassFactory.defineClass('OBTreeFilterSelectItem', isc.OBFKFilterTextItem);
+
+isc.OBTreeFilterSelectItem.addProperties({
+
+  filterDataBoundPickList: function (requestProperties, dropCache) {
+    requestProperties = requestProperties || {};
+    requestProperties.params = requestProperties.params || {};
+    // on purpose not passing the third boolean param
+    var contextInfo = this.treeWindow.treeItem.form.view.getContextInfo(false, true);
+
+    // also add the special ORG parameter
+    if (this.treeWindow.treeItem.form.getField('organization')) {
+      requestProperties.params[OB.Constants.ORG_PARAMETER] = this.treeWindow.treeItem.form.getValue('organization');
+    } else if (contextInfo.inpadOrgId) {
+      requestProperties.params[OB.Constants.ORG_PARAMETER] = contextInfo.inpadOrgId;
+    }
+    requestProperties.params._tableId = this.treeWindow.treeItem.referencedTableId;
+    return this.Super('filterDataBoundPickList', [requestProperties, true]);
+  }
 });
\ No newline at end of file