This commit is contained in:
rob_k 2007-06-11 03:41:08 +00:00
parent aa5a2787ff
commit 3e784b198f
19 changed files with 3329 additions and 360 deletions

View File

@ -48,7 +48,7 @@ public class Test extends HttpServlet
{
WebDoc doc = WebDoc.create ("Get Request Test");
//
WebUtil.createResponse(request, response, this, null, doc, true);
WebUtil.createResponse(request, response, this, null, doc, false);
} // doGet
@ -60,7 +60,7 @@ public class Test extends HttpServlet
{
WebDoc doc = WebDoc.create ("Post Request Test");
//
WebUtil.createResponse(request, response, this, null, doc, true);
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
} // Test

View File

@ -55,7 +55,7 @@ public class Test2 extends HttpServlet
{
WebDoc doc = WebDoc.create ("Get Request Test2");
//
WebUtil.createResponse(request, response, this, null, doc, true);
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
} // Test2

View File

@ -84,8 +84,9 @@ public class WAccount extends HttpServlet
String columnName = WebUtil.getParameter (request, "ColumnName");
//
GridField mField = ws.curTab.getField(columnName);
log.config("FormName=" + formName + ", ColumnName=" + columnName + ", MField=" + mField.toString());
if (mField == null || formName == null || columnName == null || formName.equals("") || columnName.equals(""))
//Modified by Rob Klein 4/29/07
log.config("FormName=" + formName + ", ColumnName=" + columnName + ", MField=" + mField.toString());
if (mField == null || columnName == null || columnName.equals(""))
{
WebUtil.createTimeoutPage(request, response, this,
Msg.getMsg(wsc.ctx, "ParameterMissing"));
@ -93,20 +94,21 @@ public class WAccount extends HttpServlet
}
// Object value = ws.curTab.getValue(columnName);
String target = "opener.document." + formName + "." + columnName;
String targetBase = "'" + columnName;
//Modifeid by Rob Klein 4/229/07
// Create Document
WebDoc doc = WebDoc.create (mField.getHeader());
WebDoc doc = WebDoc.createPopup (mField.getHeader());
body body = doc.getBody();
body.setOnBlur("self.focus();");
body.addElement(fillTable(ws, mField, target));
body.addElement(fillTable(ws, mField, targetBase));
//Modified by Rob Klein 4/29/07
// Reset, Cancel
button reset = new button();
reset.addElement("Reset"); // translate
reset.setOnClick(target + ".value='';" + target + "_D.value='';window.close();");
reset.setOnClick(targetBase + "F.value='';" + targetBase + "D.value='';self.close();");
button cancel = new button();
cancel.addElement("Cancel"); // translate
cancel.setOnClick("window.close();");
cancel.setOnClick("self.close();return false;");
body.addElement(new p(AlignType.RIGHT)
.addElement(reset)
.addElement("&nbsp")
@ -144,10 +146,15 @@ public class WAccount extends HttpServlet
private table fillTable (WWindowStatus ws, GridField mField, String target)
{
table table = new table("1");
//Modified by Rob klein 4/29/07
table.setClass("table-autosort table-autostripe table-stripeclass:alternate");
table.addElement("<thead>");
tr line = new tr();
line.addElement(new th("&nbsp")).addElement(new th(Msg.translate(ws.ctx, "Name")));
line.addElement(new th("&nbsp")).addElement(new th(Msg.translate(ws.ctx, "Name")).setClass("table-sortable:default"));
table.addElement(line);
table.addElement("</thead>");
table.addElement("<tbody>");
// Fill & list options
Lookup lookup = mField.getLookup();
lookup.fillComboBox(mField.isMandatory(false), true, true, true); // no context check
@ -162,10 +169,15 @@ public class WAccount extends HttpServlet
KeyNamePair np = (KeyNamePair)lValue;
button button = new button();
button.addElement("&gt;");
StringBuffer script = new StringBuffer(target);
script.append(".value='").append(np.getKey()).append("';")
.append(target).append("_D.value='").append(np.getName()).append("';window.close();");
button.setOnClick(script.toString());
//Modified by Rob Klein 4/29/07
StringBuffer script = new StringBuffer();
script
//.append("';closePopup();")
.append("startUpdate(").append(target).append("F',")
.append(target).append("D','").append(np.getKey()).append("',")
.append(target).append("F','").append(np.getName())
.append("');return false;");
button.setOnClick(script.toString());
//
line = new tr();
line.addElement(new td(button));
@ -177,6 +189,7 @@ public class WAccount extends HttpServlet
}
// Restore
lookup.fillComboBox(true);
table.addElement("</tbody>");
return table;
} // fillTable

View File

@ -69,7 +69,8 @@ public class WAttachment extends HttpServlet
if (session == null || ws == null)
{
doc = WebDoc.createPopup ("No Context");
doc.addPopupClose();
//Modified by Rob Klein 4/29/07
doc.addPopupClose(ws.ctx);
}
else
{
@ -192,7 +193,8 @@ public class WAttachment extends HttpServlet
table.addElement(tr);
// Footer
doc.addPopupClose();
//Modified by Rob Klein 4/29/07
doc.addPopupClose(ctx);
//
// System.out.println(doc);
return doc;

View File

@ -0,0 +1,289 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.www;
import java.io.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.ecs.AlignType;
import org.apache.ecs.Element;
import org.apache.ecs.xhtml.b;
import org.apache.ecs.xhtml.form;
import org.apache.ecs.xhtml.hr;
import org.apache.ecs.xhtml.input;
import org.apache.ecs.xhtml.p;
import org.apache.ecs.xhtml.table;
import org.apache.ecs.xhtml.td;
import org.apache.ecs.xhtml.textarea;
import org.apache.ecs.xhtml.tr;
import org.compiere.apps.AChat;
import org.compiere.model.GridField;
import org.compiere.model.MChat;
import org.compiere.model.MChatEntry;
import org.compiere.model.MUser;
import org.compiere.util.*;
/**
* Web (window) Chat
*
* @author Jorg Janke
* @version $Id: WChat.java $
*/
public class WChat extends HttpServlet
{
/** Logger */
protected CLogger log = CLogger.getCLogger(getClass());
private MChat m_chat;
private boolean m_readOnly;
private boolean m_hasDependents;
private boolean m_hasCallout;
private int m_displayLength;
private String m_columnName;
/**
* Initialize global variables
*/
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
if (!WebEnv.initWeb(config))
throw new ServletException("WChat.init");
} // init
/**
* Process the HTTP Get request
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
log.fine("doGet");
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
//
WebDoc doc = null;
if (ws == null)
{
doc = WebDoc.createPopup("No Context");
doc.addPopupClose(wsc.ctx);
}
else
{
doc = CreateChatPage (ws, wsc, doc, 0 );
}
//
WebUtil.createResponse(request, response, this, null, doc, false);
} // doGet
/**
* Process the HTTP Post request
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
WebDoc doc = null;
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
String data = WebUtil.getParameter(request, "chatinput");
int CM_ChatID = WebUtil.getParameterAsInt(request, "CM_ChatID");
int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
int record_ID = WebUtil.getParameterAsInt(request, "record_ID");
String description = WebUtil.getParameter(request, "description");
if (data != null && data.length() > 0)
{
if (CM_ChatID == 0){
m_chat = new MChat (wsc.ctx, AD_Table_ID, record_ID, description, null);
m_chat.save();
}
MChatEntry entry = new MChatEntry(m_chat, data);
entry.save();
} // data to be saved
doc = CreateChatPage (ws, wsc, doc, m_chat.getCM_Chat_ID());
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
/**
* Create Text Field
* @param data initial value
* @param rows no of rows
* @return td
*/
private td getTextField (String data, int rows)
{
textarea text = new textarea (m_columnName, rows, m_displayLength)
.addElement(Util.maskHTML(data));
text.setID(m_columnName + "F");
text.setName(m_columnName);
text.setDisabled(m_readOnly);
//
if (m_hasDependents || m_hasCallout)
text.setOnChange("startUpdate(this);");
return createTD(text);
}
/**
* Create Left Top aligned TD
* @param element element
* @return td table data
*/
private td createTD (Element element)
{
td td = new td()
.addElement(element)
.setAlign(AlignType.LEFT)
.setVAlign(AlignType.TOP);
td.setColSpan(3);
return td;
} // createTD
/**
* Create Left Top aligned TD
* @param element element
* @return td table data
*/
private WebDoc CreateChatPage (WWindowStatus ws, WebSessionCtx wsc, WebDoc doc, int CM_Chat_ID)
{
doc = WebDoc.createPopup ("Chat ");
td center = doc.addWindowCenter(false);
int record_ID = ws.curTab.getRecord_ID();
log.info("Record_ID=" + record_ID);
if (record_ID == -1) // No Key
{
log.info("Record does not exist");
return doc;
}
// Find display
String infoName = null;
String infoDisplay = null;
for (int i = 0; i < ws.curTab.getFieldCount(); i++)
{
GridField field = ws.curTab.getField(i);
if (field.isKey())
infoName = field.getHeader();
if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo") )
&& field.getValue() != null)
infoDisplay = field.getValue().toString();
if (infoName != null && infoDisplay != null)
break;
}
String description = infoName + ": " + infoDisplay;
//
if (ws.curTab.getCM_ChatID() > 0)
m_chat = new MChat (wsc.ctx, ws.curTab.getCM_ChatID(), null);
else if (CM_Chat_ID > 0)
m_chat = new MChat (wsc.ctx, CM_Chat_ID, null);
else
m_chat = new MChat (wsc.ctx, ws.curTab.getAD_Table_ID(), record_ID, description, null);
String text = m_chat.getHistory(MChat.CONFIDENTIALTYPE_Internal).toString();
form myForm = new form ("WChat")
.setName("chat");
myForm.setOnSubmit("this.Submit.disabled=true;return true;");
if (CM_Chat_ID==0)
myForm.addElement(new input(input.TYPE_HIDDEN, "CM_ChatID", ws.curTab.getCM_ChatID()));
else
myForm.addElement(new input(input.TYPE_HIDDEN, "CM_ChatID", CM_Chat_ID));
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Table_ID", ws.curTab.getAD_Table_ID()));
myForm.addElement(new input(input.TYPE_HIDDEN, "record_ID", record_ID));
myForm.addElement(new input(input.TYPE_HIDDEN, "description", description));
table myTable = new table("0", "0", "5", "100%", null);
myTable.setID("WChatParameter");
m_displayLength = 80;
//history field
myTable.addElement(new tr()
.addElement( new td("History")));
m_readOnly = true;
table HistoryTable = new table("1", "0", "5", "100%", null);
HistoryTable.addElement(new tr()
.addElement( new td(text)
.setRowSpan(10)
.setAlign(AlignType.LEFT)
.setVAlign(AlignType.TOP)
.setColSpan(4)));
myTable.addElement(HistoryTable);
//input field
myTable.addElement(new tr()
.addElement( new td("Input")));
m_readOnly = false;
m_columnName = "chatinput";
myTable.addElement(new tr()
.addElement(getTextField ("", 10)));
// Reset
String textbtn = "Reset";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Reset");
input restbtn = new input(input.TYPE_RESET, textbtn, " "+text);
restbtn.setID(text);
restbtn.setClass("resetbtn");
// Submit
textbtn = "Submit";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Submit");
input submitbtn = new input(input.TYPE_SUBMIT, textbtn, " "+text);
submitbtn.setID(text);
submitbtn.setClass("submitbtn");
// Close
textbtn = "Close";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Close");
input closebtn = new input(input.TYPE_SUBMIT, textbtn, " "+text);
closebtn.setID(text);
closebtn.setClass("closebtn");
closebtn.setOnClick ("self.close();return false;");
myTable.addElement(new tr()
.addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false,
restbtn))
.addElement(new td(null, AlignType.CENTER, AlignType.MIDDLE, false,
submitbtn ))
.addElement(new td(null, AlignType.LEFT, AlignType.MIDDLE, false,
closebtn)));
myForm.addElement(myTable);
center.addElement(myForm);
return doc;
}
} // WReport

View File

@ -57,7 +57,8 @@ public class WHelp extends HttpServlet
if (ws == null)
{
doc = WebDoc.createPopup("No Context");
doc.addPopupClose();
//Modified by Rob Klein 4/29/07
doc.addPopupClose(Env.getCtx());
}
else
doc = ws.mWindow.getHelpDoc(false);

View File

@ -113,7 +113,8 @@ public class WLocation extends HttpServlet
String action = request.getRequestURI();
// Create Document
WebDoc doc = WebDoc.createPopup (mField.getHeader());
doc.addPopupClose();
//Modified by Rob klein 4/29/07
doc.addPopupClose(ws.ctx);
boolean hasDependents = ws.curTab.hasDependants(columnName);
boolean hasCallout = mField.getCallout().length() > 0;
@ -128,8 +129,8 @@ public class WLocation extends HttpServlet
doc.getTable().addElement(new tr()
.addElement(fillForm(ws, action, location, targetBase, hasDependents || hasCallout))
.addElement(reset));
//
doc.addPopupClose();
//Modified by Rob Klein 4/29/07
doc.addPopupClose(ws.ctx);
// log.trace(log.l6_Database, doc.toString());
WebUtil.createResponse (request, response, this, null, doc, false);
} // doGet
@ -170,7 +171,8 @@ public class WLocation extends HttpServlet
// Document
WebDoc doc = WebDoc.createPopup ("WLocation");
doc.addPopupClose();
//Modified by Rob Klein 4/29/07
doc.addPopupClose(ws.ctx);
// Save Location
location.save();

View File

@ -192,7 +192,7 @@ public class WLogin extends HttpServlet
}
}
}
WebUtil.createResponse (request, response, this, cProp, doc, true);
WebUtil.createResponse (request, response, this, cProp, doc, false);
} // doPost
// Variable Names
@ -234,11 +234,15 @@ public class WLogin extends HttpServlet
String action = request.getRequestURI();
form myForm = null;
myForm = new form(action).setName("Login1");
table table = new table().setAlign(AlignType.CENTER);
table table = new table().setAlign(AlignType.CENTER).setWidth("25%");
//Modified by Rob Klein 4/29/07
// Blank Line
tr line = new tr();
line.addElement(new td().addElement(" "));
// Username
String userData = cProp.getProperty(P_USERNAME, "");
tr line = new tr();
line = new tr();
label usrLabel = new label().setFor(P_USERNAME + "F").addElement(usrText);
usrLabel.setID(P_USERNAME + "L");
line.addElement(new td().addElement(usrLabel).setAlign(AlignType.RIGHT));
@ -276,7 +280,7 @@ public class WLogin extends HttpServlet
options[i].setSelected(false);
}
line.addElement(new td().addElement(new select(Env.LANGUAGE, options)
.setID(Env.LANGUAGE + "F") ));
.setID(Env.LANGUAGE + "F")));
table.addElement(line);
// Store Cookie
@ -300,18 +304,32 @@ public class WLogin extends HttpServlet
// Finish
line = new tr();
input cancel = new input(input.TYPE_RESET, "Reset", cancelText);
line.addElement(new td().addElement(cancel ));
line.addElement(new td().addElement(new input(input.TYPE_SUBMIT, P_SUBMIT, okText) ));
table.addElement(line);
//Modified by Rob Klein 4/29/07
table tablebutton = new table().setAlign(AlignType.CENTER).setWidth("25%");
input cancel = new input(input.TYPE_RESET, "Reset", " "+"Cancel");
cancel.setClass("cancelbtn");
line.addElement(new td().addElement(cancel).setWidth("50%")).setAlign(AlignType.CENTER);
input submit = new input(input.TYPE_SUBMIT, P_SUBMIT, " "+"OK");
submit.setClass("loginbtn");
line.addElement(new td().addElement(submit).setWidth("50%").setAlign(AlignType.CENTER));
tablebutton.addElement(line);
table.addElement(tablebutton);
//
myForm.addElement(table);
// Document
WebDoc doc = WebDoc.createWindow (windowTitle);
doc.addWindowCenter(true)
.addElement(new h3("The HTML UI is Beta Functionality!"))
.addElement(myForm);
//Modified by Rob Klein 4/29/07
img img = new img (WebEnv.getImageDirectory("Logo.gif"), "logo");
doc.addWindowCenter(true)
.addElement(img)
.addElement(new p())
.addElement(new p())
//.addElement(new h3("The HTML UI is Beta Functionality!"))
//.addElement(myForm)
.addElement(myForm)
.addElement(new p())
.addElement(new p());
// Clear Menu Frame
doc.getBody()
.addElement(WebUtil.getClearFrame(WebEnv.TARGET_MENU))
@ -344,6 +362,10 @@ public class WLogin extends HttpServlet
// Role Pick
tr line = new tr();
//Modified by Rob Klein 4/29/07
line.addElement(new td().addElement(" "));
table.addElement(line);
line = new tr();
label roleLabel = new label().setFor(P_ROLE + "F").addElement(Msg.translate(wsc.language, "AD_Role_ID"));
roleLabel.setID(P_ROLE + "L");
line.addElement(new td().addElement(roleLabel).setAlign(AlignType.RIGHT));
@ -403,23 +425,37 @@ public class WLogin extends HttpServlet
line.addElement(new td().addElement(new strong(errorMessage)).setColSpan(2).setAlign(AlignType.CENTER));
table.addElement(line);
}
// Finish
//Modified by Rob Klein 4/29/07
// Finish
table tablebutton = new table().setAlign(AlignType.CENTER).setWidth("25%");
line = new tr();
input cancel = new input(input.TYPE_RESET, "Reset", Msg.getMsg(wsc.language, "Cancel"));
line.addElement(new td().addElement(cancel ));
input submit = new input(input.TYPE_SUBMIT, "Submit", Msg.getMsg(wsc.language, "OK"));
//Modified by Rob Klein 4/29/07
//input cancel = new input(input.TYPE_RESET, "Reset", Msg.getMsg(wsc.language, "Cancel"));
input cancel = new input(input.TYPE_RESET, "Reset", " "+ "Cancel");
cancel.setOnClick("window.top.location.replace('/adempiere/index.html');");
cancel.setClass("cancelbtn");
line.addElement(new td().addElement(cancel).setWidth("50%").setAlign(AlignType.CENTER));
input submit = new input(input.TYPE_SUBMIT, "Submit", " "+ "OK");
submit.setOnClick("showLoadingMenu('" + WebEnv.getBaseDirectory("") + "');");
line.addElement(new td().addElement(submit));
table.addElement(line);
//Modified by Rob Klein 4/29/07
submit.setClass("loginbtn");
line.addElement(new td().addElement(submit).setWidth("50%").setAlign(AlignType.CENTER));
tablebutton.addElement(line);
table.addElement(tablebutton);
//
myForm.addElement(table);
// Create Document
WebDoc doc = WebDoc.createWindow (windowTitle);
//Modified by Rob Klein 4/29/07
img img = new img (WebEnv.getImageDirectory("Logo.gif"), "logo");
doc.addWindowCenter(true)
.addElement(new h3("The HTML UI is Beta Functionality!"))
.addElement(myForm);
.addElement(img)
.addElement(new p())
//.addElement(new h3("The HTML UI is Beta Functionality!"))
.addElement(myForm)
.addElement(new p())
.addElement(new p());
//
String script = "fieldUpdate(document.Login2." + P_ROLE + ");"; // init dependency updates
doc.getBody()

