1 14 package org.compiere.www; 15 16 import javax.servlet.*; 17 import javax.servlet.http.*; 18 import java.io.*; 19 import java.util.*; 20 import java.sql.*; 21 22 import org.apache.ecs.xhtml.*; 24 25 import org.compiere.util.*; 26 import org.compiere.model.*; 27 28 34 public class WFieldUpdate extends HttpServlet 35 { 36 41 public void init(ServletConfig config) throws ServletException 42 { 43 super.init(config); 44 if (!WEnv.initWeb(config)) 45 throw new ServletException("WFieldUpdate.init"); 46 } 48 51 public void destroy() 52 { 53 } 55 private static final String FORM_NAME = "fieldUpdate"; 56 private static final String FIELD_FORM = "formName"; 58 private static final String FIELD_NAME = "fieldName"; 59 private static final String FIELD_VALUE = "fieldValue"; 60 61 68 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 69 { 70 doPost(request, response); 71 } 73 74 81 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 82 { 83 Log.trace(Log.l1_User, "WFieldUpdate.doPost"); 84 HttpSession sess = request.getSession(); 86 Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT); 87 WWindowStatus ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW); 88 89 if (sess == null || ctx == null) ; 91 92 String formName = request.getParameter(FIELD_FORM); 94 String fieldName = request.getParameter(FIELD_NAME); 95 String fieldValue = request.getParameter(FIELD_VALUE); 96 97 WDoc doc = WDoc.create (true); 99 body body = doc.getBody(); 100 101 createReply (body, ctx, ws, formName, fieldName, fieldValue); 103 104 form fu = new form(request.getRequestURI(), form.post); 106 fu.setName(FORM_NAME); 107 fu.addElement(new input(input.hidden, FIELD_FORM, "y")); 108 fu.addElement(new input(input.hidden, FIELD_NAME, "y")); 109 fu.addElement(new input(input.hidden, FIELD_VALUE, "y")); 110 body.addElement(fu); 111 112 114 WUtil.createResponse (request, response, this, null, doc, false); 116 } 118 129 private static void createReply (body body, Properties ctx, WWindowStatus ws, 130 String formName, String fieldName, String fieldValue) 131 { 132 StringBuffer sb = new StringBuffer (FIELD_FORM); 133 sb.append("=").append(formName).append(", ") 134 .append(FIELD_NAME).append("=").append(fieldName).append(", ") 135 .append(FIELD_VALUE).append("=").append(fieldValue); 136 Log.trace(Log.l3_Util, "WFieldUpdate.createReply", sb.toString()); 137 138 body.addElement(new p().addElement(sb.toString())); 140 141 if (formName == null || fieldName == null) 143 ; 144 else if (formName.equals("Login2") && fieldName.equals(WLogin.P_ROLE)) 146 reply_Login2_Role (body, ctx, formName, fieldValue); 147 else if (formName.equals("Login2") && fieldName.equals(WLogin.P_CLIENT)) 149 reply_Login2_Client (body, ctx, formName, fieldValue); 150 } 152 161 private static void reply_Login2_Role (body body, Properties ctx, String formName, String fieldValue) 162 { 163 String form = "top." + WEnv.TARGET_WINDOW + ".document." + formName + "."; 165 KeyNamePair[] clients = DB.loadClients(ctx, new KeyNamePair(Integer.parseInt(fieldValue) , fieldValue)); 167 168 StringBuffer script = new StringBuffer (); 170 script.append("var A=").append(form).append(WLogin.P_CLIENT).append(".options; "); 172 script.append("A.length=0; "); 174 176 for (int i = 0; i < clients.length; i++) 177 { 178 KeyNamePair p = clients[i]; 179 script.append("A[").append(i).append("]=new Option('"); 180 script.append(p.getName()); script.append("','"); 182 script.append(p.getKey()); script.append("'); "); 184 } 185 script.append("\n"); 186 187 189 if (clients.length > 0) 190 { 191 script.append("var B=").append(form).append(WLogin.P_ORG).append(".options; "); 193 script.append("B.length=0; "); 195 197 KeyNamePair[] orgs = DB.loadOrgs(ctx, clients[0]); 198 for (int i = 0; i < orgs.length; i++) 199 { 200 KeyNamePair p = orgs[i]; 201 script.append("B[").append(i).append("]=new Option('"); 202 script.append(p.getName()); script.append("','"); 204 script.append(p.getKey()); script.append("'); "); 206 } 207 script.append("\n"); 208 } 209 210 212 if (clients.length > 0) 213 { 214 script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; "); 216 script.append("C.length=0; "); 218 220 KeyNamePair[] whs = DB.loadWarehouses(ctx, clients[0]); 221 if (whs != null) 222 { 223 for (int i = 0; i < whs.length; i++) 224 { 225 KeyNamePair p = whs[i]; 226 script.append("C[").append(i).append("]=new Option('"); 227 script.append(p.getName()); script.append("','"); 229 script.append(p.getKey()); script.append("'); "); 231 } 232 } 233 } 234 235 body.addElement(new p().addElement(WLogin.P_CLIENT + "=")); 237 body.addElement(new script(script.toString())); 238 } 241 250 private static void reply_Login2_Client (body body, Properties ctx, String formName, String fieldValue) 251 { 252 String form = "top." + WEnv.TARGET_WINDOW + ".document." + formName + "."; 254 StringBuffer script = new StringBuffer (); 255 256 258 script.append("var B=").append(form).append(WLogin.P_ORG).append(".options; "); 260 script.append("B.length=0; "); 262 264 KeyNamePair client = new KeyNamePair(Integer.parseInt(fieldValue), fieldValue); 265 KeyNamePair[] orgs = DB.loadOrgs(ctx, client); 266 for (int i = 0; i < orgs.length; i++) 267 { 268 KeyNamePair p = orgs[i]; 269 script.append("B[").append(i).append("]=new Option('"); 270 script.append(p.getName()); script.append("','"); 272 script.append(p.getKey()); script.append("'); "); 274 } 275 script.append("\n"); 276 277 279 script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; "); 281 script.append("C.length=0; "); 283 285 KeyNamePair[] whs = DB.loadWarehouses(ctx, client); 286 if (whs != null) 287 { 288 for (int i = 0; i < whs.length; i++) 289 { 290 KeyNamePair p = whs[i]; 291 script.append("C[").append(i).append("]=new Option('"); 292 script.append(p.getName()); script.append("','"); 294 script.append(p.getKey()); script.append("'); "); 296 } 297 } 298 299 body.addElement(new p().addElement(WLogin.P_WAREHOUSE + "=")); 301 body.addElement(new script(script.toString())); 302 } 305 } | Popular Tags |