001
014
015 package com.liferay.portal.kernel.dao.search;
016
017 import com.liferay.portal.kernel.util.StringBundler;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.kernel.util.Validator;
020
021 import javax.portlet.PortletResponse;
022 import javax.portlet.RenderResponse;
023
024
027 public class RowChecker {
028
029 public static final String ALIGN = "left";
030
031 public static final String ALL_ROW_IDS = "allRowIds";
032
033 public static final int COLSPAN = 1;
034
035 public static final String CSS_CLASS = StringPool.BLANK;
036
037 public static final String FORM_NAME = "fm";
038
039 public static final String ROW_IDS = "rowIds";
040
041 public static final String VALIGN = "middle";
042
043 public RowChecker(PortletResponse portletResponse) {
044 _portletResponse = portletResponse;
045
046 _allRowIds = _portletResponse.getNamespace() + ALL_ROW_IDS;
047 _formName = _portletResponse.getNamespace() + FORM_NAME;
048 _rowIds = _portletResponse.getNamespace() + ROW_IDS;
049 }
050
051
054 public RowChecker(
055 RenderResponse renderResponse, String align, String valign,
056 String formName, String allRowIds, String rowIds) {
057
058 this(
059 renderResponse, align, valign, COLSPAN, formName, allRowIds,
060 rowIds);
061 }
062
063
066 public RowChecker(
067 RenderResponse renderResponse, String align, String valign, int colspan,
068 String formName, String allRowIds, String rowIds) {
069
070 this(renderResponse);
071
072 setAlign(align);
073 setValign(valign);
074 setColspan(colspan);
075 setFormName(formName);
076 setAllRowIds(allRowIds);
077 setRowIds(rowIds);
078 }
079
080 public String getAlign() {
081 return _align;
082 }
083
084 public String getAllRowsCheckBox() {
085 if (Validator.isNull(_allRowIds)) {
086 return StringPool.BLANK;
087 }
088 else {
089 StringBuilder sb = new StringBuilder();
090
091 sb.append("<input name=\"");
092 sb.append(_allRowIds);
093 sb.append("\" type=\"checkbox\" ");
094 sb.append("onClick=\"Liferay.Util.checkAll(");
095 sb.append("AUI().one(this).ancestor('");
096 sb.append("table.taglib-search-iterator'), '");
097 sb.append(_rowIds);
098 sb.append("', this");
099 sb.append(");\">");
100
101 return sb.toString();
102 }
103 }
104
105 public String getAllRowIds() {
106 return _allRowIds;
107 }
108
109 public String getAllRowsId() {
110 return getAllRowIds();
111 }
112
113 public int getColspan() {
114 return _colspan;
115 }
116
117 public String getCssClass() {
118 return _cssClass;
119 }
120
121 public String getFormName() {
122 return _formName;
123 }
124
125 public String getRowCheckBox(boolean checked, String primaryKey) {
126 return getRowCheckBox(
127 checked, _rowIds, primaryKey, "'" + _rowIds + "'", _allRowIds,
128 StringPool.BLANK);
129 }
130
131 public String getRowId() {
132 return getRowIds();
133 }
134
135 public String getRowIds() {
136 return _rowIds;
137 }
138
139 public String getValign() {
140 return _valign;
141 }
142
143 public boolean isChecked(Object obj) {
144 return false;
145 }
146
147 public void setAlign(String align) {
148 _align = align;
149 }
150
151 public void setAllRowIds(String allRowIds) {
152 _allRowIds = getNamespacedValue(allRowIds);
153 }
154
155 public void setColspan(int colspan) {
156 _colspan = colspan;
157 }
158
159 public void setCssClass(String cssClass) {
160 _cssClass = cssClass;
161 }
162
163 public void setFormName(String formName) {
164 _formName = getNamespacedValue(formName);
165 }
166
167 public void setRowIds(String rowIds) {
168 _rowIds = getNamespacedValue(rowIds);
169 }
170
171 public void setValign(String valign) {
172 _valign = valign;
173 }
174
175 protected String getNamespacedValue(String value) {
176 if (Validator.isNull(value)) {
177 return StringPool.BLANK;
178 }
179 else {
180 if (!value.startsWith(_portletResponse.getNamespace())) {
181 value = _portletResponse.getNamespace() + value;
182 }
183
184 return value;
185 }
186 }
187
188 protected String getRowCheckBox(
189 boolean checked, String name, String value, String checkBoxRowIds,
190 String checkBoxAllRowIds, String checkBoxPostOnClick) {
191
192 StringBundler sb = new StringBundler();
193
194 sb.append("<input ");
195
196 if (checked) {
197 sb.append("checked ");
198 }
199
200 sb.append("name=\"");
201 sb.append(name);
202 sb.append("\" type=\"checkbox\" value=\"");
203 sb.append(value);
204 sb.append("\" ");
205
206 if (Validator.isNotNull(_allRowIds)) {
207 sb.append("onClick=\"Liferay.Util.checkAllBox(");
208 sb.append("AUI().one(this).ancestor('");
209 sb.append("table.taglib-search-iterator'), ");
210 sb.append(checkBoxRowIds);
211 sb.append(", ");
212 sb.append(checkBoxAllRowIds);
213 sb.append(");");
214
215 if (Validator.isNotNull(checkBoxPostOnClick)) {
216 sb.append(checkBoxPostOnClick);
217 }
218
219 sb.append("\"");
220 }
221
222 sb.append(">");
223
224 return sb.toString();
225 }
226
227 private String _align = ALIGN;
228 private String _allRowIds;
229 private int _colspan = COLSPAN;
230 private String _cssClass = CSS_CLASS;
231 private String _formName;
232 private PortletResponse _portletResponse;
233 private String _rowIds;
234 private String _valign = VALIGN;
235
236 }