1 19 package org.openbravo.wad.controls; 20 21 import java.util.*; 22 import org.openbravo.data.Sqlc; 23 import org.openbravo.utils.FormatUtilities; 24 import org.openbravo.xmlEngine.XmlDocument; 25 26 public class WADSearch extends WADControl { 27 public WADControl button; 28 public String command = ""; 29 public String hiddenFields = ""; 30 public String imageName = ""; 31 public String searchName = ""; 32 public boolean isFieldEditable = true; 33 34 public WADSearch() { 35 } 36 37 public WADSearch(Properties prop) { 38 setInfo(prop); 39 initialize(); 40 } 41 42 public void initialize() { 43 addImport("ValidationTextBox", "../../../../../web/js/default/ValidationTextBox.js"); 44 addImport("searchs", "../../../../../web/js/searchs.js"); 45 generateMessages(); 46 generateJSCode(); 47 this.button = new WADFieldButton(this.imageName, getData("ColumnName"), getData("ColumnNameInp"), this.searchName, this.command); 48 if (getData("AD_Reference_Value_ID").equals("21")) this.isFieldEditable = false; 49 } 50 51 private void generateJSCode() { 52 StringBuffer validation = new StringBuffer (); 53 if (getData("IsMandatory").equals("Y")) { 54 validation.append(" if (inputValue(frm.inp").append(getData("ColumnNameInp")).append(")==null || inputValue(frm.inp").append(getData("ColumnNameInp")).append(")==\"\") {\n"); 55 if (getData("IsDisplayed").equals("Y")) validation.append(" frm.inp").append(getData("ColumnNameInp")).append("_R.focus();\n"); 56 validation.append(" mensaje(1);\n"); 57 validation.append(" return false;\n"); 58 validation.append(" }\n"); 59 } 60 setValidation(validation.toString()); 61 setCalloutJS(); 62 { 63 StringBuffer text = new StringBuffer (); 64 text.append("function debugSearch(key, text, keyField) {\n"); 65 text.append(" return true;\n"); 66 text.append("}"); 67 addJSCode("debugSearch", text.toString()); 68 } 69 if (!getData("IsReadOnly").equals("Y") && !getData("IsReadOnlyTab").equals("Y")) { 70 StringBuffer columnsScript = new StringBuffer (); 71 StringBuffer commandScript = new StringBuffer (); 72 StringBuffer hiddenScript = new StringBuffer (); 73 StringBuffer text = new StringBuffer (); 74 if (this.imageName==null || this.imageName.equals("")) this.imageName = FormatUtilities.replace(getData("searchName")); 75 if (this.searchName==null || this.searchName.equals("")) this.searchName = getData("Name"); 76 String servletName = "/info/" + this.imageName + ".html"; 77 try { 78 if (!getData("AD_Reference_Value_ID").equals("")) { 79 WADSearchData[] data = WADSearchData.select(getConnection(), getData("AD_Language"), getData("AD_Reference_Value_ID")); 80 if (data!=null && data.length>0) { 81 servletName = data[0].mappingname; 82 this.searchName = data[0].referenceNameTrl; 83 if (!servletName.startsWith("/")) servletName = "/" + servletName; 85 for (int i=0;i<data.length;i++) { 86 if (data[i].columntype.equals("I")) { 87 columnsScript.append(", 'inp").append(data[i].name).append("'"); 88 columnsScript.append(", inputValue(document.frmMain.inp").append(Sqlc.TransformaNombreColumna(data[i].columnname)).append(")"); 89 } else { 90 hiddenScript.append("<input type=\"hidden\" name=\"inp").append(Sqlc.TransformaNombreColumna(data[i].name)); 91 hiddenScript.append(data[i].columnSuffix).append("\" value=\"\" "); 92 hiddenScript.append("id=\"").append(data[i].columnname).append(data[i].columnSuffix).append("\"/>\n"); 93 } 94 } 95 } 96 } 97 } catch (Exception ex) { 98 ex.printStackTrace(); 99 } 100 commandScript.append("openSearch(null, null, '..").append(servletName).append("', "); 101 commandScript.append("null, false, 'frmMain', 'inp").append(getData("ColumnNameInp")).append("', "); 102 commandScript.append("'inp").append(getData("ColumnNameInp")).append("_R', "); 103 commandScript.append("inputValue(document.frmMain.inp").append(getData("ColumnNameInp")).append("_R), "); 104 commandScript.append("'inpIDValue', inputValue(document.frmMain.inp").append(getData("ColumnNameInp")).append("), "); 105 commandScript.append("'WindowID', inputValue(document.frmMain.inpwindowId)"); 106 commandScript.append(columnsScript); 107 text.append(commandScript).append(", 'Command', 'KEY'"); 108 commandScript.append(");"); 109 text.append(");"); 110 setOnLoad("arrTeclas[arrTeclas.length] = new Teclas(\"ENTER\", \"" + text.toString() + "\", \"inp" + getData("ColumnNameInp") + "_R\", \"null\");"); 111 this.command = commandScript.toString(); 112 this.hiddenFields = hiddenScript.toString(); 113 } 114 } 115 116 public String getType() { 117 return "TextBox_btn"; 118 } 119 120 public String editMode() { 121 String textButton = ""; 122 String buttonClass = ""; 123 if (getData("IsReadOnly").equals("N") && getData("IsReadOnlyTab").equals("N") && getData("IsUpdateable").equals("Y")) { 124 this.button.setReportEngine(getReportEngine()); 125 textButton = this.button.toString(); 126 buttonClass = this.button.getType(); 127 } 128 XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADSearch").createXmlDocument(); 129 130 xmlDocument.setParameter("columnName", getData("ColumnName")); 131 xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp")); 132 xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize")); 133 xmlDocument.setParameter("maxlength", getData("FieldLength")); 134 xmlDocument.setParameter("hiddens", this.hiddenFields); 135 xmlDocument.setParameter("hasButton", (textButton.equals("")?"TextButton_ContentCell":"")); 136 xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell"); 137 xmlDocument.setParameter("invalid", this.invalid); 138 xmlDocument.setParameter("missing", this.missing); 139 xmlDocument.setParameter("range", this.range); 140 xmlDocument.setParameter("button", textButton); 141 String className = ""; 142 boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")); 143 if (isDisabled || !this.isFieldEditable) className += " readonly"; 144 else if (getData("IsMandatory").equals("Y")) className += " required"; 145 xmlDocument.setParameter("className", className); 146 147 if (isDisabled || !this.isFieldEditable) xmlDocument.setParameter("disabled", "Y"); 148 else xmlDocument.setParameter("disabled", "N"); 149 if (getData("IsMandatory").equals("Y")) xmlDocument.setParameter("required", "true"); 150 else xmlDocument.setParameter("required", "false"); 151 xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":"")); 152 153 xmlDocument.setParameter("callout", getOnChangeCode()); 154 return replaceHTML(xmlDocument.print()); 155 } 156 157 public String newMode() { 158 String textButton = ""; 159 String buttonClass = ""; 160 if (getData("IsReadOnly").equals("N") && getData("IsReadOnlyTab").equals("N")) { 161 this.button.setReportEngine(getReportEngine()); 162 textButton = this.button.toString(); 163 buttonClass = this.button.getType(); 164 } 165 XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADSearch").createXmlDocument(); 166 167 xmlDocument.setParameter("columnName", getData("ColumnName")); 168 xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp")); 169 xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize")); 170 xmlDocument.setParameter("maxlength", getData("FieldLength")); 171 xmlDocument.setParameter("hiddens", this.hiddenFields); 172 xmlDocument.setParameter("hasButton", (textButton.equals("")?"TextButton_ContentCell":"")); 173 xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell"); 174 xmlDocument.setParameter("invalid", this.invalid); 175 xmlDocument.setParameter("missing", this.missing); 176 xmlDocument.setParameter("range", this.range); 177 xmlDocument.setParameter("button", textButton); 178 String className = ""; 179 boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")); 180 if (isDisabled || !this.isFieldEditable) className += " readonly"; 181 else if (getData("IsMandatory").equals("Y")) className += " required"; 182 xmlDocument.setParameter("className", className); 183 184 if (isDisabled || !this.isFieldEditable) xmlDocument.setParameter("disabled", "Y"); 185 else xmlDocument.setParameter("disabled", "N"); 186 if (getData("IsMandatory").equals("Y")) xmlDocument.setParameter("required", "true"); 187 else xmlDocument.setParameter("required", "false"); 188 xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":"")); 189 190 xmlDocument.setParameter("callout", getOnChangeCode()); 191 192 return replaceHTML(xmlDocument.print()); 193 } 194 195 public String toXml() { 196 String [] discard = {"xx_PARAM", "xx_PARAM_R"}; 197 if (getData("IsParameter").equals("Y")) { 198 discard[0] = new String ("xx"); 199 discard[1] = new String ("xx_R"); 200 } 201 XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADSearchXML", discard).createXmlDocument(); 202 203 xmlDocument.setParameter("columnName", getData("ColumnName")); 204 return replaceHTML(xmlDocument.print()); 205 } 206 207 public String toJava() { 208 return ""; 209 } 210 } 211 | Popular Tags |