[alfresco] Implement attach popup using freemaker and obuiapp parameters
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Tue, 26 May 2015 12:11:22 +0200
changeset 29094 358c6c277135
parent 29093 a3f95e60b4f7
child 29095 23ab666ae289
[alfresco] Implement attach popup using freemaker and obuiapp parameters

Create a new utils class to retrieve attachment method, config and metadata
parameters.
Several fixes on templates and classes to properly load the attachment popup.
modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml
modules/org.openbravo.client.application/src/org/openbravo/client/application/ViewComponent.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-attachment-view.js.ftl
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachImplementationManager.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentUtils.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentWindowComponent.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentsAH.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/CoreAttachImplementation.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewParameterHandler.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ParameterWindowComponent.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-attachment-window-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-base-parameter-window-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js
modules/org.openbravo.integration.alfresco
src/org/openbravo/erpCommon/businessUtility/TabAttachments.java
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml	Tue May 26 12:11:22 2015 +0200
@@ -1,5 +1,14 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <data>
+<!--6E017DB328FA43D28B26FD2570546AE8--><OBCLKER_TEMPLATE_DEPENDENCY>
+<!--6E017DB328FA43D28B26FD2570546AE8-->  <OBCLKER_TEMPLATE_DEPENDENCY_ID><![CDATA[6E017DB328FA43D28B26FD2570546AE8]]></OBCLKER_TEMPLATE_DEPENDENCY_ID>
+<!--6E017DB328FA43D28B26FD2570546AE8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--6E017DB328FA43D28B26FD2570546AE8-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--6E017DB328FA43D28B26FD2570546AE8-->  <OBCLKER_TEMPLATE_ID><![CDATA[01E447F740584E02BA4612F6BDFB900D]]></OBCLKER_TEMPLATE_ID>
+<!--6E017DB328FA43D28B26FD2570546AE8-->  <DEPENDSON_TEMPLATE_ID><![CDATA[05E5CD50EDE14457BCAC218A77837D1E]]></DEPENDSON_TEMPLATE_ID>
+<!--6E017DB328FA43D28B26FD2570546AE8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--6E017DB328FA43D28B26FD2570546AE8--></OBCLKER_TEMPLATE_DEPENDENCY>
+
 <!--F62202D72A8A4C5FABECAF2ED640609E--><OBCLKER_TEMPLATE_DEPENDENCY>
 <!--F62202D72A8A4C5FABECAF2ED640609E-->  <OBCLKER_TEMPLATE_DEPENDENCY_ID><![CDATA[F62202D72A8A4C5FABECAF2ED640609E]]></OBCLKER_TEMPLATE_DEPENDENCY_ID>
 <!--F62202D72A8A4C5FABECAF2ED640609E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ViewComponent.java	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ViewComponent.java	Tue May 26 12:11:22 2015 +0200
@@ -25,6 +25,7 @@
 import javax.inject.Inject;
 
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang.StringUtils;
 import org.hibernate.Query;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.exception.OBException;
@@ -92,6 +93,13 @@
           throw new IllegalArgumentException("Not found process definition with ID " + processId);
         }
         return generateProcess(process);
+      } else if (viewId.startsWith("attachment_")) {
+        String tabId = viewId.substring("attachment_".length());
+        Tab tab = OBDal.getInstance().get(Tab.class, tabId);
+        if (tab == null) {
+          throw new IllegalArgumentException("Not found process definition with ID " + tabId);
+        }
+        return generateAttachment(tab);
       } else {
         return generateView(viewId);
       }
@@ -142,7 +150,12 @@
   }
 
   protected String generateAttachment(Tab tab) {
+    attachmentWindowComponent.setClient(getParameter("client"));
     attachmentWindowComponent.setTab(tab);
+    String timestamp = getParameter("timestamp");
+    if (StringUtils.isNotEmpty(timestamp)) {
+      attachmentWindowComponent.setUniqueString(timestamp);
+    }
     attachmentWindowComponent.setParameters(getParameters());
     return attachmentWindowComponent.generate();
   }
@@ -173,6 +186,13 @@
         throw new IllegalArgumentException("Not found process definition with ID " + processId);
       }
       return process.getModule();
