Issue 18227: dataSource/optionDataSource is now destroyed on form/grid destroy
authorIván Perdomo <ivan.perdomo@openbravo.com>
Fri, 26 Aug 2011 15:02:36 +0200
changeset 13606 cff2f670c700
parent 13605 3823c5ec27a4
child 13608 882b86f4810f
Issue 18227: dataSource/optionDataSource is now destroyed on form/grid destroy
The destroy methos of OBViewGrid and OBViewForm takes care of destroying the
datasources associated to items/fields
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-linked-items.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.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/form/ob-view-form-linked-items.js	Fri Aug 26 15:00:34 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-linked-items.js	Fri Aug 26 15:02:36 2011 +0200
@@ -315,7 +315,6 @@
     hLayout.addMember(this.linkedItemListGrid);
     
     this.messageLabel = isc.Label.create({
-      ID: 'messageLabel',
       width: '100%',
       height: '100%',
       canFocus: true
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Fri Aug 26 15:00:34 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Fri Aug 26 15:02:36 2011 +0200
@@ -1535,6 +1535,33 @@
     
     delete this.storedFocusItem;
     delete this.storedSelectionRange;    
+  },
+
+  destroy: function () {
+    var i, items = this.getItems(), len = items.length, ds, dataSources = [];
+
+    // caching reference to all DS of Items
+    for (i = 0; i < len; i++) {
+      item = items[i];
+      ds = items && (item.dataSource || item.optionDataSource);
+
+      if(ds) {
+        dataSources.push(ds);
+      }
+    }
+
+    this.Super('destroy', arguments);
+
+    len = dataSources.length;
+
+    // Destroying DS not managed by DynamicForm.destroy
+    for(i = 0; i < len; i++) {
+      ds = dataSources[i];
+      if(ds) {
+        ds.destroy();
+        ds = null;
+      }
+    }
   }
 };
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Fri Aug 26 15:00:34 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Fri Aug 26 15:02:36 2011 +0200
@@ -221,7 +221,7 @@
     }
   },
 
-  initWidget: function(){
+  initWidget: function () {
     var i;
     
     // make a copy of the dataProperties otherwise we get 
@@ -290,19 +290,41 @@
     '\'].clearFilter();" class="OBLinkButtonItem">' +
     OB.I18N.getLabel('OBUIAPP_GridClearFilter') +
     '</span>';
-    
+
     return ret;
   },
 
   // destroy the context menu also
   // see why this needs to be done in the 
   // documentation of canvas.contextMenu in Canvas.js
-  destroy: function() {
+  destroy: function () {
+    var i, field, fields = this.getFields(), len = fields.length, ds, dataSources = [];
+
+    for(i = 0; i < len; i++) {
+      field = fields[i];
+      editorProperties = field && field.editorProperties;
+      ds = editorProperties && editorProperties.optionDataSource;
+      if(ds) {
+        dataSources.push(ds);
+      }
+    }
+
     if (this.contextMenu) {
       this.contextMenu.destroy();
       this.contextMenu = null;
     }
+
     this.Super('destroy', arguments);
+
+    len = dataSources.length;
+
+    for(i = 0; i < len; i++) {
+      ds = dataSources[i];
+      if(ds) {
+        ds.destroy();
+        ds = null;
+      }
+    }
   },
   
   setData: function(data) {