View File

@ -17,9 +17,18 @@
package org.compiere.www;
import java.io.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.ecs.AlignType;
import org.apache.ecs.xhtml.*;
import org.compiere.grid.ed.VLookup;
import org.compiere.model.*;
import org.compiere.util.*;
@ -45,6 +54,12 @@ public class WLookup extends HttpServlet
/** Logger */
protected static CLogger log = CLogger.getCLogger(WLookup.class);
/** The Data List */
protected volatile ArrayList<Object> p_data = new ArrayList<Object>();
private StringBuffer HeaderSelect = null;
/**
* Initialize global variables
*
@ -72,8 +87,11 @@ public class WLookup extends HttpServlet
{
WebEnv.dump(request);
WebEnv.dump(request.getSession());
//Modified by Rob Klein 4/29/07
//
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
if (ws == null)
{
WebUtil.createTimeoutPage(request, response, this, null);
@ -81,45 +99,106 @@ public class WLookup extends HttpServlet
}
// Get Mandatory Parameters
String columnName = WebUtil.getParameter (request, "ColumnName");
log.info ("ColumnName=" + columnName + " - " + ws.toString());
//
GridField mField = ws.curTab.getField(columnName);
log.config("ColumnName=" + columnName
+ ", MField=" + mField);
if (mField == null || columnName == null
|| columnName.equals(""))
{
WebUtil.createErrorPage(request, response, this,
Msg.getMsg(ws.ctx, "ParameterMissing"));
return;
}
// parent = framesetWindow
// Label - Dtata - Field - Button
String targetBase = "parent.WWindow." + WWindow.FORM_NAME + "." + columnName;
// Object value = ws.curTab.getValue(columnName);
// Create Document
WebDoc doc = WebDoc.createPopup (mField.getHeader());
doc.addPopupClose();
boolean hasDependents = ws.curTab.hasDependants(columnName);
boolean hasCallout = mField.getCallout().length() > 0;
//Lookup called from a process
//Modified by Rob Klein 4/29/07
int AD_Process_ID = WebUtil.getParameterAsInt(request, "AD_Process_ID");
// Reset
button reset = new button();
reset.addElement("Reset"); // translate
String script = targetBase + "F.value='';" + targetBase + "D.value='';closePopup();";
if (hasDependents || hasCallout)
script += "startUpdate(" + targetBase + "F);";
reset.setOnClick(script);
//
doc.getTable().addElement(new tr()
.addElement(fillTable(ws, mField, targetBase, hasDependents || hasCallout))
.addElement(reset));
//
doc.addPopupClose();
// log.trace(log.l6_Database, doc.toString());
WebUtil.createResponse (request, response, this, null, doc, false);
if (mField == null)
{
AD_Process_ID = WebUtil.getParameterAsInt(request, "AD_Process_ID");
if (AD_Process_ID < 1 || columnName == null
|| columnName.equals(""))
{
WebUtil.createErrorPage(request, response, this,
Msg.getMsg(ws.ctx, "ParameterMissing"));
return;
}
String targetBase = "'" + columnName;
MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
MProcessPara para = null;
MProcessPara[] parameter = process.getParameters();
for (int i = 0; i < parameter.length; i++)
{
para = parameter[i];
if (para.getColumnName().equals(columnName))
i=parameter.length;
}
// Create Document
WebDoc doc = WebDoc.createPopup (para.getColumnName());
// Reset
String text = "Reset";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Reset");
input button = new input("button", text, " "+text);
button.setID(text);
button.setClass("resetbtn");
String script = targetBase + "F.value='';" + targetBase + "D.value='';closePopup();";
button.setOnClick(script);
//
doc.getTable().addElement(new tr()
.addElement(fillTable(wsc, ws, para.getColumnName(), para.getAD_Reference_Value_ID(), request.getRequestURI(),targetBase,false))
.addElement(button));
//
doc.addPopupClose(ws.ctx);
// log.trace(log.l6_Database, doc.toString());
WebUtil.createResponse (request, response, this, null, doc, false);
}
//Lookup called from a window
else{
log.config("ColumnName=" + columnName
+ ", MField=" + mField);
if (mField == null || columnName == null
|| columnName.equals(""))
{
WebUtil.createErrorPage(request, response, this,
Msg.getMsg(ws.ctx, "ParameterMissing"));
return;
}
// parent = framesetWindow
// Label - Dtata - Field - Button
String targetBase = "'" + columnName;
// Create Document
WebDoc doc = WebDoc.createPopup (mField.getHeader());
boolean hasDependents = ws.curTab.hasDependants(columnName);
boolean hasCallout = mField.getCallout().length() > 0;
// Reset
// Reset
String text = "Reset";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Reset");
input restbtn = new input(input.TYPE_RESET, text, " "+text);
restbtn.setID(text);
restbtn.setClass("resetbtn");
String script = targetBase + "F.value='';" + targetBase + "D.value='';self.close();";
if (hasDependents || hasCallout)
script += "startUpdate(" + targetBase + "F);";
restbtn.setOnClick(script);
//
doc.getTable().addElement(new tr()
.addElement(fillTable(wsc, ws, mField.getColumnName(), mField.getAD_Reference_Value_ID(), request.getRequestURI(),targetBase, hasDependents || hasCallout))
.addElement(restbtn));
//
doc.addPopupClose(ws.ctx);
// log.trace(log.l6_Database, doc.toString());
WebUtil.createResponse (request, response, this, null, doc, false);
}
} // doGet
@ -137,7 +216,7 @@ public class WLookup extends HttpServlet
doGet(request, response);
} // doPost
//Modified by Rob Klein 4/29/07
/**************************************************************************
* Fill Table (Generic)
*
@ -147,8 +226,8 @@ public class WLookup extends HttpServlet
* @param addStart add startUpdate
* @return Table with selection
*/
private table fillTable (WWindowStatus ws, GridField mField,
String targetBase, boolean addStart)
private table fillTable (WebSessionCtx wsc, WWindowStatus ws, String columnName, int fieldRefId,
String action,String targetBase, boolean addStart)
{
/**
if (mField.getColumnName().equals("C_BPartner_ID"))
@ -156,63 +235,217 @@ public class WLookup extends HttpServlet
else if (mField.getColumnName().equals("M_Product_ID"))
return fillTable_Product (ws, mField, target);
**/
//
table table = new table("1"); // Border 1
table.setID("WLookup");
tr line = new tr();
line.addElement(new th("&nbsp")).addElement(new th(Msg.translate(ws.ctx, "Name")));
table.addElement(line);
Lookup lookup = mField.getLookup();
log.info(mField.getColumnName());
table table = new table("1"); // Border 1
table.setID("WLookup");
table.setClass("MultiRow table-autofilter table-filterable table-autosort table-autostripe table-stripeclass:alternate");
table.addElement("<thead>");
tr line = new tr();
// Fill & list options
lookup.fillComboBox(mField.isMandatory(false), true, true, true); // no context check
int size = lookup.getSize();
for (int i = 0; i < size; i++)
{
Object lValue = lookup.getElementAt(i);
if (!(lValue != null && lValue instanceof KeyNamePair))
continue;
//
// log.trace(log.l6_Database, lValue.toString());
KeyNamePair np = (KeyNamePair)lValue;
button button = new button();
button.addElement("&gt;");
StringBuffer script = new StringBuffer();
script.append(targetBase).append("D.value='").append(np.getKey()).append("';")
.append(targetBase).append("F.value='").append(np.getName())
.append("';closePopup();");
if (addStart)
script.append("startUpdate(").append(targetBase).append("F);");
button.setOnClick(script.toString());
//
line = new tr();
line.addElement(new td(button));
String name = np.getName();
if (name == null || name.length() == 0)
name = "&nbsp";
line.addElement(new td(name));
table.addElement(line);
}
// Restore
lookup.fillComboBox(true);
// Set Headers
line.addElement(new th("&nbsp")).
addElement(new th(Msg.translate(ws.ctx, "Key Name")).setClass("table-filterable table-filtered table-sortable:default"));
line = fillTable_Lookup_Headers(ws, columnName, fieldRefId, line, targetBase, true, true, true, false, true);
table.addElement(line);
tr line2 = new tr();
line2.addElement(new th("&nbsp")).addElement(new th("&nbsp"));
line2 = fillTable_Lookup_Headers(ws, columnName, fieldRefId, line2, targetBase, true, true, true, false, false);
table.addElement(line2);
table.addElement("</thead>");
table.addElement("<tbody>");
// Fillout rows
table = fillTable_Lookup_Rows(ws, columnName, fieldRefId, table, targetBase, true, true, true, false);
table.addElement("</tbody>");
// Restore
return table;
} // fillTable
//Modified by Rob Klein 4/29/07
/**************************************************************************
* Fill Table BPartner
* Fill Table Lookup
*
* @param ws WindowStatus
* @param mField the Field
* @param targetBase target field string
* @return Table with selection
* @return Lookup Rows in List Format
*/
private table fillTable_BPartner (WWindowStatus ws, GridField mField, String targetBase)
{
return null;
} // fillTable_BPartner
private table fillTable_Lookup_Rows (WWindowStatus ws, String columnName, int fieldRefId,
table table1, String targetBase, boolean mandatory, boolean onlyValidated, boolean onlyActive,
boolean temporary)
{
ArrayList<Object> list = new ArrayList<Object>();
StringBuffer sqlSelect = null;
StringBuffer sqlSelectDetail = null;
int size = 0;
int colCount = 0;
if (!mandatory)
list.add(new KeyNamePair (-1, ""));
StringBuffer sql = null;
if (fieldRefId > 0){
sql = new StringBuffer ("SELECT AD_Display, AD_Key, AD_Table_ID, WhereClause, OrderByClause "
+ "FROM AD_Ref_Table WHERE AD_Reference_ID = "+fieldRefId);
int nameID = 0;
int keyID = 0;
int tableID = 0;
String whereClause = null;
String orderBy = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
ResultSet rs = pstmt.executeQuery();
size=2;
while (rs.next()){
nameID = rs.getInt(1);
keyID = rs.getInt(2);
tableID = rs.getInt(3);
whereClause = rs.getString(4);
orderBy = rs.getString(5);
}
String sql1 = "Select ColumnName FROM AD_Column Where AD_Column_ID = ? AND AD_Table_ID = "+tableID;
sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID);
colCount = DB.getSQLValue(null, sql.toString());
String name = DB.getSQLValueString(null, sql1 , nameID);
String key = DB.getSQLValueString(null, sql1 , keyID);
sqlSelect = new StringBuffer ("SELECT "+key+", "+name);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sqlSelect.toString(), e);
}
String sql1 = "Select TableName FROM AD_Table Where AD_Table_ID = ?";
String tableName = DB.getSQLValueString(null, sql1 , tableID);
sqlSelect.append(" FROM " + tableName + " WHERE AD_Client_ID=?");
sqlSelectDetail = HeaderSelect.append(" FROM " + tableName + " WHERE "+columnName+" = ?");
if (whereClause != null){
sqlSelect.append(" AND " + whereClause);
sqlSelectDetail.append(" AND " + whereClause);
}
if (orderBy != null){
sqlSelect.append(" ORDER BY " + orderBy);
sqlSelectDetail.append(" ORDER BY " + orderBy);
}
}
else{
//direct select as indicated below
sql = new StringBuffer ("SELECT AD_Table_ID "
+ "FROM AD_Table WHERE TableName = '"+columnName.replace("_ID", "")+"'");
int tableID = DB.getSQLValue(null, sql.toString());
sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID);
colCount = DB.getSQLValue(null, sql.toString());
sql = new StringBuffer ("SELECT ColumnName "
+ "FROM AD_Column WHERE IsIdentifier = 'Y' AND "
+ "AD_Table_ID= "+tableID
+ " ORDER BY SeqNo");
sqlSelect = new StringBuffer ("SELECT "+columnName+", ");
size=1;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
if (size>1)
sqlSelect.append(", ");
sqlSelect.append(rs.getObject(1));
size++;
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sqlSelect.toString(), e);
}
sqlSelect.append(" FROM " + columnName.replace("_ID", "") + " WHERE AD_Client_ID=?");
sqlSelectDetail = HeaderSelect.append(" FROM " + columnName.replace("_ID", "") + " WHERE "+columnName+" = ?");
}
try
{
PreparedStatement pstmt = DB.prepareStatement(sqlSelect.toString(), null);
pstmt.setInt(1, Env.getAD_Client_ID(ws.ctx));
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
StringBuffer name = new StringBuffer ("");
for (int i = 2; i <= size; i++)
{
if (i>2)
name.append("_");
name.append(rs.getObject(i));
}
button button = new button();
button.addElement("&gt;");
StringBuffer script = new StringBuffer();
script
.append("startLookUpdate(").append(targetBase).append("F',")
.append(targetBase).append("D','").append(rs.getObject(1).toString()).append("',")
.append(targetBase).append("F','").append(name.toString())
.append("');startUpdate(").append(targetBase).append("');return false;");
button.setOnClick(script.toString());
//
tr line = new tr();
line.addElement(new td(button));
line.addElement(new td(name.toString()));
try
{
PreparedStatement pstmt1 = DB.prepareStatement(sqlSelectDetail.toString(), null);
pstmt1.setInt(1, rs.getInt(1));
ResultSet rs1 = pstmt1.executeQuery();
while (rs1.next()){
for (int i = 1; i <= colCount; i++)
{
Object fieldRS = rs1.getObject(i);
if (fieldRS == null)
line.addElement(new td("&nbsp;"));
else
line.addElement(new td(rs1.getObject(i).toString()));
}
}
rs1.close();
pstmt1.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
table1.addElement(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
return table1;
} // fillTable_Lookup_Rows
/**
* Fill Table Product
@ -222,9 +455,74 @@ public class WLookup extends HttpServlet
* @param targetBase target field string
* @return Table with selection
*/
private table fillTable_Product (WWindowStatus ws, GridField mField, String targetBase)
private tr fillTable_Lookup_Headers (WWindowStatus ws, String columnName, int fieldRefId,
tr line, String targetBase, boolean mandatory, boolean onlyValidated, boolean onlyActive,
boolean temporary, boolean firstHeaderLine)
{
return null;
StringBuffer sqlSelect = null;
int size = 0;
StringBuffer sql = null;
int colCount = 0;
if (fieldRefId > 0){
sql = new StringBuffer ("SELECT AD_Table_ID "
+ "FROM AD_Ref_Table WHERE AD_Reference_ID = "+fieldRefId);
int tableID = DB.getSQLValue(null, sql.toString());
sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID);
colCount = DB.getSQLValue(null, sql.toString());
sqlSelect = new StringBuffer ("SELECT ColumnName, Name FROM AD_Column WHERE AD_Table_ID="+tableID+" ORDER BY AD_Column_ID");
}
else{
//direct select as indicated below
sql = new StringBuffer ("SELECT AD_Table_ID "
+ "FROM AD_Table WHERE TableName = '"+columnName.replace("_ID", "")+"'");
int tableID = DB.getSQLValue(null, sql.toString());
sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID);
colCount = DB.getSQLValue(null, sql.toString());
sqlSelect = new StringBuffer ("SELECT ColumnName, Name FROM AD_Column WHERE AD_TABLE_ID="+tableID+" ORDER BY AD_Column_ID");
}
if(firstHeaderLine)
HeaderSelect = new StringBuffer ("Select ");
try
{
PreparedStatement pstmt = DB.prepareStatement(sqlSelect.toString(), null);
ResultSet rs = pstmt.executeQuery();
input filter = null;
while (rs.next()){
if(firstHeaderLine){
line.addElement(new th(rs.getString(2)).setClass("table-filterable table-filtered table-sortable:default"));
HeaderSelect.append(rs.getString(1)+",");
}
else{
th th = new th();
filter = new input (input.TYPE_TEXT, rs.getString(2)+"filter", "");
filter.setOnKeyUp("Table.filter(this,this)");
th.addElement(filter);
line.addElement(th);
}
}
if(firstHeaderLine)
HeaderSelect.setLength(HeaderSelect.length()-1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
return line;
} // fillTable_Product
} // WLookup

View File

@ -139,6 +139,7 @@ public class WMenu extends HttpServlet
throws ServletException, IOException
{
log.fine("doPost - Create Menu");
// Get Session attributes
WebSessionCtx wsc = WebSessionCtx.get(request);
if (wsc == null)
@ -146,6 +147,10 @@ public class WMenu extends HttpServlet
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
//Added by Rob Klein 4/29/07
//Reset WWindow
WebUtil.getClearFrame(WebEnv.TARGET_WINDOW);
// Get Parameters: Role, Client, Org, Warehouse, Date
String role = WebUtil.getParameter (request, WLogin.P_ROLE);
@ -246,8 +251,12 @@ public class WMenu extends HttpServlet
if (!cProp.getProperty(WLogin.P_STORE, "N").equals("Y"))
cProp.clear();
WebDoc doc = createPage (request, wsc, AD_Role_ID);
WebUtil.createResponse (request, response, this, cProp, doc, true);
WebDoc doc = createPage (request, wsc, AD_Role_ID, AD_User_ID, AD_Client_ID, AD_Org_ID);
//Added by Rob Klein 4/29/07
doc.getBody()
.addElement(WebUtil.getClearFrame(WebEnv.TARGET_WINDOW));
WebUtil.createResponse (request, response, this, cProp, doc, false);
//WebUtil.createResponse (request, response, this, cProp, doc, true);
} // doPost
/**
@ -307,9 +316,12 @@ public class WMenu extends HttpServlet
String printer = null;
Login login = new Login(ctx);
login.loadPreferences(org, wh, date, printer);
//Modified by Rob Klein to Show Accounting Tabs 04/29/2007
// Don't Show Acct/Trl Tabs on HTML UI
Env.setContext(ctx, "#ShowAcct", "N");
Env.setContext(ctx, "#ShowTrl", "N");
//Env.setContext(ctx, "#ShowAcct", "N");
//Env.setContext(ctx, "#ShowTrl", "N");
//Env.setContext(ctx, "#ShowAcct", "Y");
//Env.setContext(ctx, "#ShowTrl", "Y");
//
return loginInfo;
} // checkLogin
@ -322,33 +334,39 @@ public class WMenu extends HttpServlet
* @return document
*/
private WebDoc createPage (HttpServletRequest request,
WebSessionCtx wsc, int AD_Role_ID)
WebSessionCtx wsc, int AD_Role_ID, int AD_User_ID, int AD_Client_ID, int AD_Org_ID)
{
// Document
String windowTitle = Msg.getMsg(wsc.ctx, "Menu");
//Modified by Rob Klein 4/29/07
//String windowTitle = Msg.getMsg(wsc.ctx, "Menu");
String windowTitle = "";
WebDoc doc = WebDoc.create (windowTitle);
head head = doc.getHead();
// Target
head.addElement(new base().setTarget(WebEnv.TARGET_WINDOW));
// Specific Menu Script/Stylesheet
head.addElement(new link(WebEnv.getBaseDirectory("menu.css"), link.REL_STYLESHEET, link.TYPE_CSS));
head.addElement(new script((Element)null, WebEnv.getBaseDirectory("menu.js")));
head.addElement(new link(WebEnv.getBaseDirectory("/css/menu.css"), link.REL_STYLESHEET, link.TYPE_CSS));
head.addElement(new script((Element)null, WebEnv.getBaseDirectory("/js/menu.js")));
//Modified by Rob Klein 4/29/07
//head.addElement(new script((Element)null, WebEnv.getBaseDirectory("/js/mktree.js")));
//head.addElement(new link(WebEnv.getBaseDirectory("/css/mktree.css"), link.REL_STYLESHEET, link.TYPE_CSS));
// Scripts
String statusMessage = Msg.getMsg(wsc.ctx, "SelectMenuItem");
String scriptTxt = "top.document.title='" + windowTitle + " - " + wsc.loginInfo + "'; "
+ "var defaultStatus='" + statusMessage + "';";
head.addElement(new script(scriptTxt));
//Rob 12-16-2006 head.addElement(new script(scriptTxt));
// Body
body body = doc.getBody();
body.setTitle(statusMessage);
// Clear Window Frame
body.addElement(WebUtil.getClearFrame(WebEnv.TARGET_WINDOW));
//Rob 12-16-2006 body.addElement(WebUtil.getClearFrame(WebEnv.TARGET_WINDOW));
// Header
table table = doc.getTable();
doc.setClasses ("menuTable", "menuHeader");
doc.getTopLeft().addElement(new cite(wsc.loginInfo));
//Rob 12-16-2006 doc.getTopLeft().addElement(new cite(wsc.loginInfo));
doc.getTopLeft().addElement(new cite(""));
// Load Menu Structure ----------------------
int AD_Tree_ID = DB.getSQLValue(null,
@ -380,12 +398,13 @@ public class WMenu extends HttpServlet
// Print tree
StringBuffer buf = new StringBuffer();
StringBuffer buffav = new StringBuffer();
en = root.preorderEnumeration();
int oldLevel = 0;
while (en.hasMoreElements())
{
MTreeNode nd = (MTreeNode)en.nextElement();
// Level
int level = nd.getLevel(); // 0 == root
if (level == 0)
@ -394,7 +413,7 @@ public class WMenu extends HttpServlet
while (oldLevel < level)
{
if (level == 1)
buf.append("<ul id=\"main\">\n"); // start first level
buf.append("<ul class=\"mktree\" id=\"main\">\n"); // start first level
else
buf.append("<ul style=\"display:none\">\n");// start next level
oldLevel++;
@ -410,6 +429,9 @@ public class WMenu extends HttpServlet
// Print Node
buf.append(printNode(nd, wsc.ctx));
//Modified by Rob Klein 4/29/07
if (nd.isOnBar())
buffav.append(printNode(nd, wsc.ctx));
}
// Final
while (oldLevel > 0)
@ -420,11 +442,30 @@ public class WMenu extends HttpServlet
else
buf.append("</ul></li>\n"); // finish next level
}
//Modified by Rob Klein 4/29/07
// Set Favorites
buf.append("<ul><li class=\"menuSummary\" id=\"218\" onClick=\"changeMenu(event);\">Favorites<ul style=\"display:none\">\n");
buf.append(buffav);
buf.append("</ul></li></ul>\n");
td td = new td().setColSpan(2).setNoWrap(true);
td.setClass("menuCenter");
td.addElement(buf.toString());
table.addElement(new tr().addElement(td));
// Expand/Collapse Info
td = new td().setColSpan(2);
td.setClass("menuFooter");
// Modified by Rob Klein 4/29/07
/**td.addElement(new a("javascript:expandTree('main');", "Expand Menu"));
td.addElement(" | ");
td.addElement( new a("javascript:collapseTree('main');", "Contract Menu"));
table.addElement(new tr().addElement(td));
**/
// Exit Info
td = new td().setColSpan(2);
td.setClass("menuFooter");

View File

@ -20,15 +20,23 @@ import java.io.*;
import java.math.*;
import java.net.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.compiere.apps.ADialog;
//import org.compiere.apps.WProcessCtl;
import org.compiere.grid.ed.VDocAction;
import org.compiere.model.*;
import org.compiere.print.*;
import org.compiere.process.*;
import org.compiere.util.*;
import org.compiere.wf.MWFActivity;
import org.compiere.wf.MWFResponsible;
/**
* HTML Process and Report UI
@ -40,6 +48,11 @@ public class WProcess extends HttpServlet
{
/** Logger */
protected CLogger log = CLogger.getCLogger(getClass());
//Modified by Rob Klein 4/29/07
private String errorMessage = null;
private static String[] s_value = null;
private static String[] s_name;
private static String[] s_description;
/**
* Initialize global variables
@ -66,31 +79,59 @@ public class WProcess extends HttpServlet
throws ServletException, IOException
{
// Get Session attributes
WebSessionCtx wsc = WebSessionCtx.get(request);
//Modified by Rob Klein 4/29/07
WWindowStatus ws = WWindowStatus.get(request);
if (wsc == null)
{
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
//Modified by Rob Klein 4/29/07
if (ws == null)
{
WebUtil.createTimeoutPage(request, response, this, null);
return;
}
WebDoc doc = null;
// Get Parameter: Menu_ID
int AD_Menu_ID = WebUtil.getParameterAsInt(request, "AD_Menu_ID");
//Modified by Rob Klein 4/29/07
int AD_Menu_ID = WebUtil.getParameterAsInt(request, "AD_Menu_ID");
String fileName = WebUtil.getParameter(request, "File");
if (AD_Menu_ID > 0)
{
log.info("doGet - AD_Menu_ID=" + AD_Menu_ID);
doc = createParameterPage(wsc, AD_Menu_ID);
doc = createParameterPage(wsc, AD_Menu_ID,0,0,0,0,null,null);
}
//else if (fileName!=null)
//{
// int AD_PInstance_ID = WebUtil.getParameterAsInt(request, "AD_PInstance_ID");
//
// String error = streamResult (request, response, AD_PInstance_ID, fileName);
// if (error == null)
// return;
// doc = WebDoc.createWindow(error);
//}
else
{
String fileName = WebUtil.getParameter(request, "File");
int AD_PInstance_ID = WebUtil.getParameterAsInt(request, "AD_PInstance_ID");
log.info("doGet - AD_PInstance_ID=" + AD_PInstance_ID
+ ", File=" + fileName);
String error = streamResult (request, response, AD_PInstance_ID, fileName);
if (error == null)
int AD_Process_ID = WebUtil.getParameterAsInt(request, "AD_Process_ID");
int AD_Window_ID = WebUtil.getParameterAsInt(request, "AD_Window_ID");
int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
int AD_Record_ID = WebUtil.getParameterAsInt(request, "AD_Record_ID");
String columnName = WebUtil.getParameter(request, "columnName");
int AD_Tab_ID = WebUtil.getParameterAsInt(request, "AD_Tab_ID");
if (AD_Process_ID == 0)
{
WebUtil.createErrorPage(request, response, this, "No Process");
return;
doc = WebDoc.createWindow(error);
}
doc = createParameterPage(wsc, AD_Process_ID,AD_Window_ID,AD_Table_ID,AD_Record_ID,1,
columnName,ws.curTab);
}
if (doc == null)
doc = WebDoc.createWindow("Process Not Found");
@ -119,102 +160,217 @@ public class WProcess extends HttpServlet
return;
}
int AD_Process_ID = WebUtil.getParameterAsInt(request, "AD_Process_ID");
log.info("doGet - AD_Process_ID=" + AD_Process_ID);
//Modified by Rob Klein 4/29/07
int AD_Window_ID = WebUtil.getParameterAsInt(request, "AD_Window_ID");
int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
int AD_Record_ID = WebUtil.getParameterAsInt(request, "AD_Record_ID");
if (AD_Process_ID == 0)
{
WebUtil.createErrorPage(request, response, this, "No Process");
return;
}
WebDoc doc = createProcessPage(request, AD_Process_ID);
//Modified by Rob Klein 6/01/07
//WebDoc doc = createProcessPage(request, AD_Process_ID, AD_Window_ID);
createProcessPage(request, response, AD_Process_ID, AD_Window_ID);
//
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
//Modified by Rob Klein 4/29/07
/**************************************************************************
* Create Parameter Page
* @param wsc web session context
* @param AD_Menu_ID Menu
* @return Page
*/
private WebDoc createParameterPage (WebSessionCtx wsc, int AD_Menu_ID)
private WebDoc createParameterPage (WebSessionCtx wsc, int processId, int windowID,int tableID,int recordID,int Type,
String columnName, GridTab mTab)
{
MProcess process = MProcess.getFromMenu (wsc.ctx, AD_Menu_ID);
MProcess process = null;
if (Type == 0)
process = MProcess.getFromMenu (wsc.ctx, processId);
else
process = MProcess.get(wsc.ctx, processId);
// need to check if Role can access
if (process == null)
{
WebDoc doc = WebDoc.createWindow("Process Not Found");
return doc;
}
//Modified by Rob Klein 4/29/07
WebDoc doc = WebDoc.createWindow(process.getName());
td center = doc.addWindowCenter(false);
if (process.getDescription() != null)
center.addElement(new p(new i(process.getDescription())));
if (process.getHelp() != null)
center.addElement(new p(process.getHelp(), AlignType.LEFT));
//
form myForm = new form ("WProcess")
.setName("process" + process.getAD_Process_ID());
myForm.setOnSubmit("this.Submit.disabled=true;return true;");
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Process_ID", process.getAD_Process_ID()));
table myTable = new table("0", "0", "5", "100%", null);
myTable.setID("WProcessParameter");
MProcessPara[] parameter = process.getParameters();
for (int i = 0; i < parameter.length; i++)
if (process.isWorkflow())
{
MProcessPara para = parameter[i];
//
WebField wField = new WebField (wsc,
para.getColumnName(), para.getName(), para.getDescription(),
// no display length
para.getAD_Reference_ID(), para.getFieldLength(), para.getFieldLength(), false,
// not r/o, ., not error, not dependent
false, para.isMandatory(), false, false, false);
td toField = para.isRange()
? wField.getField(para.getLookup(), para.getDefaultValue2())
: new td(WebEnv.NBSP);
// Add to Table
myTable.addElement(new tr()
// Pop up Document Action (Workflow)
if (columnName.toString().equals("DocAction")) {
readReference();
option[] Options = dynInit( windowID, tableID, recordID,
columnName, mTab);
td center = doc.addWindowCenter(false);
WebField wField = new WebField (wsc,
columnName, columnName, columnName,
// no display length
17, 22, 22, false,
// not r/o, ., not error, not dependent
false, false, false, false, false, processId,
0,0,0,0, null,null, null,null);
if (process.getDescription() != null)
center.addElement(new p(new i(process.getDescription())));
if (process.getHelp() != null)
center.addElement(new p(process.getHelp(), AlignType.LEFT));
form myForm = new form ("WProcess")
.setName("process" + process.getAD_Process_ID());
myForm.setOnSubmit("this.Submit.disabled=true;return true;");
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Process_ID", process.getAD_Process_ID()));
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Window_ID", windowID));
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Table_ID", tableID));
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Record_ID", recordID));
table myTable = new table("0", "0", "5", "100%", null);
myTable.setID("WProcessParameter");
myTable.addElement(new tr()
.addElement(wField.getLabel())
.addElement(wField.getField(para.getLookup(), para.getDefaultValue()))
.addElement(toField));
.addElement(createSelectField(columnName,Options)));
// Reset
String text = "Reset";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Reset");
input restbtn = new input(input.TYPE_RESET, text, " "+text);
restbtn.setID(text);
restbtn.setClass("resetbtn");
// Submit
text = "Submit";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Submit");
input submitbtn = new input(input.TYPE_SUBMIT, text, " "+text);
submitbtn.setID(text);
submitbtn.setClass("submitbtn");
myTable.addElement(new tr()
.addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false,
restbtn))
.addElement(new td(null, AlignType.LEFT, AlignType.MIDDLE, false,
submitbtn ))
.addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false,
null)));
myForm.addElement(myTable);
center.addElement(myForm);
} // DocAction
}
else{
td center = doc.addWindowCenter(false);
if (process.getDescription() != null)
center.addElement(new p(new i(process.getDescription())));
if (process.getHelp() != null)
center.addElement(new p(process.getHelp(), AlignType.LEFT));
//
form myForm = new form ("WProcess")
.setName("process" + process.getAD_Process_ID());
myForm.setOnSubmit("this.Submit.disabled=true;return true;");
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Process_ID", process.getAD_Process_ID()));
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Window_ID", windowID));
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Table_ID", tableID));
myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Record_ID", recordID));
table myTable = new table("0", "0", "5", "100%", null);
myTable.setID("WProcessParameter");
MProcessPara[] parameter = process.getParameters();
for (int i = 0; i < parameter.length; i++)
{
MProcessPara para = parameter[i];
WebField wField = new WebField (wsc,
para.getColumnName(), para.getName(), para.getDescription(),
// no display length
para.getAD_Reference_ID(), para.getFieldLength(), para.getFieldLength(), false,
// not r/o, ., not error, not dependent
false, para.isMandatory(), false, false, false, para.getAD_Process_ID(),
0,0,0,i, null,null, null,null);
WebField wFieldforRange = null;
if(para.isRange())
wFieldforRange = new WebField (wsc,
para.getColumnName(), para.getName(), para.getDescription(),
// no display length
para.getAD_Reference_ID(), para.getFieldLength(), para.getFieldLength(), false,
// not r/o, ., not error, not dependent
false, para.isMandatory(), false, false, false, para.getAD_Process_ID(),0,0,0,i+1, null,null, null,null);
td toField = para.isRange()
? wFieldforRange.getField(para.getLookup(), para.getDefaultValue2())
: new td(WebEnv.NBSP);
// Add to Table
myTable.addElement(new tr()
.addElement(wField.getLabel())
.addElement(wField.getField(para.getLookup(), para.getDefaultValue()))
.addElement(toField));
}
// Reset
String text = "Reset";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Reset");
input restbtn = new input(input.TYPE_RESET, text, " "+text);
restbtn.setID(text);
restbtn.setClass("resetbtn");
// Submit
text = "Submit";
if (wsc.ctx != null)
text = Msg.getMsg (wsc.ctx, "Submit");
input submitbtn = new input(input.TYPE_SUBMIT, text, " "+text);
submitbtn.setID(text);
submitbtn.setClass("submitbtn");
myTable.addElement(new tr()
.addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false,
restbtn))
.addElement(new td(null, AlignType.LEFT, AlignType.MIDDLE, false,
submitbtn ))
.addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false,
null)));
myForm.addElement(myTable);
center.addElement(myForm);
}
// Submit
myTable.addElement(new tr()
.addElement(new td(null, AlignType.LEFT, AlignType.MIDDLE, false,
new input(input.TYPE_RESET, "Reset", "Reset") ))
.addElement(new td(null, AlignType.LEFT, AlignType.MIDDLE, false,
null ))
.addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false,
new input(input.TYPE_SUBMIT, "Submit", "Submit") )));
myForm.addElement(myTable);
center.addElement(myForm);
return doc;
} // createParameterPage
//Modified by Rob klein 4/29/07
/**************************************************************************
* Create Parocess Page
* @param request request
* @param AD_Process_ID Process
* @return Page
*/
private WebDoc createProcessPage (HttpServletRequest request, int AD_Process_ID)
public void createProcessPage (HttpServletRequest request, HttpServletResponse response, int AD_Process_ID, int AD_Window_ID)
{
WebSessionCtx wsc = WebSessionCtx.get (request);
MProcess process = MProcess.get (wsc.ctx, AD_Process_ID);
// need to check if Role can access
WebDoc doc = null;
if (process == null)
{
WebDoc doc = WebDoc.createWindow("Process Not Found");
return doc;
}
doc = WebDoc.createWindow("Process Not Found");
WebDoc doc = WebDoc.createWindow(process.getName());
}
else{
doc = WebDoc.createWindow(process.getName());
td center = doc.addWindowCenter(false);
if (process.getDescription() != null)
center.addElement(new p(new i(process.getDescription())));
@ -223,11 +379,17 @@ public class WProcess extends HttpServlet
// Create Process Instance
MPInstance pInstance = fillParameter (request, process);
//
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID());
//
int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
int AD_Record_ID = WebUtil.getParameterAsInt(request, "AD_Record_ID");
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), AD_Table_ID, AD_Record_ID);
pi.setAD_User_ID(Env.getAD_User_ID(wsc.ctx));
pi.setAD_Client_ID(Env.getAD_Client_ID(wsc.ctx));
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
pi.setAD_Client_ID(Env.getAD_Client_ID(wsc.ctx));
log.info("PI client id "+pi.getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
// Info
p p = new p();
@ -236,13 +398,44 @@ public class WProcess extends HttpServlet
// Start
boolean processOK = false;
if (process.isWorkflow())
{
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
try
{
WProcessCtl.process(this, AD_Window_ID, pi, trx, request);
//processOK = process.processIt(pi, trx);
trx.commit();
trx.close();
}
catch (Throwable t)
{
trx.rollback();
trx.close();
}
if ( pi.isError())
{
center.addElement(new p("Error:" + pi.getSummary(),
AlignType.LEFT).setClass("Cerror"));
processOK = false;
}
else
{
center.addElement(new p("OK: Workflow Started",
AlignType.LEFT));
processOK = true;
}
center.addElement(new p().addElement(pi.getSummary()));
center.addElement(pi.getLogInfo(true));
}
if (process.isJavaProcess())
{
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
try
{
processOK = process.processIt(pi, trx);
trx.commit(true);
{
processOK = process.processIt(pi, trx);
trx.commit();
trx.close();
}
catch (Throwable t)
@ -261,8 +454,11 @@ public class WProcess extends HttpServlet
}
// Report
if (processOK && process.isReport())
if (process.isReport())
//if (processOK && process.isReport())
{
doc = null;
log.info(response.toString());
ReportEngine re = ReportEngine.get(wsc.ctx, pi);
if (re == null)
{
@ -276,7 +472,15 @@ public class WProcess extends HttpServlet
File file = File.createTempFile("WProcess", ".pdf");
boolean ok = re.createPDF(file);
if (ok)
{
{
String error = WebUtil.streamFile(response, file);
//String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
if (error == null)
return;
doc = WebDoc.create(error);
//Modified by Rob Klein 6/1/07
/**
String url = "WProcess?AD_PInstance_ID="
+ pInstance.getAD_PInstance_ID()
+ "&File="
@ -287,7 +491,9 @@ public class WProcess extends HttpServlet
.addElement("Report created: ")
.addElement(link));
// Marker that Process is OK
* */
wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
}
else
center.addElement(new p("Could not create Report",
@ -301,9 +507,21 @@ public class WProcess extends HttpServlet
}
}
}
return doc;
}
doc.addPopupClose(wsc.ctx);
try {
WebUtil.createResponse(request, response, this, null, doc, false);
} catch (IOException e) {
log.info(e.toString());
}
} // createProcessPage
private ASyncProcess ASyncProcess(WProcess process) {
// TODO Auto-generated method stub
return null;
}
/**
* Fill Parameter
* @param request request
@ -397,7 +615,7 @@ public class WProcess extends HttpServlet
* @return message
*/
private String streamResult (HttpServletRequest request, HttpServletResponse response,
int AD_PInstance_ID, String fileName)
int AD_PInstance_ID, File file)
{
if (AD_PInstance_ID == 0)
return "Your process not found";
@ -406,13 +624,393 @@ public class WProcess extends HttpServlet
if (value == null || !value.equals("ok"))
return "Process Instance not found";
//
if (fileName == null || fileName.length() == 0)
if (file == null || file.length() == 0)
return "No Process Result";
File file = new File (fileName);
//File file = new File (fileName);
if (!file.exists())
return "Process Result not found: " + file;
// OK
return WebUtil.streamFile(response, file);
} // streamResult
//Modidifed by Rob Klein 4/29/07
/**
* Dynamic Init - determine valid DocActions based on DocStatus for the different documents.
* <pre>
* DocStatus (131)
?? Unknown
AP * Approved
CH Changed
CL * Closed
CO * Completed
DR Drafted
IN Inactive
NA Not Approved
PE Posting Error
PO * Posted
PR * Printed
RE Reversed
TE Transfer Error
TR * Transferred
VO * Voided
XX Being Processed
*
* DocAction (135)
-- <None>
AP * Approve
CL * Close
CO * Complete
PO * Post
PR * Print
RA Reverse - Accrual
RC Reverse - Correction
RE RE-activate
RJ Reject
TR * Transfer
VO * Void
XL Unlock
* </pre>
* @param Record_ID id
*/
private option[] dynInit(int m_WindowNo,int m_AD_Table_ID,int Record_ID,
String columnName, GridTab m_mTab)
{
String DocStatus = (String)m_mTab.getValue("DocStatus");
String DocAction = (String)m_mTab.getValue("DocAction");
//
Object Processing = m_mTab.getValue("Processing");
String OrderType = Env.getContext(Env.getCtx(), m_WindowNo, "OrderType");
String IsSOTrx = Env.getContext(Env.getCtx(), m_WindowNo, "IsSOTrx");
option[] optionsret = new option[0];
String[] list = new String [s_value.length];
if (DocStatus == null)
{
errorMessage = "Document Status is Null";
return optionsret;
}
log.fine("DocStatus=" + DocStatus
+ ", DocAction=" + DocAction + ", OrderType=" + OrderType
+ ", IsSOTrx=" + IsSOTrx + ", Processing=" + Processing
+ ", AD_Table_ID=" + m_AD_Table_ID + ", Record_ID=" + Record_ID);
//
int index = 0;
/**
* Check Existence of Workflow Acrivities
*/
String wfStatus = MWFActivity.getActiveInfo(Env.getCtx(), m_AD_Table_ID, Record_ID);
if (wfStatus != null)
{
errorMessage = wfStatus;
return optionsret;
}
// Status Change
if (!checkStatus(m_mTab.getTableName(), Record_ID, DocStatus))
{
errorMessage = "DocumentStatusChanged";
return optionsret;
}
/*******************
* General Actions
*/
// Locked
if (Processing != null)
{
boolean locked = "Y".equals(Processing);
if (!locked && Processing instanceof Boolean)
locked = ((Boolean)Processing).booleanValue();
if (locked)
list[index++]= DocumentEngine.ACTION_Unlock;
}
// Approval required .. NA
if (DocStatus.equals(DocumentEngine.STATUS_NotApproved))
{
list[index++]= (DocumentEngine.ACTION_Prepare);
list[index++]= (DocumentEngine.ACTION_Void);
}
// Draft/Invalid .. DR/IN
else if (DocStatus.equals(DocumentEngine.STATUS_Drafted)
|| DocStatus.equals(DocumentEngine.STATUS_Invalid))
{
list[index++]= (DocumentEngine.ACTION_Complete);
// options[index++] = (DocumentEngine.ACTION_Prepare);
list[index++]= (DocumentEngine.ACTION_Void);
}
// In Process .. IP
else if (DocStatus.equals(DocumentEngine.STATUS_InProgress)
|| DocStatus.equals(DocumentEngine.STATUS_Approved))
{
list[index++]= (DocumentEngine.ACTION_Complete);
list[index++]= (DocumentEngine.ACTION_Void);
}
// Complete .. CO
else if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Close);
}
// Waiting Payment
else if (DocStatus.equals(DocumentEngine.STATUS_WaitingPayment)
|| DocStatus.equals(DocumentEngine.STATUS_WaitingConfirmation))
{
list[index++]= (DocumentEngine.ACTION_Void);
list[index++]= (DocumentEngine.ACTION_Prepare);
}
// Closed, Voided, REversed .. CL/VO/RE
else if (DocStatus.equals(DocumentEngine.STATUS_Closed)
|| DocStatus.equals(DocumentEngine.STATUS_Voided)
|| DocStatus.equals(DocumentEngine.STATUS_Reversed))
return optionsret;
/********************
* Order
*/
if (m_AD_Table_ID == MOrder.Table_ID)
{
// Draft .. DR/IP/IN
if (DocStatus.equals(DocumentEngine.STATUS_Drafted)
|| DocStatus.equals(DocumentEngine.STATUS_InProgress)
|| DocStatus.equals(DocumentEngine.STATUS_Invalid))
{
list[index++]= (DocumentEngine.ACTION_Prepare);
list[index++]= (DocumentEngine.ACTION_Close);
// Draft Sales Order Quote/Proposal - Process
if ("Y".equals(IsSOTrx)
&& ("OB".equals(OrderType) || "ON".equals(OrderType)))
DocAction = DocumentEngine.ACTION_Prepare;
}
// Complete .. CO
else if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Void);
list[index++]= (DocumentEngine.ACTION_ReActivate);
}
else if (DocStatus.equals(DocumentEngine.STATUS_WaitingPayment))
{
list[index++]= (DocumentEngine.ACTION_ReActivate);
list[index++]= (DocumentEngine.ACTION_Close);
}
}
/********************
* Shipment
*/
else if (m_AD_Table_ID == MInOut.Table_ID)
{
// Complete .. CO
if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Void);
list[index++]= (DocumentEngine.ACTION_Reverse_Correct);
}
}
/********************
* Invoice
*/
else if (m_AD_Table_ID == MInvoice.Table_ID)
{
// Complete .. CO
if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Void);
list[index++]= (DocumentEngine.ACTION_Reverse_Correct);
}
}
/********************
* Payment
*/
else if (m_AD_Table_ID == MPayment.Table_ID)
{
// Complete .. CO
if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Void);
list[index++]= (DocumentEngine.ACTION_Reverse_Correct);
}
}
/********************
* GL Journal
*/
else if (m_AD_Table_ID == MJournal.Table_ID || m_AD_Table_ID == MJournalBatch.Table_ID)
{
// Complete .. CO
if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Reverse_Correct);
list[index++]= (DocumentEngine.ACTION_Reverse_Accrual);
}
}
/********************
* Allocation
*/
else if (m_AD_Table_ID == MAllocationHdr.Table_ID)
{
// Complete .. CO
if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Void);
list[index++]= (DocumentEngine.ACTION_Reverse_Correct);
}
}
/********************
* Bank Statement
*/
else if (m_AD_Table_ID == MBankStatement.Table_ID)
{
// Complete .. CO
if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++]= (DocumentEngine.ACTION_Void);
}
}
/********************
* Inventory Movement, Physical Inventory
*/
else if (m_AD_Table_ID == MMovement.Table_ID
|| m_AD_Table_ID == MInventory.Table_ID)
{
// Complete .. CO
if (DocStatus.equals(DocumentEngine.STATUS_Completed))
{
list[index++] = (DocumentEngine.ACTION_Void);
list[index++] = (DocumentEngine.ACTION_Reverse_Correct);
}
}
option[] options = new option[index];
/**
* Add Name to options
*/
for (int i = 0; i < index; i++)
{
// Serach for option and add it
boolean added = false;
for (int j = 0; j < s_value.length && !added; j++)
{
if (list[i].equals(s_value[j]))
{
options[i] = new option(list[i]).addElement(s_name[j]);
added = true;
if (DocAction.equals(s_value[i]))
options[i].setSelected(true);
}
}
}
return options;
} // dynInit
/**
* Fill Vector with DocAction Ref_List(135) values
*/
private void readReference()
{
String sql;
if (Env.isBaseLanguage(Env.getCtx(), "AD_Ref_List"))
sql = "SELECT Value, Name, Description FROM AD_Ref_List "
+ "WHERE AD_Reference_ID=135 ORDER BY Name";
else
sql = "SELECT l.Value, t.Name, t.Description "
+ "FROM AD_Ref_List l, AD_Ref_List_Trl t "
+ "WHERE l.AD_Ref_List_ID=t.AD_Ref_List_ID"
+ " AND t.AD_Language='" + Env.getAD_Language(Env.getCtx()) + "'"
+ " AND l.AD_Reference_ID=135 ORDER BY t.Name";
ArrayList<String> v_value = new ArrayList<String>();
ArrayList<String> v_name = new ArrayList<String>();
ArrayList<String> v_description = new ArrayList<String>();
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
String value = rs.getString(1);
String name = rs.getString(2);
String description = rs.getString(3);
if (description == null)
description = "";
//
v_value.add(value);
v_name.add(name);
v_description.add(description);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
// convert to arrays
int size = v_value.size();
s_value = new String[size];
s_name = new String[size];
s_description = new String[size];
for (int i = 0; i < size; i++)
{
s_value[i] = (String)v_value.get(i);
s_name[i] = (String)v_name.get(i);
s_description[i] = (String)v_description.get(i);
}
} // readReference
/**
* Check Status Change
* @param TableName table name
* @param Record_ID record
* @param DocStatus current doc status
* @return true if status not changed
*/
private boolean checkStatus (String TableName, int Record_ID, String DocStatus)
{
String sql = "SELECT 2 FROM " + TableName
+ " WHERE " + TableName + "_ID=" + Record_ID
+ " AND DocStatus='" + DocStatus + "'";
int result = DB.getSQLValue(null, sql);
return result == 2;
} // checkStatusChange
/**
* Get Select Field
* @param lookup lookup
* @param dataValue default value
* @return selction td
*/
private td createSelectField (String m_columnName, option[] options)
{
select sel = new select(m_columnName, options);
sel.setID(m_columnName);
sel.setDisabled(false);
sel.setClass("Cmandatory");
//
return createTD(sel);
} // getSelectField
/**
* Create Left Top aligned TD
* @param element element
* @return td table data
*/
private td createTD (Element element)
{
td td = new td()
.addElement(element)
.setAlign(AlignType.LEFT)
.setVAlign(AlignType.TOP);
return td;
} // createTD
} // WProcess

