Search in sources :

Example 1 with MobileSessionCtx

use of org.compiere.mobile.MobileSessionCtx in project adempiere by adempiere.

the class WLookup method doGet.

//  init
/**
	 * Process the HTTP Get request - initial Start
	 * Needs to have parameters FormName and ColumnName
	 *
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    MobileEnv.dump(request);
    MobileEnv.dump(request.getSession());
    //Modified by Rob Klein 4/29/07
    //
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null) {
        MobileUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    //  Get Mandatory Parameters
    String columnName = MobileUtil.getParameter(request, "ColumnName");
    //Lookup called from a process
    //Modified by Rob Klein 4/29/07
    int AD_Process_ID = MobileUtil.getParameterAsInt(request, "AD_Process_ID");
    //Lookup modified to include paging
    //Modified by Rob Klein 07/07/07
    int page = MobileUtil.getParameterAsInt(request, "page");
    int refValueId = 0;
    boolean startUpdate = false;
    String targetBase = "'" + columnName;
    String header = null;
    if (AD_Process_ID > 0) {
        if (AD_Process_ID < 1 || columnName == null || columnName.equals("")) {
            MobileUtil.createErrorPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
            return;
        }
        MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
        MProcessPara para = null;
        MProcessPara[] parameters = process.getParameters();
        for (int i = 0; i < parameters.length; i++) {
            if (para.getColumnName().equals(columnName))
                para = parameters[i];
        }
        if (para != null)
            refValueId = para.getAD_Reference_Value_ID();
        header = para.getColumnName();
    } else //Lookup called from a window
    {
        //	Modified by Rob Klein 7/01/07
        if (ws == null) {
            MobileUtil.createTimeoutPage(request, response, this, null);
            return;
        }
        GridField mField = ws.curTab.getField(columnName);
        log.config("ColumnName=" + columnName + ", MField=" + mField);
        if (mField == null || columnName == null || columnName.equals("")) {
            MobileUtil.createErrorPage(request, response, this, Msg.getMsg(ws.ctx, "ParameterMissing"));
            return;
        }
        header = mField.getHeader();
        boolean hasDependents = ws.curTab.hasDependants(columnName);
        boolean hasCallout = mField.getCallout().length() > 0;
        startUpdate = hasDependents || hasCallout;
        refValueId = mField.getAD_Reference_Value_ID();
    }
    if (m_searchFields == null || m_searchFields.length == 0) {
        getSearchFields(columnName, refValueId);
    }
    String search = MobileUtil.getParameter(request, "search");
    if (Util.isEmpty(MobileUtil.getParameter(request, "search"))) {
        //  Create Document
        MobileDoc doc = MobileDoc.createPopup(header);
        form panel = new form();
        panel.setMethod("post");
        panel.setClass("dialog");
        panel.setID("WLookup1");
        panel.setAction("WLookup?ColumnName=" + columnName + "&AD_Process_ID=" + AD_Process_ID);
        panel.addAttribute("selected", "true");
        fieldset set = new fieldset();
        h1 h = new h1(header);
        set.addElement(h);
        a a = new a("#", "Cancel");
        a.addAttribute("type", "cancel");
        a.setClass("button leftButton");
        set.addElement(a);
        a = new a("WLookup?ColumnName=" + columnName + "&AD_Process_ID=" + AD_Process_ID, "Search");
        a.addAttribute("type", "submit");
        a.setClass("button");
        set.addElement(a);
        panel.addElement(set);
        for (int i = 0; i < m_searchFields.length; i++) {
            /*
				label l = new label();
				l.addElement(m_searchLabels[i]);
				set.addElement(l)*/
            input f = new input(input.TYPE_TEXT, m_searchFields[i], "");
            f.setID(m_searchFields[i]);
            f.addAttribute("placeholder", m_searchLabels[i]);
            set.addElement(f).addElement(new br());
        }
        input hidden = new input(input.TYPE_HIDDEN, "search", "true");
        set.addElement(hidden);
        doc.getBody().addElement(panel);
        MobileUtil.createResponseFragment(request, response, this, null, doc);
    } else {
        //  Create Document
        MobileDoc doc = MobileDoc.createPopup(header);
        StringBuffer where = new StringBuffer();
        for (String column : m_searchFields) {
            String value = request.getParameter(column);
            if (!Util.isEmpty(value)) {
                value = "%" + value + "%";
                where.append(" AND UPPER(").append(column).append(") LIKE UPPER(").append(DB.TO_STRING(value)).append(") ");
            }
        }
        div panel = new div();
        panel.setClass("dialog");
        panel.addAttribute("selected", "true");
        panel.setID("WLookup2");
        fieldset set = new fieldset();
        panel.addElement(set);
        set.addElement(fillTable(wsc, columnName, refValueId, request.getRequestURI(), targetBase, startUpdate, page, where.toString()));
        //  Reset
        String text = "Reset";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Reset");		
        input resetbtn = new input(input.TYPE_RESET, text, "  " + text);
        resetbtn.setID(text);
        resetbtn.setClass("resetbtn");
        String script = targetBase + "F.value='';" + targetBase + "D.value='';self.close();";
        if (startUpdate)
            script += "startUpdate(" + targetBase + "F);";
        resetbtn.setOnClick(script);
        doc.getBody().addElement(panel);
        doc.getBody().addElement(resetbtn);
        MobileUtil.createResponseFragment(request, response, this, null, doc);
    }
}
Also used : MobileSessionCtx(org.compiere.mobile.MobileSessionCtx) MProcessPara(org.compiere.model.MProcessPara) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) MProcess(org.compiere.model.MProcess) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) MProcessPara(org.compiere.model.MProcessPara) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.br(org.apache.ecs.xhtml.br) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form)

Aggregations

org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)1 org.apache.ecs.xhtml.br (org.apache.ecs.xhtml.br)1 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)1 org.apache.ecs.xhtml.fieldset (org.apache.ecs.xhtml.fieldset)1 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)1 org.apache.ecs.xhtml.h1 (org.apache.ecs.xhtml.h1)1 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)1 MobileSessionCtx (org.compiere.mobile.MobileSessionCtx)1 GridField (org.compiere.model.GridField)1 MProcess (org.compiere.model.MProcess)1 MProcessPara (org.compiere.model.MProcessPara)1