1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web.renderers;
17
18 import java.io.IOException;
19
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.JspWriter;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.Tag;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.struts.taglib.html.HiddenTag;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.document.web.HideShowBlock;
29 import org.kuali.rice.core.api.config.property.ConfigurationService;
30 import org.kuali.rice.kns.web.taglib.html.KNSImageTag;
31
32
33
34
35 public class HideShowBlockRenderer implements Renderer {
36 private HideShowBlock hideShowBlock;
37 private HiddenTag tabStateTag = new HiddenTag();
38 private KNSImageTag showHideButton = new KNSImageTag();
39
40 protected String riceImageURLProperty = "kr.externalizable.images.url";
41
42
43
44
45
46 public void clear() {
47 hideShowBlock = null;
48 cleanTabStateTag();
49 cleanShowHideButton();
50 }
51
52
53
54
55 protected void cleanTabStateTag() {
56 tabStateTag.setPageContext(null);
57 tabStateTag.setParent(null);
58 tabStateTag.setProperty(null);
59 tabStateTag.setValue(null);
60 }
61
62
63
64
65 protected void cleanShowHideButton() {
66 showHideButton.setPageContext(null);
67 showHideButton.setParent(null);
68 showHideButton.setSrc(null);
69 showHideButton.setAlt(null);
70 showHideButton.setTitle(null);
71 showHideButton.setProperty(null);
72 showHideButton.setStyleClass(null);
73 showHideButton.setStyleId(null);
74 showHideButton.setOnclick(null);
75 }
76
77
78
79
80
81 public void render(PageContext pageContext, Tag parentTag) throws JspException {
82 JspWriter out = pageContext.getOut();
83
84 try {
85 out.write(buildLabelButtonTableOpening());
86 renderTabStateTag(pageContext, parentTag);
87 if (!StringUtils.isBlank(hideShowBlock.getLabel())) {
88 out.write(hideShowBlock.getLabel());
89 }
90 renderShowHideButton(pageContext, parentTag);
91 out.write(buildLabelButtonTableClosing());
92 out.write(buildInnerTableOpening());
93 hideShowBlock.renderChildRows(pageContext, parentTag);
94 out.write(buildInnerTableClosing());
95 } catch (IOException ioe) {
96 throw new JspException("Difficulty rendering Hide/Show block", ioe);
97 }
98 }
99
100
101
102
103 protected String buildLabelButtonTableOpening() {
104 return "<table class=\"datatable\" style=\"padding: 0px\"><tr><td class=\"tab-subhead\">";
105 }
106
107
108
109
110
111
112
113 protected void renderTabStateTag(PageContext pageContext, Tag parentTag) throws JspException {
114 tabStateTag.setPageContext(pageContext);
115 tabStateTag.setParent(parentTag);
116 tabStateTag.setProperty("tabStates("+hideShowBlock.getTabKey()+")");
117 tabStateTag.setValue(hideShowBlock.getTabState());
118
119 tabStateTag.doStartTag();
120 tabStateTag.doEndTag();
121 }
122
123
124
125
126 protected String buildLabelButtonTableClosing() {
127 return "</td></tr></table>";
128 }
129
130
131
132
133
134
135
136 protected void renderShowHideButton(PageContext pageContext, Tag parentTag) throws JspException {
137 showHideButton.setPageContext(pageContext);
138 showHideButton.setParent(parentTag);
139 showHideButton.setProperty("methodToCall.toggleTab.tab"+hideShowBlock.getTabKey());
140 showHideButton.setStyleClass("tinybutton");
141 showHideButton.setStyleId("tab-"+hideShowBlock.getTabKey()+"-imageToggle");
142 showHideButton.setOnclick("javascript: return toggleTab(document, '"+hideShowBlock.getTabKey()+"'); ");
143
144 String riceImageDir = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(riceImageURLProperty);
145 if (hideShowBlock.isShowing()) {
146 showHideButton.setSrc(riceImageDir+"tinybutton-hide.gif");
147 showHideButton.setAlt("Hide "+hideShowBlock.getFullLabel());
148 showHideButton.setTitle("Hide "+hideShowBlock.getFullLabel());
149 } else {
150 showHideButton.setSrc(riceImageDir+"tinybutton-show.gif");
151 showHideButton.setAlt("Show "+hideShowBlock.getFullLabel());
152 showHideButton.setTitle("Show "+hideShowBlock.getFullLabel());
153 }
154
155 showHideButton.doStartTag();
156 showHideButton.doEndTag();
157 }
158
159
160
161
162
163 protected String buildInnerTableOpening() {
164 StringBuilder opening = new StringBuilder();
165 opening.append("<div id=\"tab-"+hideShowBlock.getTabKey()+"-div\" style=\"display: ");
166 opening.append(hideShowBlock.isShowing() ? "block" : "none");
167 opening.append("\">");
168
169 opening.append("<table class=\"datatable\" style=\"width: 100%;\">");
170
171 return opening.toString();
172 }
173
174
175
176
177
178 protected String buildInnerTableClosing() {
179 return "</table></div>";
180 }
181
182
183
184
185
186
187 public HideShowBlock getHideShowBlock() {
188 return hideShowBlock;
189 }
190
191
192
193
194
195 public void setHideShowBlock(HideShowBlock hideShowBlock) {
196 this.hideShowBlock = hideShowBlock;
197 }
198
199 }