View File

@ -0,0 +1,515 @@
/******************************************************************************
* Product: Compiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.www;
import java.awt.*;
import java.io.*;
import java.lang.reflect.*;
import java.rmi.*;
import java.sql.*;
import java.util.Properties;
import java.util.logging.*;
import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import org.compiere.apps.Waiting;
import org.compiere.db.*;
import org.compiere.interfaces.*;
import org.compiere.model.*;
import org.compiere.print.*;
import org.compiere.process.*;
import org.compiere.util.*;
import org.compiere.wf.*;
/**
* Process Interface Controller.
*
* @author Jorg Janke
* @version $Id: ProcessCtl.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
*/
public class WProcessCtl extends Thread
{
/**
* Async Process - Do it all.
* <code>
* - Get Instance ID
* - Get Parameters
* - execute (lock - start process - unlock)
* </code>
* Creates a ProcessCtl instance, which calls
* lockUI and unlockUI if parent is a ASyncProcess
* <br>
* Called from ProcessCtl.startProcess, ProcessDialog.actionPerformed,
* APanel.cmd_print, APanel.actionButton, VPaySelect.cmd_generate
*
* @param parent ASyncProcess & Container
* @param WindowNo window no
* @param pi ProcessInfo process info
* @param trx Transaction
* @return worker started ProcessCtl instance or null for workflow
*/
public static WProcessCtl process (Object parent, int WindowNo, ProcessInfo pi, Trx trx, HttpServletRequest request)
{
log.fine("WindowNo=" + WindowNo + " - " + pi);
WebSessionCtx wsc = WebSessionCtx.get (request);
MPInstance instance = new MPInstance(wsc.ctx, pi.getAD_Process_ID(), pi.getRecord_ID());
if (!instance.save())
{
pi.setSummary (Msg.getMsg(wsc.ctx, "ProcessNoInstance"));
pi.setError (true);
return null;
}
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
// Get Parameters (Dialog)
/**ProcessParameter para = new ProcessParameter (Env.getFrame((Container)parent), WindowNo, pi);
if (para.initDialog())
{
para.setVisible(true);
if (!para.isOK())
{
pi.setSummary (Msg.getMsg(Env.getCtx(), "ProcessCancelled"));
pi.setError (true);
return null;
}
}
**/
// execute
WProcessCtl worker = new WProcessCtl(parent, pi, trx, wsc.ctx);
worker.start(); // MUST be start!
return worker;
} // execute
/**************************************************************************
* Constructor
* @param parent Container & ASyncProcess
* @param pi Process info
* @param trx Transaction
* Created in process(), VInvoiceGen.generateInvoices
*/
public WProcessCtl (Object parent, ProcessInfo pi, Trx trx, Properties wscctx)
{
m_parent = parent;
m_pi = pi;
m_wscctx = wscctx;
m_trx = trx; // handeled correctly
} // ProcessCtl
private Object m_parent;
private Properties m_wscctx;
private ProcessInfo m_pi;
private Trx m_trx;
private Waiting m_waiting;
private boolean m_IsServerProcess = false;
/** Static Logger */
private static CLogger log = CLogger.getCLogger (WProcessCtl.class);
/**
* Execute Process Instance and Lock UI.
* Calls lockUI and unlockUI if parent is a ASyncProcess
* <pre>
* - Get Process Information
* - Call Class
* - Submit SQL Procedure
* - Run SQL Procedure
* </pre>
*/
public void run ()
{
log.fine("AD_PInstance_ID=" + m_pi.getAD_PInstance_ID()
+ ", Record_ID=" + m_pi.getRecord_ID());
// Lock
//lock();
// try {System.out.println(">> sleeping ..");sleep(20000);System.out.println(".. sleeping <<");} catch (Exception e) {}
// Get Process Information: Name, Procedure Name, ClassName, IsReport, IsDirectPrint
String ProcedureName = "";
int AD_ReportView_ID = 0;
int AD_Workflow_ID = 0;
boolean IsReport = false;
boolean IsDirectPrint = false;
//
String sql = "SELECT p.Name, p.ProcedureName,p.ClassName, p.AD_Process_ID," // 1..4
+ " p.isReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8
+ " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE,"
+ " p.IsServerProcess "
+ "FROM AD_Process p"
+ " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
+ "WHERE p.IsActive='Y'"
+ " AND i.AD_PInstance_ID=?";
if (!Env.isBaseLanguage(m_wscctx, "AD_Process"))
sql = "SELECT t.Name, p.ProcedureName,p.ClassName, p.AD_Process_ID," // 1..4
+ " p.isReport, p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8
+ " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE,"
+ " p.IsServerProcess "
+ "FROM AD_Process p"
+ " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
+ " INNER JOIN AD_Process_Trl t ON (p.AD_Process_ID=t.AD_Process_ID"
+ " AND t.AD_Language='" + Env.getAD_Language(m_wscctx) + "') "
+ "WHERE p.IsActive='Y'"
+ " AND i.AD_PInstance_ID=?";
//
try
{
PreparedStatement pstmt = DB.prepareStatement(sql,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, null);
pstmt.setInt(1, m_pi.getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
m_pi.setTitle (rs.getString(1));
if (m_waiting != null)
m_waiting.setTitle(m_pi.getTitle());
ProcedureName = rs.getString(2);
m_pi.setClassName (rs.getString(3));
m_pi.setAD_Process_ID (rs.getInt(4));
// Report
if ("Y".equals(rs.getString(5)))
{
IsReport = true;
if ("Y".equals(rs.getString(6)) && !Ini.isPropertyBool(Ini.P_PRINTPREVIEW))
IsDirectPrint = true;
}
AD_ReportView_ID = rs.getInt(7);
AD_Workflow_ID = rs.getInt(8);
//
int estimate = rs.getInt(9);
if (estimate != 0)
{
m_pi.setEstSeconds (estimate + 1); // admin overhead
if (m_waiting != null)
m_waiting.setTimerEstimate(m_pi.getEstSeconds());
}
m_IsServerProcess = "Y".equals(rs.getString(10));
}
else
log.log(Level.SEVERE, "No AD_PInstance_ID=" + m_pi.getAD_PInstance_ID());
rs.close();
pstmt.close();
}
catch (SQLException e)
{
m_pi.setSummary (Msg.getMsg(m_wscctx, "ProcessNoProcedure") + " " + e.getLocalizedMessage(), true);
//unlock();
log.log(Level.SEVERE, "run", e);
return;
}
// No PL/SQL Procedure
if (ProcedureName == null)
ProcedureName = "";
/**********************************************************************
* Workflow
*/
if (AD_Workflow_ID > 0)
{
startWorkflow (AD_Workflow_ID);
//unlock();
return;
}
/**********************************************************************
* Start Optional Class
*/
if (m_pi.getClassName() != null)
{
// Run Class
if (!startProcess())
{
//unlock();
return;
}
// No Optional SQL procedure ... done
if (!IsReport && ProcedureName.length() == 0)
{
//unlock ();
return;
}
// No Optional Report ... done
if (IsReport && AD_ReportView_ID == 0)
{
//unlock ();
return;
}
}
// If not a report, we need a prodedure name
if (!IsReport && ProcedureName.length() == 0)
{
m_pi.setSummary (Msg.getMsg(m_wscctx, "ProcessNoProcedure"), true);
//unlock();
return;
}
/**********************************************************************
* Report submission
*/
if (IsReport)
{
// Optional Pre-Report Process
if (ProcedureName.length() > 0)
{
if (!startDBProcess(ProcedureName))
{
//unlock();
return;
}
} // Pre-Report
// Start Report -----------------------------------------------
boolean ok = ReportCtl.start(m_pi, IsDirectPrint);
m_pi.setSummary("Report", !ok);
//unlock ();
}
/**********************************************************************
* Process submission
*/
else
{
if (!startDBProcess (ProcedureName))
{
//unlock();
return;
}
// Success - getResult
ProcessInfoUtil.setSummaryFromDB(m_pi);
//unlock();
} // *** Process submission ***
// log.fine(Log.l3_Util, "ProcessCtl.run - done");
} // run
/**
* Lock UI & show Waiting
*/
/** private void lock ()
{
// log.info("...");
JFrame frame = Env.getFrame((Container)m_parent);
if (frame instanceof AWindow)
((AWindow)frame).setBusyTimer(m_pi.getEstSeconds());
else
m_waiting = new Waiting (frame, Msg.getMsg(Env.getCtx(), "Processing"), false, m_pi.getEstSeconds());
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
log.finer("lock");
m_parent.lockUI(m_pi);
}
});
if (m_waiting != null)
{
m_waiting.toFront();
m_waiting.setVisible(true);
}
} // lock
**/
/**
* Unlock UI & dispose Waiting.
* Called from run()
*/
/** private void unlock ()
{
// log.info("...");
if (m_pi.isBatch())
m_pi.setIsTimeout(true);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
String summary = m_pi.getSummary();
log.finer("unlock - " + summary);
if (summary != null && summary.indexOf("@") != -1)
m_pi.setSummary(Msg.parseTranslation(Env.getCtx(), summary));
m_parent.unlockUI(m_pi);
}
});
// Remove Waiting/Processing Indicator
if (m_waiting != null)
m_waiting.dispose();
m_waiting = null;
} // unlock
**/
/**************************************************************************
* Start Workflow.
*
* @param AD_Workflow_ID workflow
* @return true if started
*/
private boolean startWorkflow (int AD_Workflow_ID)
{
log.fine(AD_Workflow_ID + " - " + m_pi);
boolean started = false;
if (DB.isRemoteProcess())
{
log.info("trying to running on the server");
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
log.info("running on the server");
m_pi = server.workflow (m_wscctx, m_pi, AD_Workflow_ID);
log.finest("server => " + m_pi);
started = true;
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
started = false;
}
}
// Run locally
if (!started && !m_IsServerProcess)
{
log.info("running locally");
MWorkflow wf = MWorkflow.get (m_wscctx, AD_Workflow_ID);
MWFProcess wfProcess = null;
if (m_pi.isBatch())
wfProcess = wf.start(m_pi); // may return null
else
wfProcess = wf.startWait(m_pi); // may return null
started = wfProcess != null;
}
return started;
} // startWorkflow
/**************************************************************************
* Start Java Process Class.
* instanciate the class implementing the interface ProcessCall.
* The class can be a Server/Client class (when in Package
* org compiere.process or org.compiere.model) or a client only class
* (e.g. in org.compiere.report)
*
* @return true if success
*/
private boolean startProcess ()
{
log.fine(m_pi.toString());
boolean started = false;
if (DB.isRemoteProcess())
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
m_pi = server.process (m_wscctx, m_pi);
log.finest("server => " + m_pi);
started = true;
}
}
catch (UndeclaredThrowableException ex)
{
Throwable cause = ex.getCause();
if (cause != null)
{
if (cause instanceof InvalidClassException)
log.log(Level.SEVERE, "Version Server <> Client: "
+ cause.toString() + " - " + m_pi, ex);
else
log.log(Level.SEVERE, "AppsServer error(1b): "
+ cause.toString() + " - " + m_pi, ex);
}
else
log.log(Level.SEVERE, " AppsServer error(1) - "
+ m_pi, ex);
started = false;
}
catch (RemoteException ex)
{
Throwable cause = ex.getCause();
if (cause == null)
cause = ex;
log.log(Level.SEVERE, "AppsServer error - " + m_pi, cause);
started = false;
}
}
// Run locally
if (!started && !m_IsServerProcess)
{
ProcessCall myObject = null;
try
{
Class myClass = Class.forName(m_pi.getClassName());
myObject = (ProcessCall)myClass.newInstance();
if (myObject == null)
m_pi.setSummary("No Instance for " + m_pi.getClassName(), true);
else
myObject.startProcess(m_wscctx, m_pi, m_trx);
if (m_trx != null)
{
m_trx.commit();
m_trx.close();
}
}
catch (Exception e)
{
if (m_trx != null)
{
m_trx.rollback();
m_trx.close();
}
m_pi.setSummary("Error starting Class " + m_pi.getClassName(), true);
log.log(Level.SEVERE, m_pi.getClassName(), e);
}
}
return !m_pi.isError();
} // startProcess
/**************************************************************************
* Start Database Process
* @param ProcedureName PL/SQL procedure name
* @return true if success
*/
private boolean startDBProcess (String ProcedureName)
{
// execute on this thread/connection
log.fine(ProcedureName + "(" + m_pi.getAD_PInstance_ID() + ")");
String sql = "{call " + ProcedureName + "(?)}";
try
{
CallableStatement cstmt = DB.prepareCall(sql); // ro??
cstmt.setInt(1, m_pi.getAD_PInstance_ID());
cstmt.executeUpdate();
cstmt.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
m_pi.setSummary (Msg.getMsg(m_wscctx, "ProcessRunError") + " " + e.getLocalizedMessage());
m_pi.setError (true);
return false;
}
// log.fine(Log.l4_Data, "ProcessCtl.startProcess - done");
return true;
} // startDBProcess
} // ProcessCtl

