19 package org.turro.jpa.search;
21 import java.io.IOException;
22 import java.io.Serializable;
23 import java.util.HashMap;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.action.content.IContentIterator;
28 import org.turro.string.Strings;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.context.IConstructor;
31 import org.turro.html.HTMLGenerator;
32 import org.turro.i18n.I_;
33 import org.turro.marker.ElephantMarker;
34 import org.turro.skills.tags.SkillCloud;
35 import org.turro.tags.TagCloud;
43 private final String context;
44 private String tagCloudString, tagsString, tagRoot;
53 }
catch (IOException ex) {
63 if(!search.isEmpty()) {
69 if(search !=
null) search.loadValues(constructor);
75 this.context = context;
83 this.iterator = iterator;
89 if(
"input".equals(dsk.getTag())) {
98 if(
"tag-cloud".equals(dsk.getTag())) {
106 this.tagCloudString = tagCloudString;
110 return tagCloudString;
114 this.tagsString = tagsString;
122 this.tagRoot = tagRoot;
128 em.
put(
"iterator", iterator);
129 em.
put(
"keys",
this);
130 if(!Strings.isBlank(tagRoot)) {
133 return em.
parse(Strings.isBlank(root,
"iterator"), Strings.isBlank(
template,
"search"));
135 return render(constructor,
null);
144 hg.
startTable(
"cellpadding='1' cellspacing='1' style='width:100%'")
147 for(String key : keySet()) {
149 renderKey(constructor, hg, dsk, renderer);
157 String submited = constructor.
getParameter(
"search-form");
158 if(
"clear".equals(clear)) {
162 }
else if(submited !=
null) {
163 for(String key : keySet()) {
164 if(!key.startsWith(
"#")) {
165 DaoSearchKey dsk =
get(key);
166 dsk.readParam(constructor);
172 private void renderKey(IConstructor constructor, HTMLGenerator hg, DaoSearchKey dsk, DaoItemRender renderer) {
173 if(renderer !=
null && renderer.renderKey(constructor, hg, dsk)) {
176 if(
"new-row".equals(dsk.getTag())) {
177 StringBuilder sb =
new StringBuilder();
178 for(String s : dsk.getAttributes().keySet()) {
179 String v = dsk.getAttributes().get(s);
180 sb.append(
" ").append(s).append(
"=\"").append(v).append(
"\"");
182 hg.startTableRow(
"").startTableCol(sb.toString());
183 }
else if(
"new-col".equals(dsk.getTag())) {
184 StringBuilder sb =
new StringBuilder();
185 for(String s : dsk.getAttributes().keySet()) {
186 String v = dsk.getAttributes().get(s);
187 sb.append(
" ").append(s).append(
"=\"").append(v).append(
"\"");
189 hg.startTableCol(sb.toString());
190 }
else if(
"search-button".equals(dsk.getTag())) {
191 hg.startTag(
"button",
"type='submit' name='search-form'")
192 .write(
"<i class=\"fa fa-search\"></i>")
194 }
else if(
"clear-button".equals(dsk.getTag())) {
195 hg.startTag(
"button",
"type='submit' name='clear-form' value='clear'")
196 .write(
"<i class=\"fa fa-close\"></i>")
198 }
else if(
"tag-cloud".equals(dsk.getTag())) {
199 if(!Strings.isBlank(tagCloudString)) {
200 String uniqueId = constructor.getUniqueId();
201 hg.startTag(
"button",
"type='button' onclick='$(\"#" + uniqueId +
"\").slideToggle()'")
202 .write(
"<i class=\"fa fa-tags\"></i>")
204 if(!Strings.isEmpty(tagsString)) {
205 hg.startTableRow(
"").startTableCol(
"colspan='10'")
206 .startTag(
"div",
"class='selected-tag'")
210 hg.startTableRow(
"").startTableCol(
"colspan='10'");
211 hg.startTag(
"div",
"id='" + uniqueId +
"' style='display:none;'")
212 .write(tagCloudString)
215 }
else if(
"input".equals(dsk.getTag())) {
216 StringBuilder sb =
new StringBuilder();
217 sb.append(
" name=\"").append(dsk.getName()).append(
"\"");
218 sb.append(
" type=\"").append(dsk.getType()).append(
"\"");
219 sb.append(
" value=\"").append(dsk.getValue()).append(
"\"");
220 for(String s : dsk.getAttributes().keySet()) {
221 String v = dsk.getAttributes().get(s);
222 if(
"placeholder".equals(s) ||
"label".equals(s)) {
225 if(
"checked".equals(s)) {
226 sb.append(
" ").append(s);
228 sb.append(
" ").append(s).append(
"=\"").append(v).append(
"\"");
231 hg.doTag(
"input", sb.toString());
237 private Map<String, Object> attributes;
240 checkAttributtes(constructor);
241 return attributes.containsKey(attribute);
245 checkAttributtes(constructor);
246 return attributes.get(attribute);
250 checkAttributtes(constructor);
251 attributes.put(attribute, value);
254 private void checkAttributtes(
IConstructor constructor) {
255 if(attributes ==
null) {
256 attributes = (Map<String, Object>) constructor.
getSessionAttribute(context +
"-attributes");
258 if(attributes ==
null) {
259 attributes =
new HashMap<>();
static String getRootWebPath()
static String logMsg(String msg)
static String getContextVariable(IConstructor constructor)
HTMLGenerator endAllTags()
HTMLGenerator startTag(String tag)
HTMLGenerator startTableCol(String attributes)
HTMLGenerator startTable(String attributes)
void setAttribute(IConstructor constructor, String attribute, Object value)
String render(IConstructor constructor)
Object getAttribute(IConstructor constructor, String attribute)
void setTagCloudString(String tagCloudString)
void setIterator(IContentIterator iterator)
void setTagRoot(String tagRoot)
String render(IConstructor constructor, DaoItemRender renderer)
String getTagCloudString()
IContentIterator getIterator()
void setTagsString(String tagsString)
static void renderInstance(IConstructor constructor)
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
boolean hasAttribute(IConstructor constructor, String attribute)
static boolean existsTemplate(IConstructor constructor, boolean mail, String root, String name)
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)
String getParameter(String param)
void setSessionAttribute(String key, Object value)
Object getSessionAttribute(String key)