[process] Allow multi record process
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 16 Apr 2012 10:49:35 +0200
changeset 16370 6c05db2b64ec
parent 16369 088593c08cfa
child 16371 347e89ea1689
[process] Allow multi record process

Multi record allows to execute process definition for more than one selected
records.
modules/org.openbravo.client.application/src-db/database/model/tables/OBUIAPP_PROCESS.xml
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_COLUMN.xml
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_ELEMENT.xml
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_FIELD.xml
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js
--- a/modules/org.openbravo.client.application/src-db/database/model/tables/OBUIAPP_PROCESS.xml	Mon Apr 16 10:00:50 2012 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/model/tables/OBUIAPP_PROCESS.xml	Mon Apr 16 10:49:35 2012 +0200
@@ -69,6 +69,10 @@
         <default><![CDATA[S]]></default>
         <onCreateDefault/>
       </column>
+      <column name="ISMULTIRECORD" primaryKey="false" required="true" type="CHAR" size="1" autoIncrement="false">
+        <default><![CDATA[N]]></default>
+        <onCreateDefault><![CDATA['N']]></onCreateDefault>
+      </column>
       <foreign-key foreignTable="AD_CLIENT" name="OBUIAPP_PROC_AD_CLIENT">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
@@ -80,5 +84,6 @@
       </foreign-key>
       <check name="OBUIAPP_PROC_ISACTIVE_CHK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check>
       <check name="OBUIAPP_PROC_ISBACKGROUND_CHK"><![CDATA[ISBACKGROUND IN ('Y', 'N')]]></check>
+      <check name="OBUIAPP_PROC_MULTI_CHK"><![CDATA[ISMULTIRECORD IN ('Y', 'N')]]></check>
     </table>
   </database>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_COLUMN.xml	Mon Apr 16 10:00:50 2012 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_COLUMN.xml	Mon Apr 16 10:49:35 2012 +0200
@@ -320,6 +320,42 @@
 <!--0BE1E79B283540A1A9CDDACF3CD969BE-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--0BE1E79B283540A1A9CDDACF3CD969BE--></AD_COLUMN>
 
+<!--0E78BBBD0F814831A4E5837C677666FD--><AD_COLUMN>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <AD_COLUMN_ID><![CDATA[0E78BBBD0F814831A4E5837C677666FD]]></AD_COLUMN_ID>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <NAME><![CDATA[IsMultiRecord]]></NAME>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <DESCRIPTION><![CDATA[Allow execution on multiple records at the same time]]></DESCRIPTION>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <HELP><![CDATA[Multi Record allows to execute the process in multiple records at the same time. When this flag is set, multiple records can be selected in grid mode and the process can be executed in all of them at the same time.]]></HELP>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <COLUMNNAME><![CDATA[IsMultiRecord]]></COLUMNNAME>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <AD_TABLE_ID><![CDATA[FF80818132D7FB620132D8129D1A0028]]></AD_TABLE_ID>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <SEQNO><![CDATA[180]]></SEQNO>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <AD_ELEMENT_ID><![CDATA[4813809446914A86B03E9211DEA0A0E5]]></AD_ELEMENT_ID>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <POSITION><![CDATA[18]]></POSITION>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--0E78BBBD0F814831A4E5837C677666FD-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--0E78BBBD0F814831A4E5837C677666FD--></AD_COLUMN>
+
 <!--0FF70EF0FE8142BFB6F980CF54DFF184--><AD_COLUMN>
 <!--0FF70EF0FE8142BFB6F980CF54DFF184-->  <AD_COLUMN_ID><![CDATA[0FF70EF0FE8142BFB6F980CF54DFF184]]></AD_COLUMN_ID>
 <!--0FF70EF0FE8142BFB6F980CF54DFF184-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_ELEMENT.xml	Mon Apr 16 10:00:50 2012 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_ELEMENT.xml	Mon Apr 16 10:49:35 2012 +0200