View File

@ -0,0 +1,361 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.www;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.io.*;
import java.net.URLEncoder;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.JComponent;
import org.apache.ecs.AlignType;
import org.apache.ecs.xhtml.a;
import org.apache.ecs.xhtml.p;
import org.apache.ecs.xhtml.td;
import org.compiere.apps.ADialog;
import org.compiere.apps.AEnv;
import org.compiere.apps.ProcessCtl;
import org.compiere.model.*;
import org.compiere.print.AReport;
import org.compiere.print.MPrintFormat;
import org.compiere.print.ReportEngine;
import org.compiere.print.Viewer;
import org.compiere.process.ProcessInfo;
import org.compiere.util.*;
/**
* Web (window) Report
*
* @author Jorg Janke
* @version $Id: WReport.java $
*/
public class WReport extends HttpServlet
{
/** Logger */
protected CLogger log = CLogger.getCLogger(getClass());
/** Current MTab */
private GridTab m_curTab;
/** The Option List */
private ArrayList<KeyNamePair> m_list = new ArrayList<KeyNamePair>();
/**
* Initialize global variables
*/
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
if (!WebEnv.initWeb(config))
throw new ServletException("WReport.init");
} // init
/**
* Process the HTTP Get request
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
log.fine("doGet");
log.info(response.toString());
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
m_curTab = ws.curTab;
//
WebDoc doc = null;
File file = null;
if (ws == null)
{
doc = WebDoc.createPopup("No Context");
doc.addPopupClose(wsc.ctx);
}
/**else if (fileName!=null)
{
int AD_PInstance_ID = WebUtil.getParameterAsInt(request, "AD_PInstance_ID");
File file = new File (fileName);
String error = WebUtil.streamFile(response, file);
if (error == null)
return;
doc = WebDoc.createWindow(error);
}**/
else{
log.info("");
if (!MRole.getDefault().isCanReport(ws.curTab.getAD_Table_ID()))
{
doc = WebDoc.createPopup("Access Cannot Report");
doc.addPopupClose(wsc.ctx);
}
// Query
MQuery query = new MQuery(m_curTab.getTableName());
// Link for detail records
String queryColumn = m_curTab.getLinkColumnName();
// Current row otherwise
if (queryColumn.length() == 0)
queryColumn = m_curTab.getKeyColumnName();
// Find display
String infoName = null;
String infoDisplay = null;
for (int i = 0; i < m_curTab.getFieldCount(); i++)
{
GridField field = m_curTab.getField(i);
if (field.isKey())
infoName = field.getHeader();
if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo") )
&& field.getValue() != null)
infoDisplay = field.getValue().toString();
if (infoName != null && infoDisplay != null)
break;
}
if (queryColumn.length() != 0)
{
if (queryColumn.endsWith("_ID"))
query.addRestriction(queryColumn, MQuery.EQUAL,
new Integer(Env.getContextAsInt(wsc.ctx, m_curTab.getWindowNo(), queryColumn)),
infoName, infoDisplay);
else
query.addRestriction(queryColumn, MQuery.EQUAL,
Env.getContext(wsc.ctx, m_curTab.getWindowNo(), queryColumn),
infoName, infoDisplay);
}
file = getPrintFormats (m_curTab.getAD_Table_ID(), request, m_curTab, query);
String error = WebUtil.streamFile(response, file);
if (error == null)
return;
doc = WebDoc.createWindow(error);
}
//
WebUtil.createResponse(request, response, this, null, doc, false);
} // doGet
/**
* Process the HTTP Post request
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
WebDoc doc = WebDoc.createPopup ("Report - Post - Not Implemented");
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
/**
* Get the Print Formats for the table.
* Fill the list and the popup menu
* @param AD_Table_ID table
* @param invoker component to display popup (optional)
*/
private File getPrintFormats (int AD_Table_ID,HttpServletRequest request, GridTab m_curTab, MQuery m_query )
{
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
int AD_Client_ID = Env.getAD_Client_ID(wsc.ctx);
File file = null;
m_list = new ArrayList<KeyNamePair>();
//
String sql = MRole.getDefault().addAccessSQL (
"SELECT AD_PrintFormat_ID, Name, AD_Client_ID "
+ "FROM AD_PrintFormat "
+ "WHERE AD_Table_ID=? AND IsTableBased='Y' "
+ "ORDER BY AD_Client_ID DESC, IsDefault DESC, Name", // Own First
"AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
KeyNamePair pp = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
pp = new KeyNamePair (rs.getInt(1), rs.getString(2));
if (rs.getInt(3) == AD_Client_ID)
{
m_list.add(pp);
//m_popup.add(pp.toString()).addActionListener(this);
}
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
// No Format exists - create it
if (m_list.size() == 0)
{
if (pp == null)
file = createNewFormat (AD_Table_ID,request, m_curTab, m_query); // calls launch
else
file = copyFormat(pp.getKey(), AD_Client_ID,request, m_curTab, m_query);
}
// One Format exists or no invoker - show it
//else if (m_list.size() == 1 || invoker == null)
else
file = launchReport ((KeyNamePair)m_list.get(0),request, m_curTab, m_query);
//TODO Display Multiple Report List
// Multiple Formats exist - show selection
//else if (invoker.isShowing())
//m_popup.show(invoker, 0, invoker.getHeight()); // below button
return file;
} // getPrintFormats
/**
* Create and Launch new Format for table
* @param AD_Table_ID table
*/
private File createNewFormat (int AD_Table_ID, HttpServletRequest request, GridTab m_curTab, MQuery m_query)
{
WebSessionCtx wsc = WebSessionCtx.get(request);
MPrintFormat pf = MPrintFormat.createFromTable(wsc.ctx, AD_Table_ID);
File file = launchReport (pf,request, m_curTab, m_query);
return file;
} // createNewFormat
/**
* Copy existing Format
* @param AD_PrintFormat_ID print format
* @param To_Client_ID to client
*/
private File copyFormat (int AD_PrintFormat_ID, int To_Client_ID, HttpServletRequest request, GridTab m_curTab, MQuery m_query)
{
WebSessionCtx wsc = WebSessionCtx.get(request);
MPrintFormat pf = MPrintFormat.copyToClient(wsc.ctx, AD_PrintFormat_ID, To_Client_ID);
File file = launchReport (pf,request, m_curTab, m_query);
return file;
} // copyFormatFromClient
/**
* Launch Report
* @param pp Key=AD_PrintFormat_ID
*/
private File launchReport (KeyNamePair pp, HttpServletRequest request, GridTab m_curTab,MQuery m_query)
{
WebSessionCtx wsc = WebSessionCtx.get(request);
MPrintFormat pf = MPrintFormat.get(wsc.ctx, pp.getKey(), false);
File file = launchReport (pf, request, m_curTab, m_query);
return file;
} // launchReport
/**
* Launch Report
* @param pf print format
*/
private File launchReport (MPrintFormat pf, HttpServletRequest request, GridTab m_curTab, MQuery m_query)
{
int Record_ID = 0;
WebSessionCtx wsc = WebSessionCtx.get(request);
WWindowStatus ws = WWindowStatus.get(request);
//Instance pInstance = new MPInstance (wsc.ctx, 0, 0);
File fileName = null;
if (m_query.getRestrictionCount()==1 && m_query.getCode(0) instanceof Integer){
Record_ID = ((Integer)m_query.getCode(0)).intValue();
}
PrintInfo info = new PrintInfo(
pf.getName(),
pf.getAD_Table_ID(),
Record_ID);
info.setDescription(m_query.getInfo());
if(pf != null && pf.getJasperProcess_ID() > 0)
{
// It's a report using the JasperReports engine
ProcessInfo pi = new ProcessInfo ("", pf.getJasperProcess_ID());
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
// Execute Process
WProcessCtl.process(this, m_curTab.getAD_Window_ID(), pi, trx, request);
}
else
{
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine (wsc.ctx, pf, m_query, info);
if (re == null)
{
log.info("Could not start ReportEngine");
}
else
{
try
{
File file = File.createTempFile("WProcess", ".pdf");
boolean ok = re.createPDF(file);
if (ok)
{
fileName = file;
}
else{
log.info("Could not create Report");
}
}
catch (Exception e)
{
log.info(e.toString());
}
}
}
//doc.addPopupClose(wsc.ctx);
// if (m_popup.isVisible())
// m_popup.setVisible(false);
return fileName;
} // launchReport
/**************************************************************************
* Get AD_Table_ID for Table Name
* @param TableName table name
* @return AD_Table_ID or 0
*/
static public int getAD_Table_ID (String TableName)
{
int AD_Table_ID = 0;
String sql = "SELECT AD_Table_ID FROM AD_Table WHERE TableName=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, TableName);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
AD_Table_ID = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
//log.log(Level.SEVERE, sql, e);
}
return AD_Table_ID;
} // getAD_Table_ID
} // WReport

