Issue 18763: Initial implementation of Pick and Execute view
authorIván Perdomo <ivan.perdomo@openbravo.com>
Sun, 16 Oct 2011 21:27:37 +0200
changeset 14434 17a4aad9b83c
parent 14433 929d0f650ba1
child 14435 2af01ca7a492
Issue 18763: Initial implementation of Pick and Execute view
modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE.xml
modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-pick-and-execute-view-tab.js.ftl
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-pick-and-execute-view-window.js.ftl
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/StandardWindowComponent.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-view.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE.xml	Sun Oct 16 19:21:28 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE.xml	Sun Oct 16 21:27:37 2011 +0200
@@ -229,4 +229,30 @@
 <!--FF808181317B723B01317B7453E90006-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF808181317B723B01317B7453E90006--></OBCLKER_TEMPLATE>
 
+<!--FF80818132F916130132F9357DE10016--><OBCLKER_TEMPLATE>
+<!--FF80818132F916130132F9357DE10016-->  <OBCLKER_TEMPLATE_ID><![CDATA[FF80818132F916130132F9357DE10016]]></OBCLKER_TEMPLATE_ID>
+<!--FF80818132F916130132F9357DE10016-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80818132F916130132F9357DE10016-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80818132F916130132F9357DE10016-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF80818132F916130132F9357DE10016-->  <NAME><![CDATA[Pick and Execute Window]]></NAME>
+<!--FF80818132F916130132F9357DE10016-->  <DESCRIPTION><![CDATA[Template which creates a Pick and Execute window]]></DESCRIPTION>
+<!--FF80818132F916130132F9357DE10016-->  <TEMPLATECLASSPATHLOCATION><![CDATA[/org/openbravo/client/application/templates/ob-pick-and-execute-view-window.js.ftl]]></TEMPLATECLASSPATHLOCATION>
+<!--FF80818132F916130132F9357DE10016-->  <TEMPLATE_LANGUAGE><![CDATA[OBCLFRE_Freemarker]]></TEMPLATE_LANGUAGE>
+<!--FF80818132F916130132F9357DE10016-->  <COMPONENT_TYPE><![CDATA[OBUIAPP_ViewImplementation]]></COMPONENT_TYPE>
+<!--FF80818132F916130132F9357DE10016-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80818132F916130132F9357DE10016--></OBCLKER_TEMPLATE>
+
+<!--FF808181330BD14F01330BD34EA00008--><OBCLKER_TEMPLATE>
+<!--FF808181330BD14F01330BD34EA00008-->  <OBCLKER_TEMPLATE_ID><![CDATA[FF808181330BD14F01330BD34EA00008]]></OBCLKER_TEMPLATE_ID>
+<!--FF808181330BD14F01330BD34EA00008-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181330BD14F01330BD34EA00008-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181330BD14F01330BD34EA00008-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808181330BD14F01330BD34EA00008-->  <NAME><![CDATA[Pick and Execute Tab]]></NAME>
+<!--FF808181330BD14F01330BD34EA00008-->  <DESCRIPTION><![CDATA[Template which creates a Pick and Execute window]]></DESCRIPTION>
+<!--FF808181330BD14F01330BD34EA00008-->  <TEMPLATECLASSPATHLOCATION><![CDATA[/org/openbravo/client/application/templates/ob-pick-and-execute-view-tab.js.ftl]]></TEMPLATECLASSPATHLOCATION>
+<!--FF808181330BD14F01330BD34EA00008-->  <TEMPLATE_LANGUAGE><![CDATA[OBCLFRE_Freemarker]]></TEMPLATE_LANGUAGE>
+<!--FF808181330BD14F01330BD34EA00008-->  <COMPONENT_TYPE><![CDATA[OBUIAPP_ViewImplementation]]></COMPONENT_TYPE>
+<!--FF808181330BD14F01330BD34EA00008-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181330BD14F01330BD34EA00008--></OBCLKER_TEMPLATE>
+
 </data>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml	Sun Oct 16 19:21:28 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml	Sun Oct 16 21:27:37 2011 +0200
@@ -10,4 +10,14 @@
 <!--FF808181324E2FEC01324E3F2E620015-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF808181324E2FEC01324E3F2E620015--></OBCLKER_TEMPLATE_DEPENDENCY>
 
