1 19 package org.openbravo.wad.controls; 20 21 import java.util.*; 22 import org.openbravo.xmlEngine.XmlDocument; 23 24 public class WADList extends WADControl { 25 26 public WADList() { 27 } 28 29 public WADList(Properties prop) { 30 setInfo(prop); 31 initialize(); 32 } 33 34 public void initialize() { 35 addImport("String", "../../../../../web/js/String.js"); 36 addImport("TypeAheadCombo", "../../../../../web/js/TypeAheadCombo.js"); 37 generateJSCode(); 38 } 39 40 private void generateJSCode() { 41 if (getData("IsMandatory").equals("Y")) { 42 StringBuffer text = new StringBuffer (); 43 text.append(" if (inputValue(frm.inp").append(getData("ColumnNameInp")); 44 text.append(")==null || inputValue(frm.inp"); 45 text.append(getData("ColumnNameInp")); 46 text.append(")==\"\") {\n"); 47 text.append(" setFocus(frm.inp").append(getData("ColumnNameInp")).append(");\n"); 48 text.append(" mensaje(1);\n"); 49 text.append(" return false;\n"); 50 text.append(" }"); 51 setValidation(replaceHTML(text.toString())); 52 } 53 setOnLoad("new TypeAheadCombo(\"report" + getData("ColumnName") + "_S\");\nif (inputValue(key)==\"\") updateOnChange(frm.inp" + getData("ColumnNameInp") + ");"); 54 setCalloutJS(); 55 } 56 57 public String getType() { 58 return "Combo"; 59 } 60 61 public String editMode() { 62 String [] discard = {""}; 63 if (getData("IsMandatory").equals("Y")) discard[0] = "fieldBlankSection"; 64 XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADList", discard).createXmlDocument(); 65 66 xmlDocument.setParameter("columnName", getData("ColumnName")); 67 xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp")); 68 String length = getData("DisplayLength"); 69 if (!length.endsWith("%")) length += "px"; 70 xmlDocument.setParameter("size", getData("CssSize")); 71 72 String auxClassName = ""; 73 if (getData("IsMandatory").equals("Y")) auxClassName += "Key"; 74 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) auxClassName += "ReadOnly"; 75 else if (getData("IsUpdateable").equals("N")) auxClassName += "NoUpdatable"; 76 xmlDocument.setParameter("myClass", auxClassName); 77 78 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) xmlDocument.setParameter("disabled", "Y"); 79 else xmlDocument.setParameter("disabled", "N"); 80 83 StringBuffer text = new StringBuffer (); 84 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) text.append("selectCombo(this, 'xx');"); 85 text.append(getOnChangeCode()); 86 xmlDocument.setParameter("callout", text.toString()); 87 88 return replaceHTML(xmlDocument.print()); 89 } 90 91 public String newMode() { 92 String [] discard = {""}; 93 if (getData("IsMandatory").equals("Y")) discard[0] = "fieldBlankSection"; 94 XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADList", discard).createXmlDocument(); 95 96 xmlDocument.setParameter("columnName", getData("ColumnName")); 97 xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp")); 98 String length = getData("DisplayLength"); 99 if (!length.endsWith("%")) length += "px"; 100 xmlDocument.setParameter("size", getData("CssSize")); 101 102 String auxClassName = ""; 103 if (getData("IsMandatory").equals("Y")) auxClassName += "Key"; 104 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) auxClassName += "ReadOnly"; 105 xmlDocument.setParameter("myClass", auxClassName); 106 107 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) xmlDocument.setParameter("disabled", "Y"); 108 else xmlDocument.setParameter("disabled", "N"); 109 112 StringBuffer text = new StringBuffer (); 113 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) text.append("selectCombo(this, 'xx');"); 114 text.append(getOnChangeCode()); 115 xmlDocument.setParameter("callout", text.toString()); 116 117 return replaceHTML(xmlDocument.print()); 118 } 119 120 public String toXml() { 121 StringBuffer text = new StringBuffer (); 122 if (getData("IsParameter").equals("Y")) { 123 text.append("<PARAMETER id=\"").append(getData("ColumnName")); 124 text.append("\" name=\"").append(getData("ColumnName")).append("\" attribute=\"value\"/>"); 125 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) { 126 text.append("\n<PARAMETER id=\"report").append(getData("ColumnName")); 127 text.append("_S\" name=\"report").append(getData("ColumnName")).append("_S\" attribute=\"onchange\" replace=\"xx\"/>"); 128 } 129 } else { 130 text.append("<FIELD id=\"").append(getData("ColumnName")); 131 text.append("\" attribute=\"value\">"); 132 text.append(getData("ColumnName")).append("</FIELD>"); 133 if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) { 134 text.append("\n<FIELD id=\"report").append(getData("ColumnName")); 135 text.append("_S\" attribute=\"onchange\" replace=\"xx\">"); 136 text.append(getData("ColumnName")).append("</FIELD>"); 137 } 138 } 139 if (getData("IsDisplayed").equals("Y")) { 140 text.append("\n<SUBREPORT id=\"report").append(getData("ColumnName")); 141 text.append("\" name=\"report").append(getData("ColumnName")); 142 text.append("\" report=\"org/openbravo/erpCommon/reference/List\">\n"); 143 text.append(" <ARGUMENT name=\"parameterListSelected\" withId=\"").append(getData("ColumnName")).append("\"/>\n"); 144 text.append("</SUBREPORT>"); 145 } 146 return text.toString(); 147 } 148 149 public String toJava() { 150 StringBuffer text = new StringBuffer (); 151 if (getData("IsDisplayed").equals("Y")) { 152 text.append("comboTableData = new ComboTableData(vars, this, \"").append(getData("AD_Reference_ID")).append("\", "); 153 text.append("\"").append(getData("ColumnName")).append("\", \""); 154 text.append(getData("AD_Reference_Value_ID")).append("\", "); 155 text.append("\"").append(getData("AD_Val_Rule_ID")).append("\", "); 156 text.append("Utility.getContext(this, vars, \"#User_Org\", windowId), "); 157 text.append("Utility.getContext(this, vars, \"#User_Client\", windowId), 0);\n"); 158 text.append("Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField(\""); 159 text.append(getData("ColumnNameInp")).append("\"):dataField.getField(\""); 160 text.append(getData("ColumnNameInp")).append("\")));\n"); 161 text.append("xmlDocument.setData(\"report").append(getData("ColumnName")).append("\",\"liststructure\", "); 162 text.append("comboTableData.select(!strCommand.equals(\"NEW\")));\n"); 163 text.append("comboTableData = null;"); 164 } 165 return text.toString(); 166 } 167 } 168 | Popular Tags |