View File

@ -47,7 +47,7 @@ public class WStatus extends HttpServlet
{
WebDoc doc = WebDoc.create ("WStatus Get Request");
//
WebUtil.createResponse(request, response, this, null, doc, true);
WebUtil.createResponse(request, response, this, null, doc, false);
} // doGet
@ -58,7 +58,7 @@ public class WStatus extends HttpServlet
{
WebDoc doc = WebDoc.create ("WStatus Post Request");
//
WebUtil.createResponse(request, response, this, null, doc, true);
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
} // WStatus

View File

@ -0,0 +1,84 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.www;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.compiere.util.*;
import java.util.*;
import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* Web (window) Help
*
* @author Jorg Janke
* @version $Id: WHelp.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $
*/
public class WTest extends HttpServlet
{
/** Logger */
protected CLogger log = CLogger.getCLogger(WTest.class);
/**
* Initialize global variables
*/
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
if (!WebEnv.initWeb(config))
throw new ServletException("WTest.init");
} // init
/**
* Process the HTTP Get request
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
log.fine("doGet");
WWindowStatus ws = WWindowStatus.get(request);
//
WebDoc doc = null;
if (ws == null)
{
doc = WebDoc.createPopup("No Context");
//Modified by Rob Klein 4/29/07
doc.addPopupClose(Env.getCtx());
}
else
doc = WebDoc.createPopup ("Test - Get - Not Implemented");
//
WebUtil.createResponse(request, response, this, null, doc, false);
} // doGet
/**
* Process the HTTP Post request
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
WebDoc doc = WebDoc.createPopup ("Test - Post - Not Implemented");
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
} // WHelp

View File

@ -18,14 +18,20 @@ package org.compiere.www;
import java.io.*;
import java.math.*;
import java.net.URLEncoder;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.compiere.apps.ProcessCtl;
import org.compiere.model.*;
import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfo;
import org.compiere.util.*;
/**
@ -57,7 +63,7 @@ public class WWindow extends HttpServlet
*/
public String getServletInfo()
{
return "adempiere Web Window";
return "Adempiere Web Window";
} // getServletInfo
/**
@ -72,7 +78,10 @@ public class WWindow extends HttpServlet
private static int s_WindowNo = 1;
/** Form Name */
protected static final String FORM_NAME = "WForm";
//Modified by Rob Klein 4/29/07
protected static String sectionNameOld = null;
/** Hidden Parameter Command - Button */
private static final String P_Command = "PCommand";
/** Hidden Parameter - Tab No */
@ -83,7 +92,9 @@ public class WWindow extends HttpServlet
private static final String P_ChangedColumn = "ChangedColumn";
/** Multi Row Lines per Screen */
private static final int MAX_LINES = 12;
// Modified by Rob Klein 4/29/2007
//private static final int MAX_LINES = 12;
private static final int MAX_LINES = 1000;
/** Indicator for last line */
private static final int LAST_LINE = 999999;
@ -109,6 +120,7 @@ public class WWindow extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get Session attributes
WebDoc doc = null;
HttpSession sess = request.getSession();
WebSessionCtx wsc = WebSessionCtx.get(request);
if (wsc == null)
@ -124,6 +136,51 @@ public class WWindow extends HttpServlet
//
log.info("AD_Window_ID=" + AD_Window_ID
+ "; AD_Menu_ID=" + AD_Menu_ID);
String TableName = null;
//Check to see if Zoom
int AD_Record_ID = WebUtil.getParameterAsInt(request, "AD_Record_ID");
int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
if (AD_Record_ID != 0 || AD_Table_ID != 0){
AD_Window_ID = 0;
int PO_Window_ID = 0;
String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE AD_Table_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
TableName = rs.getString(1);
AD_Window_ID = rs.getInt(2);
PO_Window_ID = rs.getInt(3);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
if (TableName == null || AD_Window_ID == 0){
doc = WebDoc.createPopup ("No Context");
doc.addPopupClose(wsc.ctx);
}
// PO Zoom ?
boolean isSOTrx = true;
if (PO_Window_ID != 0)
{
String whereClause = TableName + "_ID=" + AD_Record_ID;
isSOTrx = DB.isSOTrx(TableName, whereClause);
if (!isSOTrx)
AD_Window_ID = PO_Window_ID;
}
}
// Clean up old Window
WWindowStatus ws = WWindowStatus.get(request);
@ -151,15 +208,22 @@ public class WWindow extends HttpServlet
ws = new WWindowStatus(mWindowVO);
sess.setAttribute(WWindowStatus.NAME, ws);
// Query
ws.curTab.query(ws.mWindow.isTransaction());
ws.curTab.navigate(0);
if (AD_Record_ID != 0 || AD_Table_ID != 0){ //If Zoom
ws.mWindow.initTab(ws.curTab.getTabNo());
ws.curTab.setQuery(MQuery.getEqualQuery(TableName + "_ID", AD_Record_ID));
ws.curTab.query(false);
}
else{
ws.mWindow.initTab(ws.curTab.getTabNo());
ws.curTab.query(ws.mWindow.isTransaction());
ws.curTab.navigate(0);
}
/**
* Build Page
*/
WebDoc doc = null;
if (ws.curTab.isSingleRow())
doc = getSR_Form (request.getRequestURI(), wsc, ws);
else
@ -168,7 +232,7 @@ public class WWindow extends HttpServlet
// fini
log.fine("Fini");
// log.trace(log.l6_Database, doc.toString());
WebUtil.createResponse (request, response, this, null, doc, true);
WebUtil.createResponse (request, response, this, null, doc, false);
log.fine("Closed");
} // doGet
@ -233,7 +297,7 @@ public class WWindow extends HttpServlet
//
log.fine("Fini");
// log.trace(log.l6_Database, doc.toString());
WebUtil.createResponse (request, response, this, null, doc, true);
WebUtil.createResponse (request, response, this, null, doc, false);
log.fine("Closed");
} // doPost
@ -288,9 +352,17 @@ public class WWindow extends HttpServlet
// move to detail
if (newTabNo > ws.curTab.getTabNo())
{
ws.curTab = ws.mWindow.getTab(newTabNo);
ws.mWindow.initTab(newTabNo);
ws.curTab = ws.mWindow.getTab(newTabNo);
ws.curTab.query(false);
ws.curTab.navigate(0);
//Modified by Rob Klein 6/01/07 create new record if no record exists
if (ws.curTab.getRowCount() < 1 ){
if (!ws.curTab.dataNew(false))
ws.curTab.dataIgnore();
}
}
// move back
else if (newTabNo < ws.curTab.getTabNo())
@ -331,14 +403,12 @@ public class WWindow extends HttpServlet
{
ws.curTab.navigateRelative(999999);
}
/**
* Find
*/
else if (p_cmd.equals("Find"))
else if (p_cmd.equals("Test"))
{
/** @todo Find */
/** @todo Chat */
}
/**
@ -357,16 +427,65 @@ public class WWindow extends HttpServlet
/** @todo Attachment */
}
/**
* Favorite
*/
else if (p_cmd.equals("Favorite"))
{
int AD_Window_ID = ws.curTab.getAD_Window_ID();
String sqlNode = "SELECT AD_Menu_ID FROM AD_Menu WHERE"
+ " AD_Window_ID = "+AD_Window_ID;
int Node_ID = DB.getSQLValue(null,sqlNode);
int AD_User_ID = Env.getAD_User_ID(wsc.ctx);
int AD_Role_ID = Env.getAD_Role_ID(wsc.ctx);
int AD_Org_ID = Env.getAD_Org_ID(wsc.ctx);
int AD_Client_ID = Env.getAD_Client_ID(wsc.ctx);
int AD_Tree_ID = DB.getSQLValue(null,
"SELECT COALESCE(r.AD_Tree_Menu_ID, ci.AD_Tree_Menu_ID)"
+ "FROM AD_ClientInfo ci"
+ " INNER JOIN AD_Role r ON (ci.AD_Client_ID=r.AD_Client_ID) "
+ "WHERE AD_Role_ID=?", AD_Role_ID);
if (AD_Tree_ID <= 0)
AD_Tree_ID = 10; // Menu
String sql = "SELECT count(*) FROM AD_TreeBar WHERE"
+ " Node_ID = "+Node_ID
+ " AND CreatedBy = "+AD_User_ID
+ " AND AD_Tree_ID = "+AD_Tree_ID;
int Favorite = DB.getSQLValue(null,sql);
if (Favorite >0){
sql = "DELETE FROM AD_TreeBar WHERE"
+ " Node_ID = "+Node_ID
+ " AND CreatedBy = "+AD_User_ID
+ " AND AD_Tree_ID = "+AD_Tree_ID;
DB.executeUpdate(sql, null);
}
else{
sql = "INSERT INTO AD_TreeBar "
+ "( Node_ID, AD_User_ID, AD_Client_ID, AD_Org_ID,"
+ " IsActive, CreatedBy, AD_Tree_ID, UpdatedBy)"
+ "VALUES ( "+Node_ID+", "+AD_User_ID+", "+AD_Client_ID+", "+AD_Org_ID
+ ", 'Y', "+AD_User_ID+", "+AD_Tree_ID+", "+AD_User_ID+")";
DB.executeUpdate(sql, null);
}
}
/**
* History
*/
else if (p_cmd.equals("History"))
{
if (ws.mWindow.isTransaction() && ws.curTab.getWindowNo() == 0)
{
//Modified by Rob Klein 4/29/07
//if (ws.mWindow.isTransaction() && ws.curTab.getWindowNo() == 0)
//{
ws.mWindow.initTab(ws.curTab.getTabNo());
ws.curTab.query( !ws.curTab.isOnlyCurrentRows() );
ws.curTab.navigate(0);
}
//}
}
/**
@ -375,6 +494,7 @@ public class WWindow extends HttpServlet
else if (p_cmd.equals("Report"))
{
/** @todo Report */
}
/**
@ -393,7 +513,7 @@ public class WWindow extends HttpServlet
if (!ws.curTab.dataNew(false))
ws.curTab.dataIgnore();
}
/**
* Delete
*/
@ -576,15 +696,26 @@ public class WWindow extends HttpServlet
*/
private Object getFieldValue (WebSessionCtx wsc, GridField mField, String value)
{
if (value == null || value.length() == 0)
return null;
//Modified by Rob Klein 4/29/07
//if (value == null || value.length() == 0)
//return null;
Object defaultObject = null;
int dt = mField.getDisplayType();
String columnName = mField.getColumnName();
if (value == null || value.length() == 0){
defaultObject = mField.getDefault();
mField.setValue (defaultObject, true);
if (value == null || value.length() == 0 || mField.getValue() == null){
return null;}
else
value = mField.getValue().toString();
}
// BigDecimal
if (DisplayType.isNumeric(dt))
{
{
BigDecimal bd = null;
try
{
@ -598,7 +729,7 @@ public class WWindow extends HttpServlet
if (nn instanceof BigDecimal)
bd = (BigDecimal)nn;
else
bd = new BigDecimal(nn.toString());
bd = new BigDecimal(nn.toString());
}
catch (Exception e)
{
@ -611,7 +742,7 @@ public class WWindow extends HttpServlet
// ID
else if (DisplayType.isID(dt))
{
{
Integer ii = null;
try
{
@ -625,7 +756,7 @@ public class WWindow extends HttpServlet
// -1 indicates NULL
if (ii.intValue() == -1)
ii = null;
log.fine("ID: " + columnName + "=" + value + " -> " + ii);
log.fine("ID: " + columnName + "=" + value + " -> " + ii);
return ii;
}
@ -647,7 +778,7 @@ public class WWindow extends HttpServlet
log.warning("Date: " + columnName + "=" + value + ERROR);
return ERROR;
}
log.fine("Date: " + columnName + "=" + value + " -> " + ts);
log.fine("Date: " + columnName + "=" + value + " -> " + ts);
return ts;
}
@ -657,12 +788,12 @@ public class WWindow extends HttpServlet
Boolean retValue = Boolean.FALSE;
if (value.equals("true"))
retValue = Boolean.TRUE;
log.fine("YesNo: " + columnName + "=" + value + " -> " + retValue);
return retValue;
log.fine("YesNo: " + columnName + "=" + value + " -> " + retValue);
return retValue;
}
// treat as string
log.fine(columnName + "=" + value);
log.fine(columnName + "=" + value);
return value;
} // getFieldValue
@ -674,19 +805,23 @@ public class WWindow extends HttpServlet
* @param ws window status
* @return Form
*/
private WebDoc getSR_Form (String action, WebSessionCtx wsc, WWindowStatus ws)
public WebDoc getSR_Form (String action, WebSessionCtx wsc, WWindowStatus ws)
{
log.fine("Tab=" + ws.curTab.getTabNo());
/**********************
* For all Fields
*/
table table = new table()
.setAlign(AlignType.CENTER);
// table.setBorder(1).setBorderColor("#00FF00"); // debug field lines
//Modified by Rob Klein 4/29/07
//table table = new table()
// .setAlign(AlignType.CENTER);
table table = new table();
table.setClass("centerTable");
StringBuffer scriptSrc = new StringBuffer();
//
tr line = new tr();
//Modified by Rob Klein 4/29/07
boolean isTabRO = ws.curTab.isReadOnly();
if (ws.curTab.isDisplayed())
{
int noFields = ws.curTab.getFieldCount();
@ -699,6 +834,12 @@ public class WWindow extends HttpServlet
* Get Data and convert to String (singleRow)
*/
Object oData = ws.curTab.getValue(field);
//Modified by Rob Klein 4/29/07
/**
* Get Record ID and Table ID for Processes
*/
int recordID = ws.curTab.getRecord_ID();
int tableID = ws.curTab.getAD_Table_ID();
/**
* Display field
@ -709,7 +850,9 @@ public class WWindow extends HttpServlet
line = new tr();
//
boolean hasDependents = ws.curTab.hasDependants(columnName);
addField(wsc, line, field, oData, hasDependents);
//Modified by Rob Klein 4/29/07
addField(wsc, line, field, oData, hasDependents, recordID, tableID, isTabRO, i, ws.curTab);
//addField(wsc, line, field, oData, hasDependents);
table.addElement(line);
// Additional Values
String dispLogic = field.getDisplayLogic();
@ -741,7 +884,7 @@ public class WWindow extends HttpServlet
* @param ws window status
* @return Form
*/
private WebDoc getMR_Form (String action, WebSessionCtx wsc, WWindowStatus ws)
public WebDoc getMR_Form (String action, WebSessionCtx wsc, WWindowStatus ws)
{
log.fine("Tab=" + ws.curTab.getTabNo());
@ -751,11 +894,15 @@ public class WWindow extends HttpServlet
* Table Header
*/
table table = new table().setAlign(AlignType.CENTER);
table.setClass("MultiRow");
//Modified by Rob Klein 4/29/07
table.setClass("MultiRow table-autofilter table-filterable table-autosort table-autostripe table-stripeclass:alternate");
//.setClass("MultiRow");
table.setBorder(1);
table.setCellSpacing(1);
tr line = new tr();
// First Column
//Modified by Rob Klein 4/29/07
//line.addElement(new th().addElement(" "));
line.addElement(new th().addElement(" "));
// Tab not displayed
if (!ws.curTab.isDisplayed())
@ -769,13 +916,39 @@ public class WWindow extends HttpServlet
if (field.isDisplayed(false))
{
th th = new th();
th.addElement(field.getHeader()); // Name
th.setAbbr(field.getDescription()); // Description
line.addElement(th);
//Modified by Rob Klein 4/29/07 with Autofilter
th.addElement(field.getHeader()).setClass("table-filterable table-filtered table-sortable:default");
//th.addElement(field.getHeader());
th.setAbbr(field.getDescription());
line.addElement(th);
}
} // for all columns
table.addElement(new thead().addElement(line));
// Modified by Rob Klein Client Side Filter Manual Filter 6/1/07
tr line2 = new tr();
th th = new th();
//input filter = new input (input.TYPE_TEXT, " filter", "");
//filter.setOnKeyUp("Table.filter(this,this)");
th.addElement(" ");
line2.addElement(th);
input filter = null;
for (int colNo = 0; colNo < noFields; colNo++)
{
GridField field = ws.curTab.getField(colNo);
if (field.isDisplayed(false))
{
th = new th();
filter = new input (input.TYPE_TEXT, field.getHeader()+"filter", "");
filter.setOnKeyUp("Table.filter(this,this)");
th.addElement(filter);
line2.addElement(th);
//line.addElement(th);
}
} // for all columns
//Modified by Rob Klein 4/29/07
table.addElement(new thead().addElement(line).addElement(line2));
//Modified by Rob Klein 4/29/07
table.addElement("<TBODY>");
/**
* Table Lines
*/
@ -858,8 +1031,10 @@ public class WWindow extends HttpServlet
line.addElement(td);
} // for all columns
table.addElement(line);
} // for all table lines
//Modified by Rob Klein 4/29/07
table.addElement("</TBODY>");
// Status Line
String statusDB = String.valueOf(initRowNo+1) + "-" + String.valueOf(lastRow) + " # " + ws.curTab.getRowCount();
@ -876,7 +1051,7 @@ public class WWindow extends HttpServlet
* @param statusDB status db info
* @return Form
*/
private static WebDoc createLayout (String action, table contentTable,
private WebDoc createLayout (String action, table contentTable,
WebSessionCtx wsc, WWindowStatus ws, String statusInfo, String statusDB)
{
form myForm = null;
@ -893,43 +1068,43 @@ public class WWindow extends HttpServlet
// Set Title of main window
String title = ws.mWindow.getName() + " - " + wsc.loginInfo;
myForm.addElement(new script("top.document.title='" + title + "';"));
//Modified by Rob Klein 4/29/07
// Buttons
td toolbar = new td(null, AlignType.LEFT, AlignType.MIDDLE, true);
td toolbar = new td("toolbar", AlignType.LEFT, AlignType.MIDDLE, true);
// Toolbar
toolbar.addElement(createImage(AD_Language, "Ignore",
"reset();", true, false));
toolbar.addElement(createImageLink (AD_Language, "Menu",
"parent.resizeFrame('5,*')",
true, false));
toolbar.addElement(createImageLink (AD_Language, "Ignore",
"'reset'", true, false));
toolbar.addElement("&nbsp;");
toolbar.addElement(createImage(AD_Language, "Help",
"startPopup('WHelp?AD_Window_ID=" + ws.mWindow.getAD_Window_ID() + "');",
toolbar.addElement(createImageLink (AD_Language, "Help",
"startPopup('WHelp?AD_Window_ID=" + ws.mWindow.getAD_Window_ID() + "')",
true, false));
toolbar.addElement(createImage(AD_Language, "New"));
toolbar.addElement(createImage(AD_Language, "Delete",
"if (confirm(deleteText)) submit();", true, false));
toolbar.addElement(createImage(AD_Language, "Save"));
toolbar.addElement(createImageLink (AD_Language, "New"));
toolbar.addElement(createImageLink (AD_Language, "Delete","'if(confirm(deleteText))'", true, false));
toolbar.addElement(createImageLink (AD_Language, "Save"));
toolbar.addElement("&nbsp;");
toolbar.addElement(createImage(AD_Language, "Find"));
toolbar.addElement(createImage(AD_Language, "Refresh"));
toolbar.addElement(createImage(AD_Language, "Attachment",
"startPopup('WAttachment');",
ws.curTab.canHaveAttachment(), ws.curTab.hasAttachment()));
toolbar.addElement(createImage(AD_Language, "Multi", null, true, !ws.curTab.isSingleRow()));
toolbar.addElement(createImageLink (AD_Language, "Chat","startPopup('WChat')", true, false));
toolbar.addElement(createImageLink (AD_Language, "Refresh"));
toolbar.addElement(createImageLink (AD_Language, "Attachment",
"startPopup('WAttachment')", ws.curTab.canHaveAttachment(), ws.curTab.hasAttachment()));
toolbar.addElement(createImageLink (AD_Language, "Multi", null, true, !ws.curTab.isSingleRow()));
toolbar.addElement("&nbsp;");
toolbar.addElement(createImage(AD_Language, "History",
toolbar.addElement(createImageLink (AD_Language, "History",
null, ws.mWindow.isTransaction()&&ws.curTab.getTabNo()==0, !ws.curTab.isOnlyCurrentRows()));
toolbar.addElement("&nbsp;");
boolean isFirst = ws.curTab.getCurrentRow() < 1;
toolbar.addElement(createImage(AD_Language, "First", null, !isFirst, false));
toolbar.addElement(createImage(AD_Language, "Previous", null, !isFirst, false));
toolbar.addElement(createImageLink (AD_Language, "First", null, !isFirst, false));
toolbar.addElement(createImageLink (AD_Language, "Previous", null, !isFirst, false));
boolean isLast = ws.curTab.getCurrentRow()+1 == ws.curTab.getRowCount();
toolbar.addElement(createImage(AD_Language, "Next", null, !isLast, false));
toolbar.addElement(createImage(AD_Language, "Last", null, !isLast, false));
toolbar.addElement(createImageLink (AD_Language, "Next", null, !isLast, false));
toolbar.addElement(createImageLink (AD_Language, "Last", null, !isLast, false));
toolbar.addElement("&nbsp;");
toolbar.addElement(createImage(AD_Language, "Report"));
toolbar.addElement(createImage(AD_Language, "Print"));
toolbar.addElement(createImageLink (AD_Language, "Report","startPopup('WReport')", true, false));
toolbar.addElement("&nbsp;");
toolbar.addElement(createImage(AD_Language, "Exit"));
toolbar.addElement(createImageLink (AD_Language, "Favorite"));
toolbar.addElement(createImageLink (AD_Language, "Exit"));
// Tabs
td tabbar = new td("windowCenter", AlignType.LEFT, AlignType.MIDDLE, false);
tabbar.addElement(new input(input.TYPE_HIDDEN, P_Tab, ""));
@ -938,23 +1113,26 @@ public class WWindow extends HttpServlet
GridTab tab = ws.mWindow.getTab(i);
if (tab.isSortTab())
continue;
big big = new big(tab.getName());
//Modified by Rob Klein 4/29/07
a big = new a("#",new span(tab.getName()));
if (ws.curTab.getTabNo() == i)
big.setID("tabSelected"); // css
else
{
big.setID("tab"); // css
big.setOnClick("alert('" + tab.getName() + "');");
big.setOnClick("document." + FORM_NAME + "." + P_Tab + ".value='" + i + "';submit();");
//Modified by Rob Klein 4/29/07
big.setID("tab"); // css
big.setOnClick( "SubmitForm(" + i + ",'Submit','tab')");
}
// Status: Description
if (tab.getDescription().length() > 0)
big.setOnMouseOver("status='" + tab.getDescription() + "';return true;");
tabbar.addElement(big);
}
// Top Table
table topTable = new table ("0", "0", "5", "100%", null);
//Modified by Rob Klein 4/29/07
table topTable = new table ("0", "0", "0", "100%", null);
topTable.setID("WWindow.topTable");
topTable.addElement(new tr(toolbar));
topTable.addElement(new tr(tabbar));
@ -972,10 +1150,18 @@ public class WWindow extends HttpServlet
statusLine.addElement(new td().setWidth("10%").setAlign(AlignType.RIGHT)
.addElement(new small(statusDB)));
statusLine.addElement(new td().setWidth("5%").setAlign(AlignType.RIGHT)
.addElement(createImage(AD_Language, "Save")));
//Modified by Rob Klein 4/29/07
.addElement(createImageLink (AD_Language, "Save")));
statusTable.addElement(statusLine).setClass("windowCenter");
myForm.addElement(statusTable);
//Beg Modified by Rob Klein
//div calpopdiv = new div();
//calpopdiv.setStyle("visibility:hidden;background-color:white;layer-background-color:white;");
//calpopdiv.setID("cal1div");
//myForm.addElement(calpopdiv);
//End Modified by Rob Klein
// fini
/** @todo Dynamic Display */
// myForm.addElement(new script("dynDisplay(); createWCmd();")); // initial Display & set Cmd Window
@ -1006,8 +1192,8 @@ public class WWindow extends HttpServlet
return doc;
} // createPage
/**************************************************************************
/**************************************************************************
* Create Image with name, id of button_name and set P_Command onClick
* @param AD_Language
* @param name Name of the Image used also for Name24.gif
@ -1023,7 +1209,7 @@ public class WWindow extends HttpServlet
imgName.append("D");
else if (pressed)
imgName.append("X");
imgName.append("24.gif");
imgName.append("16.gif");
//
img img = new img (WebEnv.getImageDirectory(imgName.toString()), name);
if (enabled)
@ -1033,11 +1219,11 @@ public class WWindow extends HttpServlet
img.setID("imgButton"); // css
else
img.setID("imgButtonPressed"); // css
//
if (js_command == null)
js_command = "submit();";
if (js_command.length() > 0 && enabled)
img.setOnClick("document." + FORM_NAME + "." + P_Command + ".value='" + name + "';" + js_command);
img.setHeight(16);
img.setWidth(16);
img.setBorder(0);
img.setTitle(name);
//
//
return img;
} // createImage
@ -1053,6 +1239,50 @@ public class WWindow extends HttpServlet
return createImage (AD_Language, name, null, true, false);
} // createImage
//Modified by Rob Klein 4/29/07
/**************************************************************************
* Create Image with name, id of button_name and set P_Command onClick
* @param AD_Language
* @param name Name of the Image used also for Name24.gif
* @param js_command Java script command, null results in 'submit();', an empty string disables OnClick
* @param enabled Enable the immage button, if not uses the "D" image
* @param pressed If true, use the "X" image
* @return Image
*/
private static a createImageLink (String AD_Language, String name, String js_command, boolean enabled, boolean pressed)
{
a img = new a ("#", createImage (AD_Language, name));
if (!pressed || !enabled)
img.setID("imgButtonLink"); // css
else
img.setID("imgButtonPressedLink"); // css
//
if (js_command == null)
js_command = "'Submit'";
if (js_command.length() > 0 && enabled)
img.setOnClick( "SubmitForm('" + name + "', " + js_command + ",'toolbar');return false;");
img.setClass("ToolbarButton");
img.setOnMouseOver("window.status='"+name+"';return true;");
img.setOnMouseOut("window.status='';return true;");
img.setOnBlur("this.hideFocus=false");
//
return img;
} // createImageLink
/**
* Create enabled Image with name, id of button_name and sumbit command
* @param AD_Language
* @param name Name of the Image used also for Name24.gif
* @return Image
*/
private static a createImageLink (String AD_Language, String name)
{
return createImageLink (AD_Language, name, null, true, false);
} // createImageLink
/**************************************************************************
* Add Field to Line
@ -1063,7 +1293,8 @@ public class WWindow extends HttpServlet
* @param hasDependents has Callout function(s)
*/
private void addField (WebSessionCtx wsc, tr line, GridField field,
Object oData, boolean hasDependents)
Object oData, boolean hasDependents, int recordID, int tableID, boolean tabRO, int fieldNumber,
GridTab mTab)
{
String columnName = field.getColumnName();
// Any Error?
@ -1072,6 +1303,30 @@ public class WWindow extends HttpServlet
oData = field.getErrorValue();
int dt = field.getDisplayType();
boolean hasCallout = field.getCallout().length() > 0;
//Modified by Rob Klein 4/29/07
if(!field.getFieldGroup().equals(sectionNameOld)&&!field.getFieldGroup().equals("")&&field.getFieldGroup()!=null)
{
log.fine("Fieldgroup=" + field.getFieldGroup()+".");
td td1 = new td();
td1.setClass("Fieldgroup");
td1.addElement(field.getFieldGroup());
td td2 = new td().setColSpan(4);
td2.setClass("Fieldgroup");
td2.addElement(new hr().setWidth("100%"));
line.addElement( new tr().addElement(td1));
line.addElement( new tr().addElement(td2));
sectionNameOld = field.getFieldGroup();
}
/** Set read only value
*
*/
boolean fieldRO = true;
if (tabRO==true)
fieldRO = true;
else
fieldRO = !field.isEditable(true);
/**
* HTML Label Element
@ -1085,12 +1340,16 @@ public class WWindow extends HttpServlet
columnName, field.getHeader(), field.getDescription(),
dt, field.getFieldLength(), field.getDisplayLength(), field.isLongField(),
// readOnly context check, mandatory no context check,
!field.isEditable(true), field.isMandatory(false), error,
hasDependents, hasCallout);
//Modified by Rob Klein 4/29/07
//!field.isEditable(true), field.isMandatory(false), error,
fieldRO, field.isMandatory(false), error,
hasDependents, hasCallout,field.getAD_Process_ID(),field.getAD_Window_ID(),
recordID, tableID, fieldNumber, field.getDefault(), field.getCallout(),
mTab, field );
line
.addElement(wField.getLabel())
.addElement(wField.getField(field.getLookup(), oData));
.addElement(wField.getLabel())
.addElement(wField.getField(field.getLookup(), oData));
} // addField
} // WWindow

View File

@ -51,7 +51,7 @@ public class WWindowStatus
*/
public WWindowStatus (GridWindowVO mWindowVO)
{
mWindow = new GridWindow(mWindowVO);
mWindow = new GridWindow(mWindowVO);
curTab = mWindow.getTab(0);
curTab.setSingleRow(true);
//

View File

@ -0,0 +1,227 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.www;
import java.io.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Level;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.compiere.apps.AEnv;
import org.compiere.apps.AWindow;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* HTML Zoom Window
*
* @author Rob Klein
* @version $Id: WZoom.java $
*/
public class WZoom extends HttpServlet
{
/** Logger */
private static CLogger log = CLogger.getCLogger(WAttachment.class);
/**
* Initialize global variables
*/
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
if (!WebEnv.initWeb(config))
throw new ServletException("WZoom.init");
} // init
public static final String P_Record_ID = "AD_Record_ID";
public static final String P_Table_ID = "AD_Table_ID";
private static int s_WindowNo = 3;
/**
* Process the HTTP Get request.
* Initial display and streaming
* @param request request
* @param response response
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
HttpSession session = request.getSession(false);
WWindowStatus ws = WWindowStatus.get(request);
WebDoc doc = null;
if (session == null || ws == null)
{
doc = WebDoc.createPopup ("No Context");
doc.addPopupClose(ws.ctx);
}
else
{
String error = null;
int AD_Record_ID = WebUtil.getParameterAsInt(request, P_Record_ID);
int AD_Table_ID = WebUtil.getParameterAsInt(request, P_Table_ID);
if (AD_Record_ID == 0 || AD_Table_ID == 0)
{
doc = WebDoc.createPopup ("Invalid Record ID or Table ID");
doc.addPopupClose(ws.ctx);
}
else
{
doc = createPage (ws.ctx, request,AD_Record_ID,
AD_Table_ID);
}
}
//
WebUtil.createResponse(request, response, this, null, doc, false);
} // doGet
/**
* Process the HTTP Post request.
* Update Attachment
* @param request request
* @parem response response
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession sess = request.getSession(false);
WWindowStatus ws = WWindowStatus.get(request);
WebDoc doc = null;
//
doc = WebDoc.create ("Help - Post Not Implemented");
//
WebUtil.createResponse(request, response, this, null, doc, false);
} // doPost
/**
* Create Attachment Page
* @param ctx context
* @param AD_Attachment_ID id for existing attachment
* @param AD_Table_ID table for new attachment
* @param Record_ID record for new attachment
* @param error optional error message
* @return WebDoc
*/
public static WebDoc createPage (Properties ctx, HttpServletRequest request, int AD_Record_ID,
int AD_Table_ID)
{
//WebDoc doc = WebDoc.createPopup (Msg.translate(ctx, "AD_Attachment_ID"));
WebDoc doc = null;
String TableName = null;
int AD_Window_ID = 0;
int PO_Window_ID = 0;
String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE AD_Table_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
TableName = rs.getString(1);
AD_Window_ID = rs.getInt(2);
PO_Window_ID = rs.getInt(3);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
if (TableName == null || AD_Window_ID == 0){
doc = WebDoc.createPopup ("No Context");
doc.addPopupClose(ctx);
return doc;
}
// PO Zoom ?
boolean isSOTrx = true;
if (PO_Window_ID != 0)
{
String whereClause = TableName + "_ID=" + AD_Record_ID;
isSOTrx = DB.isSOTrx(TableName, whereClause);
if (!isSOTrx)
AD_Window_ID = PO_Window_ID;
}
/**
* New Window data
*/
WWindowStatus ws = WWindowStatus.get(request);
HttpSession sess = request.getSession();
WebSessionCtx wsc = WebSessionCtx.get(request);
if (ws != null)
{
int WindowNo = ws.mWindow.getWindowNo();
log.fine("Disposing - WindowNo=" + WindowNo + ", ID=" + ws.mWindow.getAD_Window_ID());
ws.mWindow.dispose();
Env.clearWinContext(wsc.ctx, WindowNo);
}
GridWindowVO mWindowVO = GridWindowVO.create (ctx, s_WindowNo++, AD_Window_ID, 0);
if (mWindowVO == null)
{
String msg = Msg.translate(ctx, "AD_Window_ID") + " "
+ Msg.getMsg(ctx, "NotFound") + ", ID=" + AD_Window_ID + "/" + 0;
doc = WebDoc.createPopup (msg);
doc.addPopupClose(ctx);
return doc;
}
// Create New Window
ws = new WWindowStatus(mWindowVO);
sess.setAttribute(WWindowStatus.NAME, ws);
// Query
ws.mWindow.initTab(ws.curTab.getTabNo());
ws.curTab.setQuery(MQuery.getEqualQuery(TableName + "_ID", AD_Record_ID));
ws.curTab.query(false);
//ws.curTab.navigate(0);
/**
* Build Page
*/
//doc = WWindow.getSR_Form (request.getRequestURI(), wsc, ws);
return doc;
} // createPage
} // WZoom

View File

@ -16,6 +16,8 @@
*****************************************************************************/
package org.compiere.www;
import java.sql.Timestamp;
import java.util.logging.*;
import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.compiere.model.*;
@ -29,6 +31,7 @@ import org.compiere.util.*;
*/
public class WebField
{
protected static CLogger log = CLogger.getCLogger(WWindow.class);
/**
* Web Field
* @param wsc session context
@ -49,11 +52,13 @@ public class WebField
String columnName, String name, String description,
int displayType, int fieldLength, int displayLength, boolean longField,
boolean readOnly, boolean mandatory, boolean error,
boolean hasDependents, boolean hasCallout)
boolean hasDependents, boolean hasCallout, int AD_Process_ID,
int AD_Window_ID, int AD_Record_ID, int AD_Table_ID, int fieldNumber, Object defaultvalue,
String callOut, GridTab mTab, GridField mField )
{
super ();
m_wsc = wsc;
m_columnName = columnName;
m_columnName = columnName;
if (name == null || name.length() == 0)
m_name = columnName;
else
@ -61,7 +66,12 @@ public class WebField
if (description != null && description.length() > 0)
m_description = description;
//
m_defaultObject = defaultvalue;
m_displayType = displayType;
m_processID = AD_Process_ID;
m_windowID = AD_Window_ID;
m_tableID = AD_Table_ID;
m_recordID = AD_Record_ID;
m_fieldLength = fieldLength;
m_displayLength = displayLength;
if (m_displayLength == 0)
@ -73,6 +83,11 @@ public class WebField
m_error = error;
m_hasDependents = hasDependents;
m_hasCallout = hasCallout;
m_callOut = callOut;
m_fieldNumber = fieldNumber;
m_Tab = mTab;
m_Field = mField;
//
} // WebField
@ -88,8 +103,16 @@ public class WebField
private String m_columnName;
private String m_name;
private String m_description;
private String m_callOut;
private GridTab m_Tab;
private GridField m_Field;
//
private Object m_defaultObject;
private int m_displayType;
private int m_processID;
private int m_windowID;
private int m_tableID;
private int m_recordID;
private int m_fieldLength;
private int m_displayLength;
private boolean m_longField;
@ -99,6 +122,8 @@ public class WebField
private boolean m_error;
private boolean m_hasDependents;
private boolean m_hasCallout;
private int m_fieldNumber;
//Modified by Rob Klein 4/29/07
/**
* Get the field Label
@ -106,7 +131,7 @@ public class WebField
*/
public td getLabel()
{
if (m_displayType == DisplayType.YesNo)
if (m_displayType == DisplayType.YesNo||m_displayType == DisplayType.Button)
return new td(WebEnv.NBSP);
//
label myLabel = new label(m_columnName + "F", null, Util.maskHTML(m_name));
@ -146,11 +171,13 @@ public class WebField
*/
public td getField (Lookup lookup, Object data)
{
String dataValue = (data == null) ? "" : data.toString();
//
if (m_displayType == DisplayType.Search
|| m_displayType == DisplayType.Location
|| m_displayType == DisplayType.Account)
|| m_displayType == DisplayType.Account
|| m_displayType == DisplayType.PAttribute)
{
String dataDisplay = "";
if (lookup != null && data != null)
@ -159,27 +186,41 @@ public class WebField
}
if (DisplayType.isLookup(m_displayType)
|| m_displayType == DisplayType.Locator)
return getSelectField(lookup, dataValue);
|| m_displayType == DisplayType.Locator){
return getSelectField(lookup, dataValue);}
if (m_displayType == DisplayType.YesNo)
return getCheckField (dataValue);
if (m_displayType == DisplayType.YesNo){
return getCheckField (dataValue);}
if (m_displayType == DisplayType.Button)
if (m_displayType == DisplayType.Button){
return getButtonField ();
}
//Modified by Rob Klein 4/29/07
if (DisplayType.isDate(m_displayType))
return getDateField(data);
else if (DisplayType.isNumeric(m_displayType))
{
return getPopupDateField(data);
}
else if (DisplayType.isNumeric(m_displayType)){
return getNumberField(data);
}
// Strings
if (m_displayType == DisplayType.Text)
if (m_displayType == DisplayType.Text){
return getTextField (dataValue, 3);
else if (m_displayType == DisplayType.TextLong)
}
else if (m_displayType == DisplayType.TextLong){
return getTextField (dataValue, 10);
else if (m_displayType == DisplayType.Memo)
}
else if (m_displayType == DisplayType.Memo){
return getTextField (dataValue, 15);
}
//other
//if (m_displayType == DisplayType.PAttribute){
// return getPopupField(dataDisplay, dataValue);}
if (m_displayType == DisplayType.Assignment){
return getAssignmentField(data);}
return getStringField(dataValue);
} // getField
@ -267,6 +308,30 @@ public class WebField
return createTD(string);
} // getDateField
/**
* Create Assignment Field
* @param data initial value
* @return td
*/
private td getAssignmentField (Object data)
{
input string = new input(input.TYPE_TEXT, m_columnName, Util.maskHTML(""));
if (m_fieldLength > 0)
string.setMaxlength(m_fieldLength);
//
string.setDisabled(true);
if (m_error)
string.setClass(C_ERROR);
else if (m_mandatory)
string.setClass(C_MANDATORY);
//
if (m_hasDependents || m_hasCallout)
string.setOnChange("startUpdate(this);");
return createTD(string).addElement("Not Yet Supported");
}
/**
* Create Number Field
* @param data initial value
@ -275,15 +340,24 @@ public class WebField
private td getNumberField (Object data)
{
String formattedData = "";
//Modified by Rob Klein 4/29/07
if (data == null)
;
if (m_displayType == DisplayType.Amount )
formattedData = m_wsc.amountFormat.format(0.00);
else if (m_displayType == DisplayType.Number
|| m_displayType == DisplayType.CostPrice)
formattedData = m_wsc.numberFormat.format(0.00);
else if (m_displayType == DisplayType.Integer)
formattedData = m_wsc.integerFormat.format(0);
else
formattedData = "0";
else if (m_displayType == DisplayType.Amount)
formattedData = m_wsc.amountFormat.format(data);
else if (m_displayType == DisplayType.Number
|| m_displayType == DisplayType.CostPrice)
formattedData = m_wsc.numberFormat.format(data);
else if (m_displayType == DisplayType.Quantity)
formattedData = m_wsc.quantityFormat.format(data);
//else if (m_displayType == DisplayType.Quantity)
// formattedData = m_wsc.quantityFormat.format(data);
else if (m_displayType == DisplayType.Integer)
formattedData = m_wsc.integerFormat.format(data);
else
@ -345,15 +419,16 @@ public class WebField
// The hidden data field Name=columnName
input hidden = new input (input.TYPE_HIDDEN, m_columnName, dataValue);
hidden.setID(m_columnName + "D");
//Modified by Rob Klein 4/29/07
input display = null;
// The display field Name=columnName, ID=FcolumnName
display = new input(input.TYPE_TEXT, m_columnName, Util.maskHTML(dataDisplay));
display.setID(m_columnName + "F");
display.setReadOnly(true);
// The display field Name=columnName, ID=FcolumnName
input display = new input(input.TYPE_TEXT, m_columnName, Util.maskHTML(dataDisplay));
// display.setSize(field.getDisplayLength()).setMaxlength(field.getFieldLength());
display.setID(m_columnName + "F");
display.setReadOnly(true);
//Modified by Rob Klein 4/29/07
// The button Name=columnName, ID=BcolumnName
input button = new input (input.TYPE_IMAGE, m_columnName, "x");
input button = new input (input.TYPE_IMAGE, m_columnName+ "B", "x");
button.setID(m_columnName + "B");
String gif = "PickOpen10.gif";
if (m_displayType == DisplayType.Location)
@ -364,14 +439,106 @@ public class WebField
gif = "BPartner10.gif";
else if (m_columnName.equals("M_Product_ID"))
gif = "Product10.gif";
//Set PopUp
button.setSrc(WebEnv.getImageDirectory(gif));
button.setBorder(1);
if (m_displayType == DisplayType.Location)
button.setOnClick("startLocation('" + m_columnName + "');return false;");
else if (m_displayType == DisplayType.Account)
button.setOnClick("startAccount('" + m_columnName + "');return false;");
else
button.setOnClick("startLookup('" + m_columnName + "');return false;");
// modified by rob klein 4/29/07
button.setOnClick("startLookup('" + m_columnName + "', "+m_processID+");return false;");
else
//modified by rob klein 4/29/07
button.setOnClick("startLookup('" + m_columnName + "', "+m_processID+");return false;");
//Set Zoom
//Add by Rob Klein 6/6/2007
input buttonZoom = null;
if(m_Field != null)
{
buttonZoom = new input (input.TYPE_IMAGE, m_columnName+ "Z", "x");
buttonZoom.setID(m_columnName + "Z");
buttonZoom.setSrc(WebEnv.getImageDirectory("Zoom10.gif"));
buttonZoom.setBorder(1);
StringBuffer sql = null;
int refID = m_Field.getAD_Reference_Value_ID();
if (refID > 0)
sql = new StringBuffer ("SELECT AD_Table_ID"
+ "FROM AD_Ref_Table WHERE AD_Reference_ID = "+refID);
else
sql = new StringBuffer ("SELECT AD_Table_ID "
+ "FROM AD_Table WHERE TableName = '"+m_columnName.replace("_ID", "")+"'");
int tableID = DB.getSQLValue(null, sql.toString());
buttonZoom.setOnClick("startZoom('" + tableID + "', "+m_Field.getValue()+");return false;");
}
//
if (m_error)
display.setClass(C_ERROR);
else if (m_mandatory)
display.setClass(C_MANDATORY);
//
if (m_hasDependents || m_hasCallout)
display.setOnChange("startUpdate(this);");
//
return createTD(hidden)
.addElement(display)
.addElement(button)
.addElement(buttonZoom);
} // getPopupField
/**
* Get Popup Field (lookup, location, account, ..)
* @param dataDisplay data to be displayed
* @param dataValue data of value field
* @return td
*/
private td getPopupDateField ( Object data)
{
// The hidden data field Name=columnName
String dataValue = (data == null) ? "" : data.toString();
input hidden = new input (input.TYPE_HIDDEN, m_columnName+"D", dataValue);
hidden.setID(m_columnName + "D");
input display = null;
// The display field Name=columnName, ID=FcolumnName
String formattedData = "";
if (data == null)
;
else if (m_displayType == DisplayType.DateTime){
if (dataValue.equals("@#Date@"))
formattedData = m_wsc.dateTimeFormat.format(new java.util.Date());
else
formattedData = m_wsc.dateTimeFormat.format(data);
}
else if (m_displayType == DisplayType.Date){
if (dataValue.equals("@#Date@"))
formattedData = m_wsc.dateFormat.format(new java.util.Date());
else
formattedData = m_wsc.dateFormat.format(data);
}
display = new input(input.TYPE_TEXT, m_columnName, formattedData);
display.setID(m_columnName + "F"+m_fieldNumber);
display.setReadOnly(true);
// The button Name=columnName, ID=BcolumnName
input button = new input (input.TYPE_IMAGE, m_columnName+ "B", "x");
button.setID(m_columnName + "B");
String gif = "PickOpen10.gif";
if (m_displayType == DisplayType.Date)
gif = "Calendar10.gif";
else if (m_displayType == DisplayType.DateTime)
gif = "Calendar10.gif";
button.setSrc(WebEnv.getImageDirectory(gif));
button.setBorder(1);
if (m_displayType == DisplayType.Date){
button.setOnClick("showCalendar('"+m_columnName+ "F"+m_fieldNumber+"', '%m/%d/%Y');return false;");
}
else if (m_displayType == DisplayType.DateTime){
button.setOnClick("showCalendar('"+m_columnName+ "F"+m_fieldNumber+"', '%b %d, %Y %H:%M:%S %p', '24', true);return false;");
}
//
if (m_error)
display.setClass(C_ERROR);
@ -379,7 +546,6 @@ public class WebField
display.setClass(C_MANDATORY);
//
if (m_hasDependents || m_hasCallout)
// hidden.setOnChange("startUpdate(this);");
display.setOnChange("startUpdate(this);");
//
return createTD(hidden)
@ -394,19 +560,62 @@ public class WebField
* @return selction td
*/
private td getSelectField (Lookup lookup, String dataValue)
{
select sel = new select(m_columnName, getOptions(lookup, dataValue));
{
if (dataValue.length()<1 && m_defaultObject != null) {
dataValue = m_defaultObject.toString();
}
select sel = new select(m_columnName, getOptions(lookup, dataValue));
sel.setID(m_columnName);
sel.setDisabled(m_readOnly);
if (m_error)
sel.setClass(C_ERROR);
else if (m_mandatory)
sel.setClass(C_MANDATORY);
//
if (m_hasDependents || m_hasCallout)
sel.setOnChange("startUpdate(this);");
//Set Zoom
//Add by Rob Klein 6/6/2007
input buttonZoom = null;
int refID = 0;
Object recordID =0;
if(m_Field != null && !m_readOnly)
{
buttonZoom = new input (input.TYPE_IMAGE, m_columnName+ "Z", "x");
buttonZoom.setID(m_columnName + "Z");
buttonZoom.setSrc(WebEnv.getImageDirectory("Zoom10.gif"));
buttonZoom.setBorder(1);
StringBuffer sql = null;
refID = m_Field.getAD_Reference_Value_ID();
if (m_displayType == DisplayType.List ){
sql = new StringBuffer ("SELECT AD_Table_ID "
+ "FROM AD_Table WHERE TableName = 'AD_Reference'");
recordID = refID;
}
else if (refID > 0 ){
sql = new StringBuffer ("SELECT AD_Table_ID "
+ "FROM AD_Ref_Table WHERE AD_Reference_ID = "+refID);
recordID =m_Field.getValue();
}
else{
sql = new StringBuffer ("SELECT AD_Table_ID "
+ "FROM AD_Table WHERE TableName = '"+m_columnName.replace("_ID", "")+"'");
recordID =m_Field.getValue();
}
int tableID = DB.getSQLValue(null, sql.toString());
buttonZoom.setOnClick("startZoom('" + tableID + "', '"+recordID+"');return false;");
}
//
return createTD(sel);
return createTD(sel).addElement(buttonZoom);
} // getSelectField
/**
@ -419,11 +628,33 @@ public class WebField
{
if (lookup == null)
return new option[0];
//boolean keyFound = false;
//
NamePair value = null;
Object[] list = lookup.getData (m_mandatory, true, !m_readOnly, false)
.toArray(); // if r/o also inactive
int size = list.length;
int size = list.length;
option[] options = new option[size];
if (size == 0 && dataValue.length()>0){
value = lookup.getDirect(dataValue, false, false);
if (value != null){
options = new option[2];
if (dataValue.length()<1){
options[0] = new option("-1").addElement("&nbsp;").setSelected(true);
options[1] = new option(value.getID()).addElement(value.getName());
}
else
{
options[0] = new option("-1").addElement("&nbsp;");
options[1] = new option(value.getID()).addElement(value.getName()).setSelected(true);
}
}
return options;
}
for (int i = 0; i < size; i++)
{
boolean isNumber = list[0] instanceof KeyNamePair;
@ -433,17 +664,23 @@ public class WebField
MLocator loc = (MLocator)list[i];
key = String.valueOf(loc.getM_Locator_ID());
String name = Util.maskHTML(loc.getValue());
options[i] = new option(key).addElement(name);
if (dataValue.equals(key))
options[i] = new option(key).addElement(name).setSelected(true);
else
options[i] = new option(key).addElement(name);
}
else if (isNumber)
{
KeyNamePair p = (KeyNamePair)list[i];
key = String.valueOf(p.getKey());
String name = Util.maskHTML(p.getName());
options[i] = new option(key).addElement(name);
if (dataValue.equals(key))
options[i] = new option(key).addElement(name).setSelected(true);
else
options[i] = new option(key).addElement(name);
}
else
{
{
ValueNamePair p = (ValueNamePair)list[i];
key = p.getValue();
if (key == null || key.length() == 0)
@ -452,11 +689,15 @@ public class WebField
if (name == null || name.length() == 0)
name = "???";
name = Util.maskHTML(name);
options[i] = new option(key).addElement(name);
}
if (dataValue.equals(key))
options[i].setSelected(true);
if (dataValue.equals(key))
options[i] = new option(key).addElement(name).setSelected(true);
else
options[i] = new option(key).addElement(name);
}
}
//If no key found then default to first value
//if (!keyFound && size>0)
//options[0].setSelected(true);
return options;
} // getOptions
@ -467,10 +708,12 @@ public class WebField
*/
private td getButtonField ()
{
input button = new input(input.TYPE_BUTTON, m_columnName, Util.maskHTML(m_name));
//Modified by Rob Klein 4/29/07
input button = new input("button", m_columnName, " "+Util.maskHTML(m_name));
button.setID(m_columnName);
button.setDisabled(m_readOnly);
button.setOnClick("startButton(this);");
button.setClass("processbtn");
button.setDisabled(m_readOnly);
button.setOnClick("startButton("+m_processID+", "+m_windowID+", "+m_recordID+", "+m_tableID+", '"+ m_columnName+"');");
return createTD(button)
.setAlign(AlignType.LEFT); // overwrite
} // getButtonField