Issue 18227: Destroy the selectorWindow and Grid when destroying item
authorIván Perdomo <ivan.perdomo@openbravo.com>
Tue, 16 Aug 2011 11:55:38 +0200
changeset 13516 fe669fa7121d
parent 13515 c094ddabc843
child 13527 b8c828c166bc
Issue 18227: Destroy the selectorWindow and Grid when destroying item
- The SelectorItem extends a ComboBoxItem but also has a selectorWindow and
this one, a OBGrid. This objects Needs to be destroyed explicitly.
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
--- a/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js	Fri Aug 12 18:51:54 2011 +0200
+++ b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js	Tue Aug 16 11:55:38 2011 +0200
@@ -33,7 +33,7 @@
     canGroupBy: false
   },
   
-  initWidget: function(){
+  initWidget: function () {
     var selectorWindow = this;
     this.setFilterEditorProperties(this.selectorGridFields);
     
@@ -250,17 +250,26 @@
       defaultFilter = {}; // Reset filter
       isc.addProperties(defaultFilter, data);
     }
-    
+
     // adds the selector id to filter used to get filter information
     defaultFilter._selectorDefinitionId = this.selector.selectorDefinitionId;
     this.defaultFilter = defaultFilter;
     this.selectorGrid.targetRecordId = this.selector.getValue();
     this.show(true);
   },
-  
+
   setValueInField: function(){
     this.selector.setValueFromRecord(this.selectorGrid.getSelectedRecord(), true);
     this.hide();
+  },
+
+  destroy: function () {
+    // Destroy the selectorGrid to avoid memory leaks
+    if(this.selectorGrid) {
+      this.selectorGrid.destroy();
+      this.selectorGrid = null;
+    }
+    this.Super('destroy', arguments);
   }
 });
 
@@ -602,6 +611,15 @@
       return '';
     }
     return ret;
+  },
+
+  destroy: function () {
+    // Explicitly destroy the selector window to avoid memory leaks
+    if(this.selectorWindow) {
+      this.selectorWindow.destroy();
+      this.selectorWindow = null;
+    }
+    this.Super('destroy', arguments);
   }
 });
 
@@ -770,5 +788,14 @@
       this.form.handleItemChange(this);
     }
     return ret;
+  },
+
+  destroy: function () {
+    // Explicitly destroy the selector window to avoid memory leaks
+    if(this.selectorWindow) {
+      this.selectorWindow.destroy();
+      this.selectorWindow = null;
+    }
+    this.Super('destroy', arguments);
   }
 });