@@ -68,6 +68,20 @@
 <!--41A5FEDD70F140BF8438B8C8FA03B876-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--41A5FEDD70F140BF8438B8C8FA03B876--></AD_ELEMENT>
 
+<!--4813809446914A86B03E9211DEA0A0E5--><AD_ELEMENT>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <AD_ELEMENT_ID><![CDATA[4813809446914A86B03E9211DEA0A0E5]]></AD_ELEMENT_ID>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <COLUMNNAME><![CDATA[IsMultiRecord]]></COLUMNNAME>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <NAME><![CDATA[Multi Record]]></NAME>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <PRINTNAME><![CDATA[Multi Record]]></PRINTNAME>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <DESCRIPTION><![CDATA[Allow execution on multiple records at the same time]]></DESCRIPTION>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <HELP><![CDATA[Multi Record allows to execute the process in multiple records at the same time. When this flag is set, multiple records can be selected in grid mode and the process can be executed in all of them at the same time.]]></HELP>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--4813809446914A86B03E9211DEA0A0E5-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--4813809446914A86B03E9211DEA0A0E5--></AD_ELEMENT>
+
 <!--4B3999F4700C4C93ABEA49C89A8E484E--><AD_ELEMENT>
 <!--4B3999F4700C4C93ABEA49C89A8E484E-->  <AD_ELEMENT_ID><![CDATA[4B3999F4700C4C93ABEA49C89A8E484E]]></AD_ELEMENT_ID>
 <!--4B3999F4700C4C93ABEA49C89A8E484E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_FIELD.xml	Mon Apr 16 10:00:50 2012 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_FIELD.xml	Mon Apr 16 10:49:35 2012 +0200
@@ -3298,6 +3298,34 @@
 <!--F9C02B45EC1544F0B4EA67504E5929C0-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--F9C02B45EC1544F0B4EA67504E5929C0--></AD_FIELD>
 
+<!--FCD55C499D894E95B322C17919EAB3E4--><AD_FIELD>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <AD_FIELD_ID><![CDATA[FCD55C499D894E95B322C17919EAB3E4]]></AD_FIELD_ID>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <NAME><![CDATA[Multi Record]]></NAME>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <DESCRIPTION><![CDATA[Allow execution on multiple records at the same time]]></DESCRIPTION>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <HELP><![CDATA[Multi Record allows to execute the process in multiple records at the same time. When this flag is set, multiple records can be selected in grid mode and the process can be executed in all of them at the same time.]]></HELP>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <AD_TAB_ID><![CDATA[FF80818132D7FB620132D819C1720046]]></AD_TAB_ID>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <AD_COLUMN_ID><![CDATA[0E78BBBD0F814831A4E5837C677666FD]]></AD_COLUMN_ID>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <DISPLAYLOGIC><![CDATA[@Uipattern@='M']]></DISPLAYLOGIC>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <SEQNO><![CDATA[130]]></SEQNO>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--FCD55C499D894E95B322C17919EAB3E4-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--FCD55C499D894E95B322C17919EAB3E4--></AD_FIELD>
+
 <!--FEFA683DB9F742689C59285E583DA644--><AD_FIELD>
 <!--FEFA683DB9F742689C59285E583DA644-->  <AD_FIELD_ID><![CDATA[FEFA683DB9F742689C59285E583DA644]]></AD_FIELD_ID>
 <!--FEFA683DB9F742689C59285E583DA644-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl	Mon Apr 16 10:00:50 2012 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl	Mon Apr 16 10:49:35 2012 +0200
@@ -67,8 +67,9 @@
        command: '${field.command?js_string}',
        property: '${field.propertyName?js_string}',
        processId: '${field.processId?js_string}',
-       <#if field.newDefinition>newDefinition: ${field.newDefinition?string}, 
-       uiPattern: '${field.uiPattern?js_string}',</#if>
+       <#if field.newDefinition>newDefinition: ${field.newDefinition?string},
+       uiPattern: '${field.uiPattern?js_string}',
+       multiRecord: ${field.multiRecord?string},</#if>
        <#if field.windowId != "">windowId: '${field.windowId?js_string}',</#if>
        <#if field.windowTitle != "">windowTitle: '${field.windowTitle?js_string}',</#if>
        <#if !field.modal>modal: ${field.modal?string},</#if>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Mon Apr 16 10:00:50 2012 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Mon Apr 16 10:49:35 2012 +0200