+<!--FF808181330C335401330C34B729000B--><OBCLKER_TEMPLATE_DEPENDENCY>
+<!--FF808181330C335401330C34B729000B-->  <OBCLKER_TEMPLATE_DEPENDENCY_ID><![CDATA[FF808181330C335401330C34B729000B]]></OBCLKER_TEMPLATE_DEPENDENCY_ID>
+<!--FF808181330C335401330C34B729000B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181330C335401330C34B729000B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181330C335401330C34B729000B-->  <OBCLKER_TEMPLATE_ID><![CDATA[FF808181330BD14F01330BD34EA00008]]></OBCLKER_TEMPLATE_ID>
+<!--FF808181330C335401330C34B729000B-->  <DEPENDSON_TEMPLATE_ID><![CDATA[33E04D0799794C6F95F05149D2E04E78]]></DEPENDSON_TEMPLATE_ID>
+<!--FF808181330C335401330C34B729000B-->  <DESCRIPTION><![CDATA[Field Template]]></DESCRIPTION>
+<!--FF808181330C335401330C34B729000B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181330C335401330C34B729000B--></OBCLKER_TEMPLATE_DEPENDENCY>
+
 </data>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java	Sun Oct 16 19:21:28 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java	Sun Oct 16 21:27:37 2011 +0200
@@ -253,6 +253,12 @@
             "web/org.openbravo.client.application/js/personalization/ob-manage-views-toolbar.js",
             false));
 