+    } else if (id.startsWith("attachment_")) {
+      String tabId = id.substring("attachment_".length());
+      Tab tab = OBDal.getInstance().get(Tab.class, tabId);
+      if (tab == null) {
+        throw new IllegalArgumentException("Not found tab with ID " + tabId);
+      }
+      return tab.getModule();
     } else {
       OBUIAPPViewImplementation view = getView(id);
       if (view != null) {
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-attachment-view.js.ftl	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-attachment-view.js.ftl	Tue May 26 12:11:22 2015 +0200
@@ -20,15 +20,11 @@
 -->
 
 /*jslint*/
-<#if !data.popup>
-OB.Layout.ViewManager.loadedWindowClassName = 'attachment${data.windowClientClassName?js_string}';
-</#if>
-
-isc.ClassFactory.defineClass('<#if !data.popup>attachment</#if>${data.windowClientClassName?js_string}', isc.OBAttachmentWindowView).addProperties({
+isc.ClassFactory.defineClass('_attachment${data.windowClientClassName?js_string}', isc.OBAttachmentWindowView).addProperties({
     popup: true, 
     viewProperties: {
-      fields: [
-    <#list data.parameters as param>
+      additionalFields: [
+    <#list data.paramHandler.parameters as param>
       <@createParameter param/><#if param_has_next>,</#if>
     </#list>    
      ]
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachImplementationManager.java	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachImplementationManager.java	Tue May 26 12:11:22 2015 +0200
@@ -99,8 +99,13 @@
       throw new OBException(OBMessageUtils.messageBD("OBUIAPP_NoFileToAttach"));
     }
 
-    AttachmentConfig attachConf = getAttachmenConfig(OBContext.getOBContext().getCurrentClient());
-    AttachmentMethod attachMethod = attachConf.getAttachmentMethod();
+    AttachmentConfig attachConf = AttachmentUtils.getAttachmentConfig(org.getClient());
+    AttachmentMethod attachMethod;
+    if (attachConf == null) {
+      attachMethod = AttachmentUtils.getDefaultAttachmentMethod();
+    } else {
+      attachMethod = attachConf.getAttachmentMethod();
+    }
 
     String strName = file.getName();
 
@@ -363,8 +368,8 @@
       return ((AttachmentConfig) obc.uniqueResult());
     }
     OBCriteria<AttachmentMethod> am = OBDal.getInstance().createCriteria(AttachmentMethod.class);
-    obc.add(Restrictions.eq(AttachmentMethod.PROPERTY_VALUE, "Default"));
-    obc.setMaxResults(1);
+    am.add(Restrictions.eq(AttachmentMethod.PROPERTY_VALUE, "Default"));
+    am.setMaxResults(1);
     if (am.uniqueResult() != null) {
       return (AttachmentConfig) am.uniqueResult();
     } else {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentUtils.java	Tue May 26 12:11:22 2015 +0200
@@ -0,0 +1,73 @@
+package org.openbravo.client.application.window;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.client.application.Parameter;
+import org.openbravo.dal.core.DalUtil;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.model.ad.utility.AttachmentConfig;
+import org.openbravo.model.ad.utility.AttachmentMethod;
+
+public class AttachmentUtils {
+  private static Map<String, String> clientConfigs = new HashMap<String, String>();
+  public final static String DEFAULT_METHOD = "Default";
+
+  public static AttachmentConfig getAttachmentConfig(Client client) {
+    String strAttachmentConfigId = clientConfigs.get(DalUtil.getId(client));
+    if (strAttachmentConfigId == null) {
+      // Only one active AttachmentConfig is allowed per client.
+      OBCriteria<AttachmentConfig> critAttConf = OBDal.getInstance().createCriteria(
+          AttachmentConfig.class);
+      critAttConf.add(Restrictions.eq(AttachmentConfig.PROPERTY_CLIENT, client));
+      if (!OBDal.getInstance().isActiveFilterEnabled()) {
+        critAttConf.setFilterOnActive(true);
+      }
+      critAttConf.setMaxResults(1);
+      AttachmentConfig attConf = (AttachmentConfig) critAttConf.uniqueResult();
+      if (attConf != null) {
+        clientConfigs.put((String) DalUtil.getId(client), attConf.getId());
+      }
+      return attConf;
+    }
+    return OBDal.getInstance().get(AttachmentConfig.class, strAttachmentConfigId);
+  }
+
+  public static AttachmentConfig getAttachmentConfig() {
+    Client client = OBContext.getOBContext().getCurrentClient();
+    return getAttachmentConfig(client);
+  }
+
+  public static AttachmentMethod getDefaultAttachmentMethod() {
+    OBCriteria<AttachmentMethod> critAttMethod = OBDal.getInstance().createCriteria(
+        AttachmentMethod.class);
+    critAttMethod.add(Restrictions.eq(AttachmentMethod.PROPERTY_VALUE, DEFAULT_METHOD));
+    critAttMethod.setMaxResults(1);
+    if (critAttMethod.uniqueResult() != null) {
+      return (AttachmentMethod) critAttMethod.uniqueResult();
+    } else {
+      throw new OBException(OBMessageUtils.messageBD("OBUIAPP_NoMethod"));
+    }
+  }
+
+  public static List<Parameter> getMethodMetadataParameters(AttachmentMethod attachMethod, Tab tab) {
+    StringBuilder where = new StringBuilder();
+    where.append(Parameter.PROPERTY_ATTACHMENTMETHOD + "= :attMethod");
+    where.append(" and (" + Parameter.PROPERTY_TAB + " is null or " + Parameter.PROPERTY_TAB
+        + " = :tab)");
+    final OBQuery<Parameter> qryParams = OBDal.getInstance().createQuery(Parameter.class,
+        where.toString());
+    qryParams.setNamedParameter("attMethod", attachMethod);
+    qryParams.setNamedParameter("tab", tab);
+    return qryParams.list();
+  }
+}
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentWindowComponent.java	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentWindowComponent.java	Tue May 26 12:11:22 2015 +0200
@@ -29,24 +29,28 @@
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.client.application.Parameter;
-import org.openbravo.client.application.window.OBViewParameterHandler.OBViewParameter;
+import org.openbravo.client.kernel.BaseTemplateComponent;
 import org.openbravo.client.kernel.KernelConstants;
 import org.openbravo.client.kernel.Template;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.ad.domain.Validation;
+import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.model.ad.utility.AttachmentConfig;
+import org.openbravo.model.ad.utility.AttachmentMethod;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * The component which takes care of creating a class for a tab's Attachment popup.
  */
-public class AttachmentWindowComponent extends ParameterWindowComponent {
+public class AttachmentWindowComponent extends BaseTemplateComponent {
   private static final String DEFAULT_TEMPLATE_ID = "01E447F740584E02BA4612F6BDFB900D";
   private static final Logger log = LoggerFactory.getLogger(AttachmentWindowComponent.class);
 
   private Boolean inDevelopment = null;
   private String uniqueString = "" + System.currentTimeMillis();
+  private String clientId = null;
   private Tab tab;
 
   @Inject
@@ -69,6 +73,10 @@
     this.uniqueString = uniqueString;
   }
 
+  public void setClient(String clientId) {
+    this.clientId = clientId;
+  }
+
   public boolean isIndevelopment() {
     if (inDevelopment != null) {
       return inDevelopment;
@@ -88,14 +96,9 @@
     return jsCode;
   }
 
-  public String getThreadSafe() {
-    return "true";
-  }
-
   public void setTab(Tab tab) {
     this.tab = tab;
-    // TODO: Review whether the process is necessary or not
-    // paramHandler.setProcess(process);
+    paramHandler.setParameters(getTabMetadataFields());
     paramHandler.setParamWindow(this);
   }
 
@@ -103,10 +106,6 @@
     return paramHandler;
   }
 
-  public List<OBViewParameter> getParameters() {
-    return null;
-  }
-
   public String getDynamicColumns() {
     List<Parameter> paramsWithValidation = new ArrayList<Parameter>();
     List<String> allParams = new ArrayList<String>();
@@ -147,9 +146,17 @@
   }
 
   private List<Parameter> getTabMetadataFields() {
+    AttachmentConfig attConf = AttachmentUtils.getAttachmentConfig((Client) OBDal.getInstance()
+        .getProxy(Client.ENTITY_NAME, clientId));
+    AttachmentMethod attachMethod;
+    if (attConf == null) {
+      attachMethod = AttachmentUtils.getDefaultAttachmentMethod();
+    } else {
+      attachMethod = attConf.getAttachmentMethod();
+    }
     // TODO Auto-generated method stub
     // Load attachment method in use
-    return null;
+    return AttachmentUtils.getMethodMetadataParameters(attachMethod, tab);
   }
 
   /**
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentsAH.java	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/AttachmentsAH.java	Tue May 26 12:11:22 2015 +0200
@@ -79,8 +79,12 @@
         Attachment attachment = null;
         String attachId = "";
         if ("INITIALIZE".equals(action)) {
-          attConf = aim.getAttachmenConfig(OBContext.getOBContext().getCurrentClient());
-          attMethod = attConf.getAttachmentMethod();
+          attConf = AttachmentUtils.getAttachmentConfig();
+          if (attConf == null) {
+            attMethod = AttachmentUtils.getDefaultAttachmentMethod();
+          } else {
+            attMethod = attConf.getAttachmentMethod();
+          }
         } else {
           attachId = request.getString("attachId");
           attachment = OBDal.getInstance().get(Attachment.class, attachId);
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/CoreAttachImplementation.java	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/CoreAttachImplementation.java	Tue May 26 12:11:22 2015 +0200
@@ -20,14 +20,15 @@
 package org.openbravo.client.application.window;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Map;
 
 import javax.enterprise.context.ApplicationScoped;
 
+import org.apache.commons.io.FileUtils;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.client.kernel.ComponentProvider;
-import org.openbravo.common.actionhandler.OrderCreatePOLines;
 import org.openbravo.erpCommon.businessUtility.TabAttachments;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.model.ad.utility.Attachment;
@@ -37,7 +38,7 @@
 @ApplicationScoped
 @ComponentProvider.Qualifier(CoreAttachImplementation.DEFAULT)
 public class CoreAttachImplementation extends AttachImplementation {
-  private Logger log = LoggerFactory.getLogger(OrderCreatePOLines.class);
+  private Logger log = LoggerFactory.getLogger(CoreAttachImplementation.class);
 
   public static final String DEFAULT = "Default";
   public static final String METADATA_DESCRIPTION = "Description";
@@ -55,19 +56,17 @@
     // FIXME: Get the directory separator from Java runtime
     String attachmentFolder = OBPropertiesProvider.getInstance().getOpenbravoProperties()
         .getProperty("attach.path");
-    final File uploadedDir = new File(attachmentFolder + "/" + strFileDir);
-    if (!uploadedDir.exists()) {
-      uploadedDir.mkdirs();
-    }
     String strName = "";
     File uploadedFile = null;
     strName = file.getName();
-    uploadedFile = new File(uploadedDir, strName);
+    uploadedFile = new File(attachmentFolder + "/" + strFileDir, strName);
     log.debug("Destination file before renaming: " + uploadedFile);
-    if (!file.renameTo(uploadedFile)) {
-      log.error("CoreAttachImplmentation: Error renaming the file. Unreachable destination: "
-          + uploadedDir);
-      throw new OBException(OBMessageUtils.messageBD("UnreachableDestination") + uploadedDir);
+    try {
+      FileUtils.moveFileToDirectory(file, uploadedFile, true);
+    } catch (IOException e) {
+      log.error("Error moving the file to: " + uploadedFile, e);
+      throw new OBException(
+          OBMessageUtils.messageBD("UnreachableDestination") + " " + uploadedFile, e);
     }
     if (parameters != null && parameters.get(METADATA_DESCRIPTION) != null) {
       attachment.setText(parameters.get(METADATA_DESCRIPTION).toString());
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewParameterHandler.java	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewParameterHandler.java	Tue May 26 12:11:22 2015 +0200
@@ -28,7 +28,7 @@
 import org.apache.log4j.Logger;
 import org.openbravo.client.application.DynamicExpressionParser;
 import org.openbravo.client.application.Parameter;
-import org.openbravo.client.application.Process;
+import org.openbravo.client.kernel.BaseTemplateComponent;
 import org.openbravo.client.kernel.reference.UIDefinition;
 import org.openbravo.client.kernel.reference.UIDefinitionController;
 import org.openbravo.dal.core.DalUtil;
@@ -42,12 +42,11 @@
 public class OBViewParameterHandler {
   private static final Logger log = Logger.getLogger(OBViewParameterHandler.class);
   private static final String WINDOW_REFERENCE_ID = "FF80818132D8F0F30132D9BC395D0038";
-  private Process process;
-  private ParameterWindowComponent paramWindow;
-  private List<Parameter> parameters;
+  private BaseTemplateComponent paramWindow;
+  private List<Parameter> parameters = new ArrayList<Parameter>();
 
-  public void setProcess(Process process) {
-    this.process = process;
+  public void setParameters(List<Parameter> parameters) {
+    this.parameters = parameters;
   }
 
   public List<OBViewParameter> getParameters() {
@@ -57,7 +56,7 @@
     // Computes the display logic of the parameters
     // It has to be done in advance in order to determine the dynamic parameters
     Map<Parameter, String> displayLogicMap = new HashMap<Parameter, String>();
-    for (Parameter param : process.getOBUIAPPParameterList()) {
+    for (Parameter param : parameters) {
       if (param.isActive() && param.getDisplayLogic() != null && !param.getDisplayLogic().isEmpty()) {
         final DynamicExpressionParser parser = new DynamicExpressionParser(param.getDisplayLogic(),
             param.getObuiappProcess(), true);
@@ -72,7 +71,7 @@
 
     // Computes read-only logic
     Map<Parameter, String> readOnlyLogicMap = new HashMap<Parameter, String>();
-    for (Parameter param : process.getOBUIAPPParameterList()) {
+    for (Parameter param : parameters) {
       if (param.isActive() && !param.isFixed() && param.getReadOnlyLogic() != null
           && !param.getReadOnlyLogic().isEmpty()) {
         final DynamicExpressionParser parser = new DynamicExpressionParser(
@@ -89,7 +88,7 @@
     List<OBViewParameter> params = new ArrayList<OBViewParameterHandler.OBViewParameter>();
     OBViewParamGroup currentGroup = null;
     FieldGroup currentADFieldGroup = null;
-    for (Parameter param : process.getOBUIAPPParameterList()) {
+    for (Parameter param : parameters) {
       if (!(param.isActive()
           && (!param.isFixed() || param.getReference().getId().equals(WINDOW_REFERENCE_ID)) && (!param
           .getReference().getId().equals(ParameterWindowComponent.BUTTON_LIST_REFERENCE_ID)))) {
@@ -361,7 +360,7 @@
     }
   }
 
-  public void setParamWindow(ParameterWindowComponent parameterWindowComponent) {
-    this.paramWindow = parameterWindowComponent;
+  public void setParamWindow(BaseTemplateComponent baseTemplateComponent) {
+    this.paramWindow = baseTemplateComponent;
   }
 }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ParameterWindowComponent.java	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ParameterWindowComponent.java	Tue May 26 12:11:22 2015 +0200
@@ -109,8 +109,7 @@
 
   public void setProcess(org.openbravo.client.application.Process process) {
     this.process = process;
-    paramHandler.setProcess(process);
-    paramHandler.setParameters(parameters);
+    paramHandler.setParameters(process.getOBUIAPPParameterList());
     paramHandler.setParamWindow(this);
   }
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js	Tue May 26 12:11:22 2015 +0200
@@ -170,6 +170,7 @@
 
   width: '100%',
   align: 'left',
+  docOrganization: null,
 
   // never disable this item
   isDisabled: function () {
@@ -253,7 +254,6 @@
   fillAttachments: function (attachments) {
     var id, i, length;
 
-    var docOrganization;
     this.savedAttachments = attachments;
     this.destroyAndRemoveMembers(this.getMembers());
     var hLayout = isc.HLayout.create();
@@ -267,20 +267,47 @@
     //Here we are checking if the entity is 'Organization' because the way of obtaining the
     //id of the organization of the form is different depending on the entity
     if (this.entity === 'Organization') {
-      docOrganization = this.recordId;
+      this.docOrganization = this.recordId;
     } else {
-      docOrganization = this.attachmentForm.values.organization;
+      this.docOrganization = this.attachmentForm.values.organization;
     }
     var addButton = isc.OBLinkButtonItem.create({
       title: '[ ' + OB.I18N.getLabel('OBUIAPP_AttachmentAdd') + ' ]',
       width: '30px',
       canvas: me,
       action: function (forceUpload) {
-        var form, submitbutton;
+        var viewId = 'attachment_' + this.canvas.tabId,
+           ownerView = this.canvas.getForm().view,
+           standardWindow = ownerView.standardWindow,
+           parts = standardWindow.getPrototype().Class.split('_'),
+           clientContext = null,
+           record = this.canvas.getForm().values,
+           params = {},
+           callback;
         if (OB.Utilities.currentUploader === null || forceUpload) {
-          var attachmentFile = OB.I18N.getLabel('OBUIAPP_AttachmentFile');
+          callback = function () {
+            standardWindow.openProcess({
+              paramWindow: true,
+              processId: viewId,
+              ownerView: ownerView,
+              attachSection: me,
+              windowTitle: OB.I18N.getLabel('OBUIAPP_AttachFile'),
+              uiPattern: 'A'
+            });
+          };
+          params.tabTitle = record[OB.Constants.IDENTIFIER];
+          params.inpDocumentOrg = me.docOrganization;
+          params.client = me.attachmentForm.values.client;
+          if (parts.length === 3) {
+            // is in development. add the timestamp to the parameters.
+            params.timestamp = parts[2];
+          }
+
+          OB.Layout.ViewManager.fetchView(viewId, callback, clientContext, null, false, params);
+
           //Callback: creates metadata Fields, add them to form and executes popup.
-          var callback = function (rpcResponse, data, rpcRequest) {
+          /*
+            var callback = function (rpcResponse, data, rpcRequest) {
               var metadataFields = [],
                   j;
 
@@ -415,7 +442,7 @@
           }, {
             tabId: form.getItem('inpTabId').value
           }, callback);
-
+*/
         } else {
           isc.ask(OB.I18N.getLabel('OBUIAPP_OtherUploadInProgress'), function (clickOK) {
             if (clickOK) {
@@ -593,7 +620,7 @@
         }, {
           name: 'inpDocumentOrg',
           type: 'hidden',
-          value: docOrganization
+          value: this.docOrganization
         }, {
           name: 'inpwindowId',
           type: 'hidden',
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-attachment-window-view.js	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-attachment-window-view.js	Tue May 26 12:11:22 2015 +0200
@@ -26,7 +26,7 @@
 
 isc.OBAttachmentWindowView.addProperties({
   // Set default properties for the OBPopup container
-  showMinimizeButton: true,
+  showMinimizeButton: false,
   showMaximizeButton: true,
   popupWidth: '90%',
   popupHeight: '90%',
@@ -40,519 +40,149 @@
   overflow: 'auto',
   autoSize: false,
 
-  dataSource: null,
-
-  viewGrid: null,
-
-  addNewButton: null,
-
-  gridFields: [],
   members: [],
+  attachSection: null,
+  ownerView: null,
+  attachFormProps: {
+    encoding: 'multipart',
+    action: './businessUtility/TabAttachments_FS.html',
+    target: 'background_target',
+    //numCols: 2,
+    align: 'center'
+    //redraw: function () {}
+    //theCanvas: this.canvas
+  },
 
   initWidget: function () {
-    var i, field, items = [],
-        buttonLayout = [],
-        okButton, newButton, cancelButton, view = this,
-        newShowIf, params;
+    var i, attachFields = [{
+      name: 'inpname',
+      title: OB.I18N.getLabel('OBUIAPP_AttachmentFile'),
+      type: 'upload',
+      multiple: false,
+      canFocus: false
+    }, {
+      name: 'Command',
+      type: 'hidden',
+      value: 'SAVE_NEW_OB3'
+    }, {
+      name: 'buttonId',
+      type: 'hidden',
+      value: this.attachSection.ID
+    }, {
+      name: 'viewId',
+      type: 'hidden',
+      value: this.ownerView.ID
+    }, {
+      name: 'inpKey',
+      type: 'hidden',
+      value: this.attachSection.recordId
+    }, {
+      name: 'inpTabId',
+      type: 'hidden',
+      value: this.attachSection.tabId
+    }, {
+      name: 'inpDocumentOrg',
+      type: 'hidden',
+      value: this.attachSection.docOrganization
+    }, {
+      name: 'inpwindowId',
+      type: 'hidden',
+      value: this.attachSection.windowId
+    }];
 
-    // Buttons
+    this.formProps = isc.addProperties({}, this.formProps, this.attachFormProps);
+    this.viewProperties.fields = isc.shallowClone(attachFields);
+    for (i = 0; i < this.viewProperties.additionalFields.length; i++) {
+      this.viewProperties.fields.push(this.viewProperties.additionalFields[i]);
+    }
 
-    function actionClick() {
-      var hasErrors = false,
-          grid, fields, selection, len, allRows, lineNumbers, i, j, record, undef;
-      view.messageBar.hide();
-      if (view.grid && view.grid.viewGrid) {
-        grid = view.grid.viewGrid;
-        fields = grid.getFields();
-        selection = grid.getSelectedRecords() || [];
-        len = selection.length;
-        allRows = grid.data.allRows || grid.data.localData || grid.data;
-        for (i = 0; i < len; i++) {
-          record = grid.getEditedRecord(grid.getRecordIndex(selection[i]));
-          for (j = 0; j < fields.length; j++) {
-            if (fields[j].required) {
-              if (record[fields[j].name] === null || record[fields[j].name] === '' || record[fields[j] === undef]) {
-                hasErrors = true;
-                if (lineNumbers === undef) {
-                  lineNumbers = grid.getRecordIndex(selection[i]).toString();
-                } else {
-                  lineNumbers = lineNumbers + "," + grid.getRecordIndex(selection[i]).toString();
-                }
-              }
-            }
+
+    this.Super('initWidget', arguments);
+
+  },
+  
+  buildButtonLayout: function () {
+    var view = this,
+        buttons = [],
+        submitbutton, cancelButton;
+
+    function doClick () {
+      var view = this.view,
+       value = view.theForm.getItem('inpname').getElement().value,
+      lastChar, fileName;
+
+      if (!value) {
+        isc.say(OB.I18N.getLabel('OBUIAPP_AttachmentsSpecifyFile'));
+        return;
+      }
+
+      lastChar = value.lastIndexOf("\\") + 1;
+      fileName = lastChar === -1 ? value : value.substring(lastChar);
+    
+      if (view.attachSection.fileExists(fileName, view.attachSection.savedAttachments)) {
+        isc.confirm(OB.I18N.getLabel('OBUIAPP_ConfirmUploadOverwrite'), function (clickedOK) {
+          if (clickedOK !== true) {
+            return;
           }
-        }
+          view.submitFile(fileName);
+        });
+      } else {
+        view.submitFile(fileName);
       }
-      if (!hasErrors) {
-        if (view.validate()) {
-          view.doProcess(this._buttonValue);
-        } else {
-          // If the messageBar is visible, it means that it has been set due to a custom validation inside view.validate()
-          // so we don't want to overwrite it with the generic OBUIAPP_ErrorInFields message
-          if (!view.messageBar.isVisible()) {
-            view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, OB.I18N.getLabel('OBUIAPP_ErrorInFields'));
-          }
-        }
-      } else {
-        view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, OB.I18N.getLabel('OBUIAPP_FillMandatoryFields') + " " + lineNumbers);
+
+    }
+    
+    submitbutton = isc.OBFormButton.create({
+      title: OB.I18N.getLabel('OBUIAPP_AttachmentSubmit'),
+      click: doClick,
+      view: view
+    });
+    view.firstFocusedItem = submitbutton;
+    cancelButton = isc.OBFormButton.create({
+      title: OB.I18N.getLabel('OBUISC_Dialog.CANCEL_BUTTON_TITLE'),
+      realTitle: '',
+      click: function () {
+        view.closeClick();
+      }
+    });
+
+    buttons.push(isc.LayoutSpacer.create({}));
+    buttons.push(submitbutton);
+    buttons.push(isc.LayoutSpacer.create({}));
+    buttons.push(cancelButton);
+    buttons.push(isc.LayoutSpacer.create({}));
+
+    return buttons;
+  },
+  
+  submitFile: function (fileName) {
+    var form = this.theForm;
+    var hTempLayout = isc.HLayout.create();
+    this.attachSection.addMember(hTempLayout, this.attachSection.getMembers().size());
+    var uploadingFile = isc.Label.create({
+      contents: fileName
+    });
+    var uploading = isc.Label.create({
+      className: 'OBLinkButtonItemFocused',
+      contents: '    ' + OB.I18N.getLabel('OBUIAPP_AttachmentUploading')
+    });
+    hTempLayout.addMember(uploadingFile);
+    hTempLayout.addMember(uploading);
+    var button = this.attachSection.getForm().view.toolBar.getLeftMember(isc.OBToolbar.TYPE_ATTACHMENTS);
+    if (!button) {
+      button = this.attachSection.getForm().view.toolBar.getLeftMember("attachExists");
+    }
+    button.customState = 'Progress';
+    button.resetBaseStyle();
+    if (OB.Utilities.currentUploader !== null) {
+      var curAttachSection = window[OB.Utilities.currentUploader];
+      if (curAttachSection && curAttachSection.resetToolbar) {
+        curAttachSection.resetToolbar();
       }
     }
+    OB.Utilities.currentUploader = this.attachSection.ID;
+    form.submitForm();
+    this.closeClick();
+  }
 
-    okButton = isc.OBFormButton.create({
-      title: OB.I18N.getLabel('OBUIAPP_Done'),
-      realTitle: '',
-      _buttonValue: 'DONE',
-      click: actionClick
-    });
-
-    if (this.popup) {
-      buttonLayout.push(isc.LayoutSpacer.create({}));
-    }
-
-    if (this.buttons && !isc.isA.emptyObject(this.buttons)) {
-      for (i in this.buttons) {
-        if (this.buttons.hasOwnProperty(i)) {
-
-          newButton = isc.OBFormButton.create({
-            title: this.buttons[i],
-            realTitle: '',
-            _buttonValue: i,
-            click: actionClick
-          });
-          buttonLayout.push(newButton);
-          OB.TestRegistry.register('org.openbravo.client.application.process.pickandexecute.button.' + i, newButton);
-
-          // pushing a spacer
-          if (this.popup) {
-            buttonLayout.push(isc.LayoutSpacer.create({
-              width: 32
-            }));
-          }
-        }
-      }
-    } else {
-      buttonLayout.push(okButton);
-      OB.TestRegistry.register('org.openbravo.client.application.process.pickandexecute.button.ok', okButton);
-      if (this.popup) {
-        buttonLayout.push(isc.LayoutSpacer.create({
-          width: 32
-        }));
-      }
-    }
-
-    if (this.popup) {
-      cancelButton = isc.OBFormButton.create({
-        title: OB.I18N.getLabel('OBUISC_Dialog.CANCEL_BUTTON_TITLE'),
-        realTitle: '',
-        click: function () {
-          view.closeClick();
-        }
-      });
-      buttonLayout.push(cancelButton);
-      buttonLayout.push(isc.LayoutSpacer.create({}));
-      OB.TestRegistry.register('org.openbravo.client.application.process.pickandexecute.button.cancel', cancelButton);
-    }
-
-    if (!this.popup) {
-      this.toolBarLayout = isc.OBToolbar.create({
-        view: this,
-        leftMembers: [{}],
-        rightMembers: buttonLayout
-      });
-      // this.toolBarLayout.addMems(buttonLayout);
-      this.members.push(this.toolBarLayout);
-    }
-
-    // Message bar
-    this.messageBar = isc.OBMessageBar.create({
-      visibility: 'hidden',
-      view: this
-    });
-    this.members.push(this.messageBar);
-
-    newShowIf = function (item, value, form, values) {
-      var currentValues = isc.shallowClone(values || form.view.getCurrentValues()),
-          context = {},
-          originalShowIfValue = false;
-
-      OB.Utilities.fixNull250(currentValues);
-
-      try {
-        if (isc.isA.Function(this.originalShowIf)) {
-          originalShowIfValue = this.originalShowIf(item, value, form, currentValues, context);
-        } else {
-          originalShowIfValue = isc.JSON.decode(this.originalShowIf);
-        }
-      } catch (_exception) {
-        isc.warn(_exception + ' ' + _exception.message + ' ' + _exception.stack);
-      }
-      return originalShowIfValue;
-    };
-
-    // Parameters
-    if (this.viewProperties.fields) {
-      for (i = 0; i < this.viewProperties.fields.length; i++) {
-        field = this.viewProperties.fields[i];
-        field = isc.addProperties({
-          view: this
-        }, field);
-
-        if (field.showIf) {
-          field.originalShowIf = field.showIf;
-          field.showIf = newShowIf;
-        }
-        if (field.isGrid) {
-          this.grid = isc.OBPickAndExecuteView.create(field);
-        } else {
-          items.push(field);
-        }
-      }
-
-      if (items.length !== 0) {
-        // create form if there items to include
-        this.theForm = isc.DynamicForm.create({
-          paramWindow: this,
-          width: '99%',
-          titleSuffix: '',
-          requiredTitleSuffix: '',
-          autoFocus: true,
-          titleOrientation: 'top',
-          numCols: 4,
-          showErrorIcons: false,
-          colWidths: ['*', '*', '*', '*'],
-          itemChanged: function (item, newValue) {
-            var affectedParams, i, field;
-
-            this.paramWindow.handleReadOnlyLogic();
-
-            // Check validation rules (subordinated fields), when value of a
-            // parent field is changed, all its subordinated are reset
-            affectedParams = this.paramWindow.dynamicColumns[item.name];
-            if (!affectedParams) {
-              return;
-            }
-            for (i = 0; i < affectedParams.length; i++) {
-              field = this.getField(affectedParams[i]);
-              if (field && field.setValue) {
-                field.setValue(null);
-              }
-            }
-          }
-        });
-
-        this.theForm.setItems(items);
-        this.members.push(this.theForm);
-      }
-    }
-    if (this.grid) {
-      this.members.push(this.grid);
-    }
-
-
-    if (this.popup) {
-      this.firstFocusedItem = okButton;
-      this.popupButtons = isc.HLayout.create({
-        align: 'center',
-        width: '100%',
-        height: OB.Styles.Process.PickAndExecute.buttonLayoutHeight,
-        members: [isc.HLayout.create({
-          width: 1,
-          overflow: 'visible',
-          styleName: this.buttonBarStyleName,
-          height: this.buttonBarHeight,
-          defaultLayoutAlign: 'center',
-          members: buttonLayout
-        })]
-      });
-      this.members.push(this.popupButtons);
-      this.closeClick = function () {
-        this.closeClick = function () {
-          return true;
-        }; // To avoid loop when "Super call"
-        this.parentElement.parentElement.closeClick(); // Super call
-      };
-    }
-    this.loading = OB.Utilities.createLoadingLayout(OB.I18N.getLabel('OBUIAPP_PROCESSING'));
-    this.loading.hide();
-    this.members.push(this.loading);
-    this.Super('initWidget', arguments);
-
-    params = {
-      processId: this.processId
-    };
-
-    if (this.sourceView) {
-      params.context = this.sourceView.getContextInfo(false, true, true, true);
-    }
-
-    OB.RemoteCallManager.call('org.openbravo.client.application.process.DefaultsProcessActionHandler', {}, params, function (rpcResponse, data, rpcRequest) {
-      view.handleDefaults(data);
-    });
-  },
-
-  handleResponse: function (refresh, message, responseActions, retryExecution, data) {
-    var window = this.parentWindow,
-        tab = OB.MainView.TabSet.getTab(this.viewTabId),
-        i;
-
-    // change title to done
-    if (tab) {
-      tab.setTitle(OB.I18N.getLabel('OBUIAPP_ProcessTitle_Done', [this.tabTitle]));
-    }
-
-    if (data.showResultsInProcessView) {
-      if (!this.resultLayout) {
-        this.resultLayout = isc.HLayout.create({
-          width: '100%',
-          height: '*'
-        });
-        this.addMember(this.resultLayout);
-      } else {
-        // clear the resultLayout
-        this.resultLayout.setMembers([]);
-      }
-    }
-
-    this.showProcessing(false);
-    if (message) {
-      if (this.popup) {
-        if (!retryExecution) {
-          if (message.title) {
-            this.buttonOwnerView.messageBar.setMessage(message.severity, message.title, message.text);
-          } else {
-            this.buttonOwnerView.messageBar.setMessage(message.severity, message.text);
-          }
-        } else {
-          // Popup has no message bar, showing the message in a warn popup
-          isc.warn(message.text);
-        }
-      } else {
-        if (message.title) {
-          this.messageBar.setMessage(message.severity, message.title, message.text);
-        } else {
-          this.messageBar.setMessage(message.severity, message.text);
-        }
-      }
-    }
-
-    if (!retryExecution) {
-      this.disableFormItems();
-    } else {
-      // Show again all toolbar buttons so the process
-      // can be called again
-      if (this.toolBarLayout) {
-        for (i = 0; i < this.toolBarLayout.children.length; i++) {
-          if (this.toolBarLayout.children[i].show) {
-            this.toolBarLayout.children[i].show();
-          }
-        }
-      }
-      if (this.popupButtons) {
-        this.popupButtons.show();
-      }
-    }
-
-    if (responseActions) {
-      responseActions._processView = this;
-      OB.Utilities.Action.executeJSON(responseActions, null, null, this);
-    }
-
-    if (this.popup && !retryExecution) {
-      this.buttonOwnerView.setAsActiveView();
-
-      if (refresh) {
-        window.refresh();
-      }
-
-      this.closeClick = function () {
-        return true;
-      }; // To avoid loop when "Super call"
-      this.parentElement.parentElement.closeClick(); // Super call
-    }
-  },
-
-  disableFormItems: function () {
-    var i, params;
-    if (this.theForm && this.theForm.getItems) {
-      params = this.theForm.getItems();
-      for (i = 0; i < params.length; i++) {
-        if (params[i].disable) {
-          params[i].disable();
-        }
-      }
-    }
-  },
-
-  // dummy required by OBStandardView.prepareGridFields
-  setFieldFormProperties: function () {},
-
-  validate: function () {
-    var viewGrid, validForm;
-    if (this.theForm) {
-      validForm = this.theForm.validate();
-      if (!validForm) {
-        return validForm;
-      }
-    }
-
-    if (this.grid) {
-      viewGrid = this.grid.viewGrid;
-
-      viewGrid.endEditing();
-      return !viewGrid.hasErrors();
-    }
-    return true;
-  },
-
-  showProcessing: function (processing) {
-    var i;
-    if (processing) {
-      if (this.theForm) {
-        this.theForm.hide();
-      }
-      if (this.grid) {
-        this.grid.hide();
-      }
-      if (this.popupButtons) {
-        this.popupButtons.hide();
-      }
-
-      if (this.toolBarLayout) {
-        for (i = 0; i < this.toolBarLayout.children.length; i++) {
-          if (this.toolBarLayout.children[i].hide) {
-            this.toolBarLayout.children[i].hide();
-          }
-        }
-      }
-
-      this.loading.show();
-    } else {
-      if (this.theForm) {
-        this.theForm.show();
-      }
-      if (this.grid) {
-        this.grid.show();
-      }
-
-      this.loading.hide();
-    }
-  },
-
-  doProcess: function (btnValue) {
-    var i, tmp, view = this,
-        grid, allProperties = (this.sourceView && this.sourceView.getContextInfo(false, true, false, true)) || {},
-        selection, len, allRows, params, tab;
-    // activeView = view.parentWindow && view.parentWindow.activeView,  ???.
-    if (this.resultLayout && this.resultLayout.destroy) {
-      this.resultLayout.destroy();
-      delete this.resultLayout;
-    }
-    this.showProcessing(true);
-
-    // change tab title to show executing...
-    tab = OB.MainView.TabSet.getTab(this.viewTabId);
-    if (tab) {
-      tab.setTitle(OB.I18N.getLabel('OBUIAPP_ProcessTitle_Executing', [this.tabTitle]));
-    }
-
-    if (this.grid) {
-      // TODO: Support for multiple grids
-      grid = this.grid.viewGrid;
-      selection = grid.getSelectedRecords() || [];
-      len = selection.length;
-      allRows = grid.data.allRows || grid.data.localData || grid.data;
-      allProperties._selection = [];
-      allProperties._allRows = [];
-
-      for (i = 0; i < len; i++) {
-        tmp = isc.addProperties({}, selection[i], grid.getEditedRecord(grid.getRecordIndex(selection[i])));
-        allProperties._selection.push(tmp);
-      }
-
-      len = (allRows && allRows.length) || 0;
-      // Only send _allRows if all rows are cached
-      if (!(grid.data.resultSize) || (len < grid.data.resultSize)) {
-        for (i = 0; i < len; i++) {
-          tmp = isc.addProperties({}, allRows[i], grid.getEditedRecord(grid.getRecordIndex(allRows[i])));
-          allProperties._allRows.push(tmp);
-        }
-      }
-    }
-
-    allProperties._buttonValue = btnValue || 'DONE';
-
-    allProperties._params = this.getContextInfo();
-
-    OB.RemoteCallManager.call(this.actionHandler, allProperties, {
-      processId: this.processId,
-      windowId: this.windowId
-    }, function (rpcResponse, data, rpcRequest) {
-      view.handleResponse(true, (data && data.message), (data && data.responseActions), (data && data.retryExecution), data);
-    });
-  },
-
-  handleDefaults: function (defaults) {
-    var i, field, def;
-    if (!this.theForm) {
-      return;
-    }
-
-    for (i in defaults) {
-      if (defaults.hasOwnProperty(i)) {
-        def = defaults[i];
-        field = this.theForm.getItem(i);
-        if (field) {
-          if (isc.isA.Object(def)) {
-            if (def.identifier && def.value) {
-              field.valueMap = field.valueMap || {};
-              field.valueMap[def.value] = def.identifier;
-              field.setValue(def.value);
-            }
-          } else {
-            field.setValue(def);
-          }
-        }
-      }
-    }
-
-    this.handleReadOnlyLogic();
-
-    // redraw to execute display logic
-    this.theForm.markForRedraw();
-  },
-
-  // Checks params with readonly logic enabling or disabling them based on it
-  handleReadOnlyLogic: function () {
-    var form, fields, i, field;
-
-    form = this.theForm;
-    if (!form) {
-      return;
-    }
-
-    fields = form.getFields();
-    for (i = 0; i < fields.length; i++) {
-      field = form.getField(i);
-      if (field.readOnlyIf && field.setDisabled) {
-        field.setDisabled(field.readOnlyIf(form.getValues()));
-      }
-    }
-  },
-
-  getContextInfo: function () {
-    var result = {},
-        params, i;
-    if (!this.theForm) {
-      return result;
-    }
-
-    if (this.theForm && this.theForm.getItems) {
-      params = this.theForm.getItems();
-      for (i = 0; i < params.length; i++) {
-        result[params[i].name] = params[i].getValue();
-      }
-    }
-
-    return result;
-  }
 });
\ No newline at end of file
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-base-parameter-window-view.js	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-base-parameter-window-view.js	Tue May 26 12:11:22 2015 +0200
@@ -74,7 +74,6 @@
     var i, field, items = [],
         buttonLayout = [],
         view = this,
-        params = isc.shallowClone(this.baseParams),
         newShowIf;
 
     buttonLayout = view.buildButtonLayout();
@@ -174,13 +173,6 @@
     this.members.push(this.loading);
     this.Super('initWidget', arguments);
 
-    if (this.sourceView) {
-      params.context = this.sourceView.getContextInfo(false, true, true, true);
-    }
-
-    OB.RemoteCallManager.call('org.openbravo.client.application.process.DefaultsProcessActionHandler', {}, params, function (rpcResponse, data, rpcRequest) {
-      view.handleDefaults(data);
-    });
   },
 
   /*
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js	Tue May 26 12:07:35 2015 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js	Tue May 26 12:11:22 2015 +0200
@@ -34,10 +34,20 @@
   gridFields: [],
 
   initWidget: function () {
+    var params, view = this;
     this.baseParams.processId = this.processId;
 
     this.Super('initWidget', arguments);
 
+    params = isc.shallowClone(this.baseParams);
+    if (this.sourceView) {
+      params.context = this.sourceView.getContextInfo(false, true, true, true);
+    }
+
+    OB.RemoteCallManager.call('org.openbravo.client.application.process.DefaultsProcessActionHandler', {}, params, function (rpcResponse, data, rpcRequest) {
+      view.handleDefaults(data);
+    });
+
   },
 
   buildButtonLayout: function() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.integration.alfresco	Tue May 26 12:11:22 2015 +0200
@@ -0,0 +1,1 @@
+/home/gorkaion/openbravo/modules/hg/org.openbravo.integration.alfresco
\ No newline at end of file
--- a/src/org/openbravo/erpCommon/businessUtility/TabAttachments.java	Tue May 26 12:07:35 2015 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/TabAttachments.java	Tue May 26 12:11:22 2015 +0200
@@ -45,6 +45,7 @@
 import org.openbravo.base.weld.WeldUtils;
 import org.openbravo.client.application.Parameter;
 import org.openbravo.client.application.window.AttachImplementationManager;
+import org.openbravo.client.application.window.AttachmentUtils;
 import org.openbravo.client.application.window.AttachmentsAH;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
@@ -57,6 +58,7 @@
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.ui.Tab;
 import org.openbravo.model.ad.utility.Attachment;
+import org.openbravo.model.ad.utility.AttachmentConfig;
 import org.openbravo.model.ad.utility.AttachmentMethod;
 import org.openbravo.xmlEngine.XmlDocument;
 
@@ -127,8 +129,13 @@
         }
         //
         Map<String, String> metadata = new HashMap<String, String>();
-        AttachmentMethod attachMethod = aim.getAttachmenConfig(
-            OBContext.getOBContext().getCurrentClient()).getAttachmentMethod();
+        AttachmentConfig attConfig = AttachmentUtils.getAttachmentConfig();
+        AttachmentMethod attachMethod;
+        if (attConfig == null) {
+          attachMethod = AttachmentUtils.getDefaultAttachmentMethod();
+        } else {
+          attachMethod = attConfig.getAttachmentMethod();
+        }
         final OBQuery<Parameter> paramQuery = OBDal.getInstance().createQuery(Parameter.class,
             "attachmentMethod.id=:attachmentMethodId and (tab is null or tab.id=:tabId)");
         paramQuery.setNamedParameter("attachmentMethodId", attachMethod.getId());
@@ -168,6 +175,19 @@
         writer.write("top.OB.Utilities.writeErrorMessage(\"" + viewId + "\",\"" + e.getMessage()
             + "\");");
         writer.write("</SCRIPT></BODY></HTML>");
+      } catch (Exception e) {
+        OBDal.getInstance().rollbackAndClose();
+        log.error(e.getMessage(), e);
+
+        String viewId = vars.getStringParameter("viewId");
+        response.setContentType("text/html; charset=UTF-8");
+        Writer writer = response.getWriter();
+        writer.write("<HTML><BODY><script type=\"text/javascript\">");
+        writer.write("top.OB.Utilities.uploadFinished(\"" + buttonId + "\"," + obj.toString()
+            + ");");
+        writer.write("top.OB.Utilities.writeErrorMessage(\"" + viewId + "\",\"" + e.getMessage()
+            + "\");");
+        writer.write("</SCRIPT></BODY></HTML>");
       } finally {
         OBContext.restorePreviousMode();
         if (tempFile.exists()) { // If tempFile still exists in attachments/tmp must be removed