Fixes bug 29172: Improved performance select/deselect all records in OrderInv grid
authorUnai Martirena <unai.martirena@openbravo.com>
Mon, 09 Mar 2015 18:58:14 +0100
changeset 26172 ba035397bf8a
parent 26171 ed4452a6ac7d
child 26173 6f599d5217c4
child 26174 5c3aeebd4d49
Fixes bug 29172: Improved performance select/deselect all records in OrderInv grid

The problem was that on every selection/deselection of a record in Order Invoices grid it was triggering the execution of these three methods: 'OB.APRM.AddPayment.updateInvOrderTotal(view.theForm, orderInvoice), OB.APRM.AddPayment.updateActualExpected(view.theForm), OB.APRM.AddPayment.updateDifference(view.theForm)'.
Actually it is not necessary to execute these functions on every record, because in the end they are updating total values, so just executing them after the iteration of the last record selected/deselected it would be enough.
To implement this, 'userSelectAllRecords' and 'deselectAllRecords' ListGrid methods have been overriden, to set a flag to true, in order to know when a record is changed while clicking selected/deselect all records, and in this case the three methods will be executed in the last record of the grid.
The 'OB.APRM.AddPayment.userSelectAllRecords' is executed only when clicking in select all records checkbox, but 'OB.APRM.AddPayment.deselectAllRecords' is executed while unchecking the previous checkbox and when fetching data in the grid using 'invalidateCache()' method. In this last case these functions will not be executed on every deselection neither in the last record, because they are already invoked directly in 'invalidateCache()', so in this case they will be avoided.
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Thu Mar 12 16:09:45 2015 +0000
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Mon Mar 09 18:58:14 2015 +0100
@@ -122,6 +122,8 @@
   glitemGrid.fetchData();
   creditUseGrid.fetchData();
   orderInvoiceGrid.selectionChanged = OB.APRM.AddPayment.selectionChanged;
+  orderInvoiceGrid.userSelectAllRecords = OB.APRM.AddPayment.userSelectAllRecords;
+  orderInvoiceGrid.deselectAllRecords = OB.APRM.AddPayment.deselectAllRecords;
   orderInvoiceGrid.dataProperties.transformData = OB.APRM.AddPayment.ordInvTransformData;
   glitemGrid.removeRecordClick = OB.APRM.AddPayment.removeRecordClick;
   creditUseGrid.selectionChanged = OB.APRM.AddPayment.selectionChangedCredit;
@@ -594,11 +596,28 @@
       }
     }
   }
-  OB.APRM.AddPayment.updateInvOrderTotal(view.theForm, orderInvoice);
-  OB.APRM.AddPayment.updateActualExpected(view.theForm);
-  OB.APRM.AddPayment.updateDifference(view.theForm);
+  if (!orderInvoice.obaprmAllRecordsSelectedByUser || (orderInvoice.obaprmAllRecordsSelectedByUser && (orderInvoice.getRecordIndex(record) === orderInvoice.getTotalRows() - 1))) {
+
+    OB.APRM.AddPayment.updateInvOrderTotal(view.theForm, orderInvoice);
+    OB.APRM.AddPayment.updateActualExpected(view.theForm);
+    OB.APRM.AddPayment.updateDifference(view.theForm);
+    if (orderInvoice.obaprmAllRecordsSelectedByUser) {
+      delete orderInvoice.obaprmAllRecordsSelectedByUser;
+    }
+  }
 };
 
+OB.APRM.AddPayment.userSelectAllRecords = function () {
+  this.obaprmAllRecordsSelectedByUser = true;
+  this.Super('userSelectAllRecords', arguments);
+};
+
+OB.APRM.AddPayment.deselectAllRecords = function () {
+  this.obaprmAllRecordsSelectedByUser = true;
+  this.Super('deselectAllRecords', arguments);
+};
+
+
 OB.APRM.AddPayment.updateActualExpected = function (form) {
   var orderInvoice = form.getItem('order_invoice').canvas.viewGrid,
       issotrx = form.getItem('issotrx').getValue(),