1 package gboat2.base.view.components;
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5
6 import org.apache.commons.lang3.RandomStringUtils;
7 import org.apache.struts2.components.ClosingUIBean;
8 import org.apache.struts2.views.annotations.StrutsTag;
9 import org.apache.struts2.views.annotations.StrutsTagAttribute;
10
11 import com.opensymphony.xwork2.util.ValueStack;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 @StrutsTag(
37 name = "dialog",
38 tldTagClass = "gboat2.base.view.jsp.DialogTag",
39 description = "创建一个弹出框,弹出框中的内容可以是本页中的内容或通过 ajax 远程加载的数据,详见 http://api.jqueryui.com/dialog/",
40 allowDynamicAttributes = true)
41 public class Dialog extends ClosingUIBean {
42
43 public static final String TEMPLATE = "dialog";
44 public static final String TEMPLATE_CLOSE = "dialog-close";
45 public static final String JQUERYACTION = "dialog";
46
47 protected String appendTo;
48 protected String autoOpen;
49 protected String buttons;
50 protected String closeOnEscape;
51 protected String closeText;
52 protected String dialogClass;
53 protected String draggable;
54 protected String height;
55 protected String hide;
56 protected String maxHeight;
57 protected String maxWidth;
58 protected String minHeight;
59 protected String minWidth;
60 protected String modal;
61 protected String position;
62 protected String resizable;
63 protected String show;
64 protected String width;
65
66 protected String showCloseButton;
67
68 protected String onBeforeCloseTopics;
69 protected String onCloseTopics;
70 protected String onFocusTopics;
71 protected String onOpenTopics;
72 protected String openTopics;
73 protected String closeTopics;
74 protected String destroyTopics;
75
76 public Dialog(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
77 super(stack, request, response);
78 }
79
80 @Override
81 public String getDefaultOpenTemplate() {
82 return TEMPLATE;
83 }
84
85 @Override
86 protected String getDefaultTemplate() {
87 return TEMPLATE_CLOSE;
88 }
89
90 @Override
91 public void evaluateExtraParams() {
92 super.evaluateExtraParams();
93
94 addParameter("jqueryaction", JQUERYACTION);
95
96 if (appendTo != null)
97 addParameter("appendTo", findString(appendTo));
98
99 if (autoOpen != null)
100 addParameter("autoOpen", findValue(autoOpen, Boolean.class));
101
102 if (buttons != null)
103 addParameter("buttons", findString(buttons));
104
105 if (closeOnEscape != null)
106 addParameter("closeOnEscape", findValue(closeOnEscape, Boolean.class));
107
108 if (closeOnEscape != null)
109 addParameter("closeText", findString(closeText));
110
111 if (dialogClass != null)
112 addParameter("dialogClass", findString(dialogClass));
113
114 if (draggable != null)
115 addParameter("draggable", findValue(draggable, Boolean.class));
116
117 if (height != null)
118 addParameter("height", findValue(height, Integer.class));
119
120 if (hide != null)
121 addParameter("hide", findString(hide));
122
123 if (maxHeight != null)
124 addParameter("maxHeight", findValue(maxHeight, Integer.class));
125
126 if (maxWidth != null)
127 addParameter("maxWidth", findValue(maxWidth, Integer.class));
128
129 if (minHeight != null)
130 addParameter("minHeight", findValue(minHeight, Integer.class));
131
132 if (minWidth != null)
133 addParameter("minWidth", findValue(minWidth, Integer.class));
134
135 if (modal != null)
136 addParameter("modal", findValue(modal, Boolean.class));
137
138 if (position != null)
139 addParameter("position", findString(position));
140
141 if (resizable != null)
142 addParameter("resizable", findValue(resizable, Boolean.class));
143
144 if (show != null)
145 addParameter("show", findString(show));
146
147 if (width != null)
148 addParameter("width", findString(width));
149
150 if (showCloseButton != null)
151 addParameter("showCloseButton", findValue(showCloseButton, Boolean.class));
152
153 if ((this.id == null || this.id.length() == 0)) {
154 this.id = "dialog_" + RandomStringUtils.randomNumeric(3);
155 addParameter("id", this.id);
156 }
157
158 if (onBeforeCloseTopics != null)
159 addParameter("onBeforeCloseTopics", findString(onBeforeCloseTopics));
160
161 if (onCloseTopics != null)
162 addParameter("onCloseTopics", findString(onCloseTopics));
163
164 if (onFocusTopics != null)
165 addParameter("onFocusTopics", findString(onFocusTopics));
166
167 if (onOpenTopics != null)
168 addParameter("onOpenTopics", findString(onOpenTopics));
169
170 if (openTopics != null)
171 addParameter("openTopics", findString(openTopics));
172
173 if (closeTopics != null)
174 addParameter("closeTopics", findString(closeTopics));
175
176 if (destroyTopics != null)
177 addParameter("destroyTopics", findString(destroyTopics));
178 }
179
180 @StrutsTagAttribute(description = "dialog(和遮罩层,如果 modal=true)应该被追加到哪个元素。", defaultValue = "body")
181 public void setAppendTo(String appendTo) {
182 this.appendTo = appendTo;
183 }
184
185 @StrutsTagAttribute(description = "当设置为 true 时, dialog 会在初始化时自动打开. 如果为 false dialog 将会继续隐藏直到调用open()方法 。", type = "Boolean", defaultValue = "true")
186 public void setAutoOpen(String autoOpen) {
187 this.autoOpen = autoOpen;
188 }
189
190 @StrutsTagAttribute(description = "定义需要显示的按钮,是一个 JSON 数组的字符串,如:[{text: '关闭', click: function(){$(this).dialog('close');}}]。回调函数的上下文(即 this)指向的对象是 dialog 元素,如果需要获得点击的按钮对象,可以通过 event.target 获取,详见:http://api.jqueryui.com/dialog/#option-buttons。")
191 public void setButtons(String buttons) {
192 this.buttons = buttons;
193 }
194
195 @StrutsTagAttribute(description = "在用户按下退出(ESC)键时,是否关闭当前具有焦点的弹出框 ", type = "Boolean", defaultValue = "true")
196 public void setCloseOnEscape(String closeOnEscape) {
197 this.closeOnEscape = closeOnEscape;
198 }
199
200 @StrutsTagAttribute(description = "关闭按钮显示的文本", defaultValue = "关闭")
201 public void setCloseText(String closeText) {
202 this.closeText = closeText;
203 }
204
205 @StrutsTagAttribute(description = "设置弹出框的附加样式类")
206 public void setDialogClass(String dialogClass) {
207 this.dialogClass = dialogClass;
208 }
209
210 @StrutsTagAttribute(description = "弹出框是否可以进行拖动", type = "Boolean", defaultValue = "true")
211 public void setDraggable(String draggable) {
212 this.draggable = draggable;
213 }
214
215 @StrutsTagAttribute(description = "设置弹出框的高度(单位:像素)。 ", type="Integer")
216 public void setHeight(String height) {
217 this.height = height;
218 }
219
220 @StrutsTagAttribute(description = "关闭(隐藏)弹出框的动画效果,如 slideUp、fold,可用的动画效果请参见 http://api.jqueryui.com/category/effects/。")
221 public void setHide(String hide) {
222 this.hide = hide;
223 }
224
225 @StrutsTagAttribute(description = "弹出框可以调整的最大高度,以像素为单位。")
226 public void setMaxHeight(String maxHeight) {
227 this.maxHeight = maxHeight;
228 }
229
230 @StrutsTagAttribute(description = "可以调整的最大宽度,以像素为单位。")
231 public void setMaxWidth(String maxWidth) {
232 this.maxWidth = maxWidth;
233 }
234
235 @StrutsTagAttribute(description = "可以调整的最小高度,以像素为单位。")
236 public void setMinHeight(String minHeight) {
237 this.minHeight = minHeight;
238 }
239
240 @StrutsTagAttribute(description = "可以调整的最小宽度,以像素为单位。")
241 public void setMinWidth(String minWidth) {
242 this.minWidth = minWidth;
243 }
244
245 @StrutsTagAttribute(description = "是否以模态弹出框的方式进行展现。如果设置为true,该dialog将会有遮罩层; 页面上的其他项目将被禁用, 即,不能交互。 遮罩层创建弹出框下方,但高于其它页面元素。 ", type = "Boolean", defaultValue = "false")
246 public void setModal(String modal) {
247 this.modal = modal;
248 }
249
250 @StrutsTagAttribute(description = "设置弹出框显示的位置,详见 http://api.jqueryui.com/dialog/#option-position。", defaultValue = "{ my: 'center', at: 'center', of: window }")
251 public void setPosition(String position) {
252 this.position = position;
253 }
254
255 @StrutsTagAttribute(description = "是否允许通过拖拽鼠标调整弹出框的大小", type = "Boolean", defaultValue = "true")
256 public void setResizable(String resizable) {
257 this.resizable = resizable;
258 }
259
260 @StrutsTagAttribute(description = "打开(显示)弹出框的动画效果,如 slideUp、fold,可用的动画效果请参见 http://api.jqueryui.com/category/effects/。")
261 public void setShow(String show) {
262 this.show = show;
263 }
264
265 @Override
266 @StrutsTagAttribute(description = "弹出框的标题文字")
267 public void setTitle(String title) {
268 super.setTitle(title);
269 }
270
271 @StrutsTagAttribute(description = "设置弹出框的宽度(单位:像素)。 ", type="Integer")
272 public void setWidth(String width) {
273 this.width = width;
274 }
275
276 @StrutsTagAttribute(description = "是否显示关闭按钮", type="Boolean", defaultValue = "true")
277 public void setShowCloseButton(String showCloseButton) {
278 this.showCloseButton = showCloseButton;
279 }
280
281 @StrutsTagAttribute(description = "关闭弹出框之前(触发 beforeClose 事件时)发布的主题,多值之间使用逗号分隔")
282 public void setOnBeforeCloseTopics(String onBeforeCloseTopics) {
283 this.onBeforeCloseTopics = onBeforeCloseTopics;
284 }
285
286 @StrutsTagAttribute(description = "关闭弹出框之后(触发 close 事件时)发布的主题,多值之间使用逗号分隔")
287 public void setOnCloseTopics(String onCloseTopics) {
288 this.onCloseTopics = onCloseTopics;
289 }
290
291 @StrutsTagAttribute(description = "弹出框获得焦点时(触发 focus 事件时)发布的主题,多值之间使用逗号分隔")
292 public void setOnFocusTopics(String onFocusTopics) {
293 this.onFocusTopics = onFocusTopics;
294 }
295
296 @StrutsTagAttribute(description = "打开(显示)弹出框时(触发 open 事件时)发布的主题,多值之间使用逗号分隔")
297 public void setOnOpenTopics(String onOpenTopics) {
298 this.onOpenTopics = onOpenTopics;
299 }
300
301 @StrutsTagAttribute(description = "订阅的关闭弹出框的话题,执行调用弹出框实例的 close() 方法,关闭弹出框")
302 public void setOpenTopics(String openTopics) {
303 this.openTopics = openTopics;
304 }
305
306 @StrutsTagAttribute(description = "订阅的打开弹出框的话题,执行调用弹出框实例的 open() 方法,打开弹出框")
307 public void setCloseTopics(String closeTopics) {
308 this.closeTopics = closeTopics;
309 }
310
311 @StrutsTagAttribute(description = "订阅的销毁弹出框的话题,执行调用弹出框实例的 destroy() 方法,销毁弹出框")
312 public void setDestroyTopics(String destroyTopics) {
313 this.destroyTopics = destroyTopics;
314 }
315 }