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