src-wad/src/org/openbravo/wad/ActionButton_Responser.javaxml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1093 c9c5a6341849
child 1805 317f843b2033
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0" encoding="UTF-8" ?>
carlos@0
     2
<!--
carlos@0
     3
 *************************************************************************
carlos@0
     4
 * The contents of this file are subject to the Openbravo  Public  License
carlos@0
     5
 * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
     6
 * Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
     7
 * file except in compliance with the License. You  may  obtain  a copy of
carlos@0
     8
 * the License at http://www.openbravo.com/legal/license.html 
carlos@0
     9
 * Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
    10
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    11
 * License for the specific  language  governing  rights  and  limitations
carlos@0
    12
 * under the License. 
carlos@0
    13
 * The Original Code is Openbravo ERP. 
carlos@0
    14
 * The Initial Developer of the Original Code is Openbravo SL 
asier@1093
    15
 * All portions are Copyright (C) 2001-2008 Openbravo SL 
carlos@0
    16
 * All Rights Reserved. 
carlos@0
    17
 * Contributor(s):  ______________________________________.
carlos@0
    18
 ************************************************************************
carlos@0
    19
-->
carlos@0
    20
carlos@0
    21
carlos@0
    22
<java_TMP>
carlos@0
    23
package org.openbravo.erpCommon.ad_actionButton;
carlos@0
    24
carlos@0
    25
import org.openbravo.erpCommon.utility.*;
carlos@0
    26
import org.openbravo.erpCommon.reference.*;
carlos@0
    27
import org.openbravo.utils.Replace;
carlos@0
    28
import org.openbravo.base.secureApp.HttpSecureAppServlet;
carlos@0
    29
import org.openbravo.base.secureApp.VariablesSecureApp;
carlos@0
    30
import org.openbravo.xmlEngine.XmlDocument;
carlos@0
    31
import java.io.*;
carlos@0
    32
import javax.servlet.*;
carlos@0
    33
import javax.servlet.http.*;
carlos@0
    34
carlos@0
    35
public class ActionButton_Responser extends HttpSecureAppServlet {
carlos@0
    36
  private static final long serialVersionUID = 1L;
carlos@0
    37
  protected static final String windowId = "ActionButtonResponser";
carlos@0
    38
carlos@0
    39
  public void init (ServletConfig config) {
carlos@0
    40
    super.init(config);
carlos@0
    41
    boolHist = false;
carlos@0
    42
  }
carlos@0
    43
carlos@0
    44
  public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
carlos@0
    45
    VariablesSecureApp vars = new VariablesSecureApp(request);
asier@120
    46
    
asier@120
    47
    String strProcessId = null;
asier@120
    48
    String command = vars.getCommand();
asier@120
    49
    
asier@120
    50
    if (command.equals("DEFAULT"))
asier@120
    51
      strProcessId = vars.getRequiredStringParameter("inpadProcessId");
asier@120
    52
    else if (command.startsWith("BUTTON"))
asier@120
    53
      strProcessId = command.substring("BUTTON".length());
asier@120
    54
    else if (command.startsWith("SAVE_BUTTONActionButton"))
asier@120
    55
      strProcessId = command.substring("SAVE_BUTTONActionButton".length());
asier@120
    56
   
asier@120
    57
    if (!vars.commandIn("DEFAULT") &amp;&amp; !hasGeneralAccess(vars, "P", strProcessId)) {
asier@120
    58
      bdErrorGeneralPopUp(response, Utility.messageBD(this, "Error", vars.getLanguage()), Utility.messageBD(this, "AccessTableNoView", vars.getLanguage()));
asier@120
    59
    }
asier@120
    60
    
asier@120
    61
      
carlos@0
    62
    if (vars.commandIn("DEFAULT")) {
asier@120
    63
      printPageDefault(response, vars, strProcessId);
carlos@0
    64
<FIELDS_TMP id="sectionActionButtons1">    } else if (vars.commandIn("BUTTON<FIELD_TMP id="ProcessID1">button</FIELD_TMP>")) {
carlos@0
    65
        <FIELD_TMP id="FieldsLoad1">String strField = vars.getStringParameter("inpFields");</FIELD_TMP>
carlos@0
    66
        printPageButton<FIELD_TMP id="ProcessID1">xx</FIELD_TMP>(response, vars<FIELD_TMP id="FieldsLoadName1">, strFields</FIELD_TMP>);
carlos@0
    67
</FIELDS_TMP>
carlos@0
    68
<FIELDS_TMP id="sectionActionButtons3">    } else if (vars.commandIn("SAVE_BUTTONActionButton<FIELD_TMP id="ProcessID3">button</FIELD_TMP>")) {
carlos@0
    69
        <FIELD_TMP id="FieldsLoad3">String strField = vars.getStringParameter("inpFields");</FIELD_TMP>
carlos@0
    70
        String strProcessing = vars.getStringParameter("inpprocessing");
carlos@0
    71
        String pinstance = SequenceIdData.getSequence(this, "AD_PInstance", vars.getClient());
carlos@0
    72
        PInstanceProcessData.insertPInstance(this, pinstance, "<FIELD_TMP id="ProcessID3">button</FIELD_TMP>", "0", strProcessing, vars.getUser(), vars.getClient(), vars.getOrg());
carlos@0
    73
        <FIELD_TMP id="FieldsLoadParams3">PInstanceProcessData.insertPInstanceParam(this, pinstance, )</FIELD_TMP>
carlos@0
    74
        <FIELD_TMP id="AdditionalCode3">code</FIELD_TMP>
carlos@0
    75
        <FIELD_TMP id="ProcessCode3">ActionButtonData.processxx(this, pinstance);</FIELD_TMP>
carlos@0
    76
carlos@0
    77
        processButtonHelper(response, vars, pinstance);        
carlos@0
    78
</FIELDS_TMP>
carlos@0
    79
    } else pageErrorPopUp(response);
carlos@0
    80
  }
