Fixed issue 29867: Now grid multiple selection is not lost on refresh
authorDavid Baz Fayos <david.baz@openbravo.com>
Thu, 28 May 2015 19:51:06 +0200
changeset 26795 4f48ce65dacf
parent 26794 aed0c66779e9
child 26797 2971dc0bd036
Fixed issue 29867: Now grid multiple selection is not lost on refresh

If the selected items are in different pages, only the items belonging to the land
page once the grid get refreshed will be shown. A message notifying this loss will
be shown (in the message bar if this is empty or as a popup if there is a message
already been displayed, to avoid loss its information if we come from a process
execution)
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Thu May 28 12:58:25 2015 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Thu May 28 19:51:06 2015 +0200
@@ -1605,6 +1605,18 @@
 <!--CE3E9A8711D54E719F02630BE8D5E2FB-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--CE3E9A8711D54E719F02630BE8D5E2FB--></AD_MESSAGE>
 
+<!--CEA329C437C54C7AB101D4A3EC0A89EC--><AD_MESSAGE>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <AD_MESSAGE_ID><![CDATA[CEA329C437C54C7AB101D4A3EC0A89EC]]></AD_MESSAGE_ID>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <VALUE><![CDATA[OBUIAPP_NumOfSeledtedItemsChange]]></VALUE>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <MSGTEXT><![CDATA[There were %0 records selected prior to refreshing. Due to limitations regarding the page size, only the  first %1 record(s) selection has been kept.]]></MSGTEXT>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <MSGTYPE><![CDATA[W]]></MSGTYPE>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--CEA329C437C54C7AB101D4A3EC0A89EC--></AD_MESSAGE>
+
 <!--CF668C49E43D4FA799A43191EA10C17A--><AD_MESSAGE>
 <!--CF668C49E43D4FA799A43191EA10C17A-->  <AD_MESSAGE_ID><![CDATA[CF668C49E43D4FA799A43191EA10C17A]]></AD_MESSAGE_ID>
 <!--CF668C49E43D4FA799A43191EA10C17A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Thu May 28 12:58:25 2015 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Thu May 28 19:51:06 2015 +0200
@@ -1785,6 +1785,12 @@
         this.selectedRecordEndInterval = this.selectedRecordInitInterval + this.data.resultSize;
       }
       this.notRemoveFilter = true;
+      if (this.getSelectedRecords().length > 1) {
+        this.selectedRecordsBeforeRefresh = [];
+        for (i = 0; i < this.getSelectedRecords().length; i++) {
+          this.selectedRecordsBeforeRefresh.push(this.getSelectedRecords()[i][OB.Constants.ID]);
+        }
+      }
     } else {
       visibleRows = this.getVisibleRows();
       if (visibleRows && visibleRows[0] > 0) {
@@ -1833,6 +1839,7 @@
       criteria = originalCriteria;
     }
     filterDataCallback = function () {
+      var i, gridRecord, recordIndexes = [];
       if (me.refreshingWithScrolledGrid) {
         // move the scroll to part of the grid that contains the data that was just received to
         // prevent unneded requests (see https://issues.openbravo.com/view.php?id=25811)
@@ -1846,6 +1853,24 @@
       delete me.selectedRecordInitInterval;
       delete me.selectedRecordEndInterval;
       delete me.selectedRecordId;
+
+      if (me.selectedRecordsBeforeRefresh) {
+        for (i = 0; i < me.selectedRecordsBeforeRefresh.length; i++) {
+          gridRecord = me.data.find(OB.Constants.ID, me.selectedRecordsBeforeRefresh[i]);
+          if (gridRecord !== null) {
+            recordIndexes.push(me.getRecordIndex(gridRecord));
+          }
+        }
+        me.selectRecords(recordIndexes);
+        if (me.selectedRecordsBeforeRefresh.length !== recordIndexes.length) {
+          if (me.view.messageBar.isVisible()) {
+            isc.warn(OB.I18N.getLabel('OBUIAPP_NumOfSeledtedItemsChange', [me.selectedRecordsBeforeRefresh.length, recordIndexes.length]));
+          } else {
+            me.view.messageBar.setMessage(isc.OBMessageBar.TYPE_WARNING, null, OB.I18N.getLabel('OBUIAPP_NumOfSeledtedItemsChange', [me.selectedRecordsBeforeRefresh.length, recordIndexes.length]));
+          }
+        }
+        delete me.selectedRecordsBeforeRefresh;
+      }
     };
     this.filterData(criteria, filterDataCallback, context);
     // Set the refreshingWithRecordSelected and refreshingWithScrolledGrid flags to true when needed after