1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.container;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.kuali.rice.core.api.util.KeyValue;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
24 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
25 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
26 import org.kuali.rice.krad.uif.UifConstants;
27 import org.kuali.rice.krad.uif.component.Component;
28 import org.kuali.rice.krad.uif.control.MultiValueControl;
29 import org.kuali.rice.krad.uif.field.InputField;
30 import org.kuali.rice.krad.uif.field.MessageField;
31 import org.kuali.rice.krad.uif.util.ScriptUtils;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 @BeanTags({@BeanTag(name = "dialogGroup-bean", parent = "Uif-DialogGroup"),
65 @BeanTag(name = "sensitiveData-dialogGroup-bean", parent = "Uif-SensitiveData-DialogGroup"),
66 @BeanTag(name = "ok-cancel-dialogGroup-bean", parent = "Uif-OK-Cancel-DialogGroup"),
67 @BeanTag(name = "yes-no-dialogGroup-bean", parent = "Uif-Yes-No-DialogGroup"),
68 @BeanTag(name = "true-false-dialogGroup-bean", parent = "Uif-True-False-DialogGroup"),
69 @BeanTag(name = "checkbox-dialogGroup-bean", parent = "Uif-Checkbox-DialogGroup"),
70 @BeanTag(name = "radioButton-dialogGroup-bean", parent = "Uif-RadioButton-DialogGroup")})
71 public class DialogGroup extends Group {
72 private static final long serialVersionUID = 1L;
73
74 private String promptText;
75 private List<KeyValue> availableResponses;
76
77 private MessageField prompt;
78 private InputField explanation;
79 private InputField responseInputField;
80
81 private boolean reverseButtonOrder;
82 private boolean displayExplanation;
83
84 private String onDialogResponseScript;
85 private String onShowDialogScript;
86
87 public DialogGroup() {
88 super();
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102 @Override
103 public void performInitialization(Object model) {
104 super.performInitialization(model);
105
106
107
108 List<Component> newItems = new ArrayList<Component>();
109 List<? extends Component> items = getItems();
110
111
112 if (!(items.contains(prompt))) {
113 newItems.add(prompt);
114 }
115
116 if (!(items.contains(explanation))) {
117 newItems.add(explanation);
118 }
119
120 newItems.addAll(getItems());
121
122 if (!(items.contains(responseInputField))) {
123 newItems.add(responseInputField);
124 }
125
126 this.setItems(newItems);
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 @Override
146 public void performApplyModel(Object model, Component parent) {
147 super.performApplyModel(model, parent);
148
149
150 prompt.setMessageText(promptText);
151
152
153 explanation.setRender(displayExplanation);
154
155
156 if (responseInputField.getControl() != null && responseInputField.getControl() instanceof MultiValueControl) {
157 MultiValueControl multiValueControl = (MultiValueControl) responseInputField.getControl();
158
159 if (reverseButtonOrder) {
160
161 List<KeyValue> buttonList = new ArrayList<KeyValue>(availableResponses);
162 Collections.reverse(buttonList);
163 multiValueControl.setOptions(buttonList);
164 } else {
165 multiValueControl.setOptions(availableResponses);
166 }
167 }
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 @Override
185 public void performFinalize(Object model, Component parent) {
186 super.performFinalize(model, parent);
187
188 if (responseInputField != null) {
189 String responseInputSelector = "#" + responseInputField.getId() + " [name='" +
190 responseInputField.getBindingInfo().getBindingPath() + "']";
191
192 String onChangeScript = "var value = coerceValue(\"" + responseInputField.getBindingInfo().getBindingPath()
193 + "\");";
194 onChangeScript += "jQuery('#" + getId() + "').trigger({type:'" + UifConstants.JsEvents.DIALOG_RESPONSE
195 + "',value:value});";
196
197 String onChangeHandler = "jQuery(\"" + responseInputSelector + "\").change(function(e){" + onChangeScript
198 + "});";
199
200 String onReadyScript = ScriptUtils.appendScript(getOnDocumentReadyScript(), onChangeHandler);
201 setOnDocumentReadyScript(onReadyScript);
202 }
203 }
204
205
206
207
208
209
210 @Override
211 public String getEventHandlerScript() {
212 String handlerScript = super.getEventHandlerScript();
213
214 handlerScript += ScriptUtils.buildEventHandlerScript(getId(), UifConstants.JsEvents.DIALOG_RESPONSE,
215 getOnDialogResponseScript());
216
217 handlerScript += ScriptUtils.buildEventHandlerScript(getId(), UifConstants.JsEvents.SHOW_DIALOG,
218 getOnShowDialogScript());
219
220 return handlerScript;
221 }
222
223
224
225
226
227
228
229 @BeanTagAttribute(name = "promptText")
230 public String getPromptText() {
231 return promptText;
232 }
233
234
235
236
237
238
239 public void setPromptText(String promptText) {
240 this.promptText = promptText;
241 }
242
243
244
245
246
247
248 @BeanTagAttribute(name = "prompt", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
249 public MessageField getPrompt() {
250 return prompt;
251 }
252
253
254
255
256
257
258 public void setPrompt(MessageField prompt) {
259 this.prompt = prompt;
260 }
261
262
263
264
265
266
267
268
269
270
271
272 @BeanTagAttribute(name = "explanation", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
273 public InputField getExplanation() {
274 return explanation;
275 }
276
277
278
279
280
281
282 public void setExplanation(InputField explanation) {
283 this.explanation = explanation;
284 }
285
286
287
288
289
290
291
292
293
294
295 @BeanTagAttribute(name = "displayExplanation")
296 public boolean isDisplayExplanation() {
297 return displayExplanation;
298 }
299
300
301
302
303
304
305 public void setDisplayExplanation(boolean displayExplanation) {
306 this.displayExplanation = displayExplanation;
307 }
308
309
310
311
312
313
314
315
316
317
318 @BeanTagAttribute(name = "availableResponses", type = BeanTagAttribute.AttributeType.LISTBEAN)
319 public List<KeyValue> getAvailableResponses() {
320 return availableResponses;
321 }
322
323
324
325
326
327
328 public void setAvailableResponses(List<KeyValue> availableResponses) {
329 this.availableResponses = availableResponses;
330 }
331
332
333
334
335
336
337
338
339
340
341
342
343 @BeanTagAttribute(name = "responseInputField", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
344 public InputField getResponseInputField() {
345 return responseInputField;
346 }
347
348
349
350
351
352
353 public void setResponseInputField(InputField responseInputField) {
354 this.responseInputField = responseInputField;
355 }
356
357
358
359
360
361
362
363
364
365
366
367
368 @BeanTagAttribute(name = "reverseButtonOrder")
369 public boolean isReverseButtonOrder() {
370 return reverseButtonOrder;
371 }
372
373
374
375
376
377
378
379
380
381
382 public void setReverseButtonOrder(boolean reverseButtonOrder) {
383 this.reverseButtonOrder = reverseButtonOrder;
384 }
385
386
387
388
389
390
391
392
393
394
395
396
397 @BeanTagAttribute(name = "onDialogResponseScript")
398 public String getOnDialogResponseScript() {
399 return onDialogResponseScript;
400 }
401
402
403
404
405
406
407 public void setOnDialogResponseScript(String onDialogResponseScript) {
408 this.onDialogResponseScript = onDialogResponseScript;
409 }
410
411
412
413
414
415
416
417
418
419
420
421
422 @BeanTagAttribute(name = "onShowDialogScript")
423 public String getOnShowDialogScript() {
424 return onShowDialogScript;
425 }
426
427
428
429
430
431
432 public void setOnShowDialogScript(String onShowDialogScript) {
433 this.onShowDialogScript = onShowDialogScript;
434 }
435
436
437
438
439 @Override
440 protected <T> void copyProperties(T component) {
441 super.copyProperties(component);
442
443 DialogGroup dialogGroupCopy = (DialogGroup) component;
444
445 if (this.availableResponses != null) {
446 dialogGroupCopy.setAvailableResponses(new ArrayList<KeyValue>(this.availableResponses));
447 }
448
449 dialogGroupCopy.setDisplayExplanation(this.displayExplanation);
450 dialogGroupCopy.setOnDialogResponseScript(this.onDialogResponseScript);
451 dialogGroupCopy.setOnShowDialogScript(this.onShowDialogScript);
452
453 if (this.prompt != null) {
454 dialogGroupCopy.setPrompt((MessageField)this.prompt.copy());
455 }
456
457 dialogGroupCopy.setPromptText(this.promptText);
458 dialogGroupCopy.setReverseButtonOrder(this.reverseButtonOrder);
459
460 if (this.explanation != null) {
461 dialogGroupCopy.setExplanation((InputField) this.explanation.copy());
462 }
463
464 if (this.responseInputField != null) {
465 dialogGroupCopy.setResponseInputField((InputField) this.responseInputField.copy());
466 }
467 }
468 }