@@ -515,6 +515,7 @@
     private String windowTitle = "";
     private boolean newDefinition = false;
     private String uiPattern = "";
+    private boolean multiRecord = false;
 
     public ButtonField(Field fld) {
       id = fld.getId();
@@ -535,6 +536,7 @@
         command = newProcess.getJavaClassName();
         newDefinition = true;
         uiPattern = newProcess.getUIPattern();
+        multiRecord = newProcess.isMultiRecord();
 
         if ("OBUIAPP_PickAndExecute".equals(uiPattern)) {
           // TODO: modal should be a parameter in the process definition?
@@ -710,6 +712,10 @@
       return uiPattern;
     }
 
+    public boolean isMultiRecord() {
+      return multiRecord;
+    }
+
     public void setNewDefinition(boolean newDefinition) {
       this.newDefinition = newDefinition;
     }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js	Mon Apr 16 10:00:50 2012 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-action-button.js	Mon Apr 16 10:49:35 2012 +0200
@@ -216,17 +216,58 @@
     // do not hide non autosave buttons when hidding the rest if keepNonAutosave === true
     var hideButton = hide && (!keepNonAutosave || this.autosave);
 
+    var multiSelect = false,
+        readonly, i, selection;
+
     if (hideButton || !record) {
-      this.hide();
-      return;
+      multiSelect = this.multiRecord && this.contextView.viewGrid.getSelectedRecords().length > 1;
+      if (!multiSelect) {
+        this.hide();
+        return;
+      }
     }
 
     context = context || this.contextView.getContextInfo(false, true, true);
 
 
-    OB.Utilities.fixNull250(currentValues);
+    if (!multiSelect) {
+      OB.Utilities.fixNull250(currentValues);
 
-    this.visible = !this.displayIf || (context && this.displayIf(this.contextView.viewForm, record, context));
+      this.visible = !this.displayIf || (context && this.displayIf(this.contextView.viewForm, record, context));
+      readonly = this.readOnlyIf && context && this.readOnlyIf(this.contextView.viewForm, record, context);
+
+      var buttonValue = record[this.property];
+      if (buttonValue === '--') {
+        buttonValue = 'CL';
+      }
+
+      // Changing button name associated with a list is not allowed in multi record buttons.
+      var label = this.labelValue[buttonValue];
+      if (!label) {
+        if (this.realTitle) {
+          label = this.realTitle;
+        } else {
+          label = this.title;
+        }
+      }
+      this.realTitle = label;
+      this.setTitle(label);
+
+    } else {
+      // For multi selection processes:
+      //   -Button is displayed in case it should be displayed in ALL selected records
+      //   -Button is readonly in case it should be readonly in ALL sected records
+      selection = this.contextView.viewGrid.getSelectedRecords();
+      readonly = false;
+      this.visible = true;
+      for (i = 0; i < selection.length; i++) {
+        currentValues = 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));
+      }
+
+    }
 
     // Even visible is correctly set, it is necessary to execute show() or hide()
     if (this.visible) {
@@ -234,28 +275,12 @@
     } else {
       this.hide();
     }
-
-    var readonly = this.readOnlyIf && context && this.readOnlyIf(this.contextView.viewForm, record, context);
     if (readonly) {
       this.disable();
     } else {
       this.enable();
     }
 
-    var buttonValue = record[this.property];
-    if (buttonValue === '--') {
-      buttonValue = 'CL';
-    }
 
-    var label = this.labelValue[buttonValue];
-    if (!label) {
-      if (this.realTitle) {
-        label = this.realTitle;
-      } else {
-        label = this.title;
-      }
-    }
-    this.realTitle = label;
-    this.setTitle(label);
   }
 });
\ No newline at end of file