Fixes issue 18227: Destroying a Grid doesn't destroy the DS associated
authorIván Perdomo <ivan.perdomo@openbravo.com>
Thu, 18 Aug 2011 12:57:18 +0200
changeset 13558 64678d049fe8
parent 13557 d72ed756c368
child 13559 8afb69d7545e
Fixes issue 18227: Destroying a Grid doesn't destroy the DS associated
When you destroy a ListGrid the associated datasource is not distroyed. In our
case we want to do it since we have a DS per selector grid.
Only destroy the DS if the tab/window is getting destroyed, not when the view
gets a DataSource though setDataSource()
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	Thu Aug 18 08:23:33 2011 +0200
+++ b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js	Thu Aug 18 12:57:18 2011 +0200
@@ -266,11 +266,16 @@
   destroy: function () {
     // Destroy the selectorGrid to avoid memory leaks
     if(this.selectorGrid) {
+      if(this.selectorGrid.dataSource &&
+         this.selector.form.destroyItemObjects) {
+        this.selectorGrid.dataSource.destroy();
+        this.selectorGrid.dataSource = null;
+      }
       this.selectorGrid.destroy();
       this.selectorGrid = null;
     }
 
-    if(this.dataSource) {
+    if(this.dataSource && this.selector.form.destroyItemObjects) {
       this.dataSource.destroy();
       this.dataSource = null;
     }
@@ -625,12 +630,13 @@
 
   destroy: function () {
     // Explicitly destroy the selector window to avoid memory leaks
+    if(this.selectorWindow) {
+      this.selectorWindow.destroy();
+      this.selectorWindow = null;
+    }
+
+    // Only destroy the optionDataSource if is allowed by the form
     if(this.form.destroyItemObjects) {
-      if(this.selectorWindow) {
-        this.selectorWindow.destroy();
-        this.selectorWindow = null;
-      }
-
       if(this.optionDataSource) {
         this.optionDataSource.destroy();
         this.optionDataSource = null;
@@ -809,12 +815,13 @@
 
   destroy: function () {
     // Explicitly destroy the selector window to avoid memory leaks
+    if(this.selectorWindow) {
+      this.selectorWindow.destroy();
+      this.selectorWindow = null;
+    }
+
+    // Only destroy the optionDataSource if is allowed by the form
     if(this.form.destroyItemObjects) {
-      if(this.selectorWindow) {
-        this.selectorWindow.destroy();
-        this.selectorWindow = null;
-      }
-
       if(this.optionDataSource) {
         this.optionDataSource.destroy();
         this.optionDataSource = null;