carlos@0
    81
carlos@0
    82
  void printPageDefault(HttpServletResponse response, VariablesSecureApp vars, String strProcessId) throws IOException, ServletException {
carlos@0
    83
    log4j.debug("Output: Default");
carlos@0
    84
    response.setContentType("text/html; charset=UTF-8");
carlos@0
    85
    PrintWriter out = response.getWriter();
carlos@0
    86
    XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/ActionButtonDefault").createXmlDocument();
carlos@0
    87
    xmlDocument.setParameter("processId", strProcessId);
carlos@0
    88
carlos@0
    89
    out.println(xmlDocument.print());
carlos@0
    90
    out.close();
carlos@0
    91
  }
carlos@0
    92
carlos@0
    93
  void printPageResponse(HttpServletResponse response, VariablesSecureApp vars, String strMessage) throws IOException, ServletException {
carlos@0
    94
    log4j.debug("Output: Default");
carlos@0
    95
    response.setContentType("text/html; charset=UTF-8");
carlos@0
    96
    PrintWriter out = response.getWriter();
carlos@0
    97
    XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/ActionButtonResponse").createXmlDocument();
carlos@0
    98
    xmlDocument.setParameter("message", (strMessage.equals("")?"":"alert('" + Replace.replace(strMessage, "\"", "") + "');"));
carlos@0
    99
carlos@0
   100
    out.println(xmlDocument.print());
carlos@0
   101
    out.close();
carlos@0
   102
  }
carlos@0
   103
carlos@0
   104
carlos@0
   105
<FIELDS_TMP id="sectionActionButtons2">    void printPageButton<FIELD_TMP id="ProcessID2">xx</FIELD_TMP>(HttpServletResponse response, VariablesSecureApp vars<FIELD_TMP id="FieldsLoadName2">, strFields</FIELD_TMP>)
carlos@0
   106
    throws IOException, ServletException {
carlos@0
   107
      log4j.debug("Output: Button process <FIELD_TMP id="ProcessID2">xx</FIELD_TMP>");
carlos@0
   108
      String[] discard = {"newDiscard"};
carlos@0
   109
      response.setContentType("text/html; charset=UTF-8");
carlos@0
   110
      PrintWriter out = response.getWriter();
carlos@0
   111
      XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/ActionButton<FIELD_TMP id="ButtonProcessId2">name</FIELD_TMP>", discard).createXmlDocument();
carlos@0
   112
      xmlDocument.setParameter("processing", "Y");
carlos@0
   113
      xmlDocument.setParameter("form", "ActionButton_Responser.html");
carlos@0
   114
      xmlDocument.setParameter("css", vars.getTheme());
juanpablo@1605
   115
      xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
juanpablo@1605
   116
      xmlDocument.setParameter("language", "defaultLang = \"" + vars.getLanguage() + "\";\n");
carlos@0
   117
      xmlDocument.setParameter("cancel", Utility.messageBD(this, "Cancel", vars.getLanguage()));
carlos@0
   118
      xmlDocument.setParameter("ok", Utility.messageBD(this, "OK", vars.getLanguage()));
carlos@0
   119
      
carlos@0
   120
      {
carlos@0
   121
        OBError myMessage = vars.getMessage("<FIELD_TMP id="ProcessID2">xx</FIELD_TMP>");
carlos@0
   122
        vars.removeMessage("<FIELD_TMP id="ProcessID2">xx</FIELD_TMP>");
carlos@0
   123
        if (myMessage!=null) {
carlos@0
   124
          xmlDocument.setParameter("messageType", myMessage.getType());
carlos@0
   125
          xmlDocument.setParameter("messageTitle", myMessage.getTitle());
carlos@0
   126
          xmlDocument.setParameter("messageMessage", myMessage.getMessage());
carlos@0
   127
        }
carlos@0
   128
      }
carlos@0
   129
carlos@0
   130
      <FIELD_TMP id="JavaCode2">javaCode</FIELD_TMP>
carlos@0
   131
      out.println(xmlDocument.print());
carlos@0
   132
      out.close();
carlos@0
   133
    }
carlos@0
   134
</FIELDS_TMP>
carlos@0
   135
carlos@0
   136
carlos@0
   137
  public String getServletInfo() {
carlos@0
   138
    return "Servlet ActionButton_Responser. This Servlet was made by Wad constructor";
carlos@0
   139
  } // end of the getServletInfo() method
carlos@0
   140
carlos@0
   141
  private void processButtonHelper(HttpServletResponse response, VariablesSecureApp vars, String pinstance) 
carlos@0
   142
     throws ServletException, IOException {
carlos@0
   143
      OBError myMessage;
carlos@0
   144
      try {
carlos@0
   145
        PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, pinstance);
carlos@0
   146
      myMessage = Utility.getProcessInstanceMessage(this, vars, pinstanceData);
carlos@0
   147
      } catch (Exception e) {
carlos@0
   148
          myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
carlos@0
   149
          e.printStackTrace();
carlos@0
   150
          log4j.warn("Error");
carlos@0
   151
      }
carlos@0
   152
      advisePopUp(response, myMessage.getType(), myMessage.getTitle(), myMessage.getMessage());
carlos@0
   153
  }
carlos@0
   154
}
carlos@0
   155
</java_TMP>