[pi-process-multi-record] processes executed for more than one record
authorNaroa Iriarte <naroa.iriarte@openbravo.com>
Tue, 22 Nov 2016 16:09:12 +0100
changeset 31471 0264118a76fa
parent 31470 26c591b1863d
child 31472 0f4dc3f4ee7e
[pi-process-multi-record] processes executed for more than one record

Now, it is possible to select more than one record and execute a process. Before this fix, even it was possible to select more than one record, the process was only affecting the first selected record. The javascript logic which handles this has been added.
Also, a refresh of the view, in the cases of having multi record processes, has been added.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js	Tue Nov 22 13:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js	Tue Nov 22 16:09:12 2016 +0100
@@ -215,7 +215,7 @@
   handleResponse: function (refreshParent, message, responseActions, retryExecution, data) {
     var window = this.parentWindow,
         tab = OB.MainView.TabSet.getTab(this.viewTabId),
-        i, afterRefreshCallback, me = this;
+        i, selectedRecords, afterRefreshCallback, me = this;
 
     // change title to done
     if (tab) {
@@ -294,7 +294,12 @@
           // In this case we are inside a process called from another process, so we want to refresh the caller process instead of the main window.
           this.callerField.view.onRefreshFunction(this.callerField.view);
         } else {
-          this.buttonOwnerView.refreshCurrentRecord(afterRefreshCallback);
+
+          if (this.button.multiRecord) {
+            this.buttonOwnerView.refresh(afterRefreshCallback);
+          } else {
+            this.buttonOwnerView.refreshCurrentRecord(afterRefreshCallback);
+          }
         }
       }
 
@@ -312,9 +317,21 @@
 
   doProcess: function (btnValue) {
     var i, tmp, view = this,
-        grid, allProperties = this.getUnderLyingRecordContext(false, true, false, true),
-        selection, len, allRows, params, tab, actionHandlerCall, clientSideValidationFail;
-    // activeView = view.parentWindow && view.parentWindow.activeView,  ???.
+        grid, allProperties, selection, len, allRows, params, tab, actionHandlerCall, clientSideValidationFail, selectedRecords, recordIds;
+
+    if (this.button.multiRecord) {
+      selectedRecords = this.buttonOwnerView.viewGrid.getSelectedRecords();
+      recordIds = [];
+      for (i = 0; i < selectedRecords.length; i++) {
+        recordIds.push(selectedRecords.get(i).id);
+      }
+      allProperties = {
+        recordIds: recordIds
+      };
+    } else {
+      allProperties = this.getUnderLyingRecordContext(false, true, false, true);
+    }
+
     if (this.resultLayout && this.resultLayout.destroy) {
       this.resultLayout.destroy();
       delete this.resultLayout;
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js	Tue Nov 22 13:14:49 2016 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js	Tue Nov 22 16:09:12 2016 +0100
@@ -302,7 +302,7 @@
       readonly = false;
       this.visible = true;
       for (i = 0; i < selection.length; i++) {
-        currentValues = selection[i];
+        currentValues = isc.shallowClone(selection[i]);
         OB.Utilities.fixNull250(currentValues);
         this.visible = this.visible && (!this.displayIf || (context && this.displayIf(this.contextView.viewForm, currentValues, context)));
         readonly = readonly || (this.readOnlyIf && context && this.readOnlyIf(this.contextView.viewForm, currentValues, context));