+    // Process
+    globalResources.add(createStaticResource(
+        "web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js", false));
+    globalResources.add(createStaticResource(
+        "web/org.openbravo.client.application/js/process/ob-pick-and-execute-view.js", false));
+
     // Styling
     globalResources.add(createStyleSheetResource(
         "web/org.openbravo.userinterface.smartclient/openbravo/skins/"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-pick-and-execute-view-tab.js.ftl	Sun Oct 16 21:27:37 2011 +0200
@@ -0,0 +1,75 @@
+<#--
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+*/
+-->
+<@createView data/>      
+
+<#macro createView tabComponent>    
+    tabTitle: '${tabComponent.tabTitle?js_string}',
+    entity:  '${tabComponent.entityName}',
+    
+    <#if tabComponent.parentProperty != ''>
+        parentProperty: '${tabComponent.parentProperty?js_string}',
+    </#if>
+    <#if tabComponent.tabSet>
+        tabId: '${tabComponent.tabId}',
+        moduleId: '${tabComponent.moduleId}',
+    </#if>
+    
+    <#if tabComponent.defaultEditMode>
+    defaultEditMode: ${tabComponent.defaultEditMode?string},
+    </#if> 
+    mapping250: '${tabComponent.mapping250?js_string}',
+    <#if tabComponent.acctTab>
+    isAcctTab: ${tabComponent.acctTab?string},
+    </#if> 
+    <#if tabComponent.trlTab>
+    isTrlTab: ${tabComponent.trlTab?string},
+    </#if> 
+    
+    standardProperties:{
+<@compress single_line=true>
+      inpTabId: '${tabComponent.tabId}',
+      inpwindowId: '${tabComponent.windowId}',
+      inpTableId: '${tabComponent.tableId?js_string}',
+      inpkeyColumnId: '${tabComponent.keyProperty.columnId?js_string}',
+      keyProperty: '${tabComponent.keyProperty.name?js_string}',
+      inpKeyName: '${tabComponent.keyInpName?js_string}',
+      keyColumnName: '${tabComponent.keyColumnName?js_string}',
+      keyPropertyType: '${tabComponent.keyPropertyType?js_string}'      
+</@compress>
+    },
+
+
+    fields: [
+    <#list tabComponent.fieldHandler.fields as field>
+      <@createField field/><#if field_has_next>,</#if>
+    </#list>    
+    ],
+    
+    statusBarFields: [
+<@compress single_line=true>
+    <#list tabComponent.fieldHandler.statusBarFields as sbf>
+      '${sbf?js_string}'<#if sbf_has_next>,</#if>
+    </#list>
+</@compress>
+    ],
+ 
+    dataSource: ${tabComponent.dataSourceJavaScript}
+</#macro>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-pick-and-execute-view-window.js.ftl	Sun Oct 16 21:27:37 2011 +0200
@@ -0,0 +1,32 @@
+<#--
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+*/
+-->
+
+/*jslint*/
+OB.Layout.ViewManager.loadedWindowClassName = '${data.windowClientClassName?js_string}';
+
+isc.ClassFactory.defineClass('${data.windowClientClassName?js_string}', isc.OBPickAndExecuteView).addProperties({
+    windowId: '${data.windowId?js_string}',
+    viewProperties: {
+      windowId: '${data.windowId?js_string}', 
+      ${data.tabView}
+    }
+});
+
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Sun Oct 16 19:21:28 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Sun Oct 16 21:27:37 2011 +0200
@@ -63,7 +63,13 @@
  */
 public class OBViewTab extends BaseTemplateComponent {
 
-  private static final String TEMPLATE_ID = "B5124C0A450D4D3A867AEAC7DF64D6F0";
+  private static final String DEFAULT_TEMPLATE_ID = "B5124C0A450D4D3A867AEAC7DF64D6F0";
+  protected static final Map<String, String> TEMPLATE_MAP = new HashMap<String, String>();
+
+  static {
+    // Map: WindowType - Template
+    TEMPLATE_MAP.put("OBUIAPP_PickAndExecute", "FF808181330BD14F01330BD34EA00008");
+  }
 
   private Entity entity;
   private Tab tab;
@@ -81,20 +87,28 @@
 
   @Inject
   @ComponentProvider.Qualifier(DataSourceConstants.DS_COMPONENT_TYPE)
-  private ComponentProvider componentProvider;
+  private ComponentProvider dsComponentProvider;
 
   public String getDataSourceJavaScript() {
     final String dsId = getDataSourceId();
     final Map<String, Object> dsParameters = new HashMap<String, Object>(getParameters());
     dsParameters.put(DataSourceConstants.DS_ONLY_GENERATE_CREATESTATEMENT, true);
-    dsParameters.put(DataSourceConstants.DS_CLASS_NAME, "OBViewDataSource");
+    if ("OBUIAPP_PickAndExecute".equals(tab.getWindow().getWindowType())) {
+      dsParameters.put(DataSourceConstants.DS_CLASS_NAME, "OBRestDataSource");
+    } else {
+      dsParameters.put(DataSourceConstants.DS_CLASS_NAME, "OBViewDataSource");
+    }
     dsParameters.put(DataSourceConstants.MINIMAL_PROPERTY_OUTPUT, true);
-    final Component component = componentProvider.getComponent(dsId, dsParameters);
+    final Component component = dsComponentProvider.getComponent(dsId, dsParameters);
     return component.generate();
   }
 
   protected Template getComponentTemplate() {
-    return OBDal.getInstance().get(Template.class, TEMPLATE_ID);
+    final String windowType = tab.getWindow().getWindowType();
+    if (TEMPLATE_MAP.containsKey(windowType)) {
+      return OBDal.getInstance().get(Template.class, TEMPLATE_MAP.get(windowType));
+    }
+    return OBDal.getInstance().get(Template.class, DEFAULT_TEMPLATE_ID);
   }
 
   public OBViewFieldHandler getFieldHandler() {
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/StandardWindowComponent.java	Sun Oct 16 19:21:28 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/StandardWindowComponent.java	Sun Oct 16 21:27:37 2011 +0200
@@ -19,7 +19,9 @@
 package org.openbravo.client.application.window;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.openbravo.client.kernel.BaseTemplateComponent;
@@ -39,8 +41,13 @@
  */
 public class StandardWindowComponent extends BaseTemplateComponent {
   private static final Logger log = Logger.getLogger(StandardWindowComponent.class);
+  private static final String DEFAULT_TEMPLATE_ID = "ADD5EF45333C458098286D0E639B3290";
 
-  private static final String TEMPLATE_ID = "ADD5EF45333C458098286D0E639B3290";
+  protected static final Map<String, String> TEMPLATE_MAP = new HashMap<String, String>();
+  static {
+    // WindowType - Template
+    TEMPLATE_MAP.put("OBUIAPP_PickAndExecute", "FF80818132F916130132F9357DE10016");
+  }
 
   private Window window;
   private OBViewTab rootTabComponent = null;
@@ -48,7 +55,10 @@
   private String uniqueString = "" + System.currentTimeMillis();
 
   protected Template getComponentTemplate() {
-    return OBDal.getInstance().get(Template.class, TEMPLATE_ID);
+    if (TEMPLATE_MAP.containsKey(window.getWindowType())) {
+      return OBDal.getInstance().get(Template.class, TEMPLATE_MAP.get(window.getWindowType()));
+    }
+    return OBDal.getInstance().get(Template.class, DEFAULT_TEMPLATE_ID);
   }
 
   public String getWindowClientClassName() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Sun Oct 16 21:27:37 2011 +0200
@@ -0,0 +1,43 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distribfuted  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+isc.defineClass('OBPickAndExecuteGrid', isc.OBGrid);
+
+isc.OBPickAndExecuteGrid.addProperties({
+  dataProperties: {
+    useClientFiltering: false,
+    useClientSorting: false
+  },
+  view: null,
+  dataSource: null,
+  showFilterEditor: true,
+
+  // Editing
+  canEdit: true,
+  editEvent: 'click',
+  autoSaveEdits: false,
+
+  selectionAppearance: 'checkbox',
+  autoFitFieldWidths: true,
+  autoFitWidthApproach: 'title',
+  canAutoFitFields: false,
+  minFieldWidth: 75,
+  width: '100%',
+  height: '100%'
+});
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-view.js	Sun Oct 16 21:27:37 2011 +0200
@@ -0,0 +1,101 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distribfuted  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+isc.defineClass('OBPickAndExecuteView', isc.OBPopup);
+
+
+isc.OBPickAndExecuteView.addProperties({
+
+  // Override default properties of OBPopup
+  canDragReposition: false,
+  canDragResize: false,
+  isModal: false,
+  showModalMask: false,
+  dismissOnEscape: false,
+  showMinimizeButton: false,
+  showMaximizeButton: false,
+  showFooter: false,
+
+  width: '100%',
+  overflow: 'auto',
+
+  dataSource: null,
+
+  viewGrid: null,
+
+  gridFields: null,
+
+  initWidget: function () {
+
+    var view = this,
+        okButton = isc.OBFormButton.create({
+        title: OB.I18N.getLabel('OBUISC_Dialog.OK_BUTTON_TITLE'),
+        click: function () {
+          console.log(view.viewGrid.getSelectedRecords());
+        }
+      }),
+        cancelButton = isc.OBFormButton.create({
+        title: OB.I18N.getLabel('OBUISC_Dialog.CANCEL_BUTTON_TITLE'),
+        click: function () {
+          view.viewGrid.discardAllEdits();
+        }
+      });
+
+    this.prepareGridFields(this.viewProperties.fields);
+
+    this.dataSource = this.viewProperties.dataSource;
+    this.dataSource.view = this;
+
+    this.viewGrid = isc.OBPickAndExecuteGrid.create({
+      view: this,
+      sortField: 'lineNo',
+      fields: this.gridFields,
+      // FIXME: using fixed size
+      height: 300,
+      dataSource: this.dataSource
+    });
+
+    this.items = [this.viewGrid, isc.HLayout.create({
+      styleName: this.buttonBarStyleName,
+      height: this.buttonBarHeight,
+      defaultLayoutAlign: 'center',
+      members: [isc.LayoutSpacer.create({}), okButton, isc.LayoutSpacer.create({
+        width: this.buttonBarSpace
+      }), cancelButton, isc.LayoutSpacer.create({})]
+    })];
+
+    this.Super('initWidget', arguments);
+    this.viewGrid.fetchData();
+  },
+
+  prepareGridFields: function (fields) {
+    //FIXME: using fixed $b4 reference
+    var result = isc.OBStandardView.$b4.prepareGridFields.apply(this, arguments),
+        i, f, len = result.length;
+    for (i = 0; i < len; i++) {
+      if (result[i].disabled) {
+        result[i].canEdit = false;
+      }
+    }
+    this.gridFields = result;
+  },
+
+  // dummy required by OBStandardView.prepareGridFields
+  setFieldFormProperties: function () {}
+});
\ No newline at end of file