1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.exception.RiceRuntimeException;
20 import org.kuali.rice.krad.uif.UifConstants;
21 import org.kuali.rice.krad.uif.UifParameters;
22 import org.kuali.rice.krad.uif.UifPropertyPaths;
23 import org.kuali.rice.krad.uif.component.ComponentSecurity;
24 import org.kuali.rice.krad.uif.view.FormView;
25 import org.kuali.rice.krad.uif.view.View;
26 import org.kuali.rice.krad.uif.component.Component;
27 import org.kuali.rice.krad.uif.widget.LightBox;
28
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33
34
35
36
37
38
39 public class ActionField extends FieldBase {
40 private static final long serialVersionUID = 1025672792657238829L;
41
42 private String methodToCall;
43 private String navigateToPageId;
44
45 private String clientSideJs;
46
47 private String jumpToIdAfterSubmit;
48 private String jumpToNameAfterSubmit;
49 private String focusOnAfterSubmit;
50
51 private String actionLabel;
52 private ImageField actionImage;
53 private String actionImageLocation = "LEFT";
54
55 private String actionEvent;
56 private Map<String, String> actionParameters;
57
58 private LightBox lightBoxLookup;
59 private LightBox lightBoxDirectInquiry;
60
61 private boolean blockValidateDirty;
62 private boolean disabled;
63 private String disabledReason;
64
65 public ActionField() {
66 super();
67
68 disabled = false;
69
70 actionParameters = new HashMap<String, String>();
71 }
72
73
74
75
76
77
78
79
80
81
82 @Override
83 public void performInitialization(View view, Object model) {
84 super.performInitialization(view, model);
85
86 if (StringUtils.isBlank(actionLabel)) {
87 actionLabel = this.getLabel();
88 }
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102 @Override
103 public void performFinalize(View view, Object model, Component parent) {
104 super.performFinalize(view, model, parent);
105
106 if(actionImage != null && StringUtils.isNotBlank(actionImageLocation) && StringUtils.isNotBlank(actionLabel)){
107 actionImage.setAltText("");
108 }
109
110 if (!actionParameters.containsKey(UifConstants.UrlParams.ACTION_EVENT) && StringUtils.isNotBlank(actionEvent)) {
111 actionParameters.put(UifConstants.UrlParams.ACTION_EVENT, actionEvent);
112 }
113
114 actionParameters.put(UifConstants.UrlParams.SHOW_HOME, "false");
115 actionParameters.put(UifConstants.UrlParams.SHOW_HISTORY, "false");
116
117 if (StringUtils.isNotBlank(navigateToPageId)) {
118 actionParameters.put(UifParameters.NAVIGATE_TO_PAGE_ID, navigateToPageId);
119 if (StringUtils.isBlank(methodToCall)) {
120 actionParameters.put(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME,
121 UifConstants.MethodToCallNames.NAVIGATE);
122 }
123 }
124
125 if (!actionParameters.containsKey(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME)
126 && StringUtils.isNotBlank(methodToCall)) {
127 actionParameters.put(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME, methodToCall);
128 }
129
130
131 if (lightBoxLookup == null) {
132 String prefixScript = this.getOnClickScript();
133 if (prefixScript == null) {
134 prefixScript = "";
135 }
136
137 boolean validateFormDirty = false;
138 if (view instanceof FormView && !isBlockValidateDirty()) {
139 validateFormDirty = ((FormView) view).isValidateDirty();
140 }
141
142 boolean includeDirtyCheckScript = false;
143 String writeParamsScript = "";
144 if (!actionParameters.isEmpty()) {
145 for (String key : actionParameters.keySet()) {
146 String parameterPath = key;
147 if (!key.equals(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME)) {
148 parameterPath = UifPropertyPaths.ACTION_PARAMETERS + "[" + key + "]";
149 }
150
151 writeParamsScript = writeParamsScript + "writeHiddenToForm('" + parameterPath + "' , '"
152 + actionParameters.get(key) + "'); ";
153
154
155
156 if (validateFormDirty && !includeDirtyCheckScript
157 && key.equals(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME)) {
158 String keyValue = (String) actionParameters.get(key);
159 if (StringUtils.equals(keyValue, UifConstants.MethodToCallNames.REFRESH)
160 || StringUtils.equals(keyValue, UifConstants.MethodToCallNames.NAVIGATE)
161 || StringUtils.equals(keyValue, UifConstants.MethodToCallNames.CANCEL)
162 || StringUtils.equals(keyValue, UifConstants.MethodToCallNames.CLOSE)) {
163 includeDirtyCheckScript = true;
164 }
165 }
166 }
167 }
168
169
170
171
172 writeParamsScript = writeParamsScript + "writeHiddenToForm('" + UifConstants.UrlParams.SHOW_HISTORY
173 + "', '" + "false" + "'); ";
174 writeParamsScript = writeParamsScript + "writeHiddenToForm('" + UifConstants.UrlParams.SHOW_HOME + "' , '"
175 + "false" + "'); ";
176
177 if (StringUtils.isBlank(focusOnAfterSubmit)) {
178
179 focusOnAfterSubmit = this.getId();
180 writeParamsScript = writeParamsScript + "writeHiddenToForm('focusId' , '" + this.getId() + "'); ";
181 } else if (!focusOnAfterSubmit.equalsIgnoreCase(UifConstants.Order.FIRST.toString())) {
182
183 writeParamsScript = writeParamsScript + "writeHiddenToForm('focusId' , '" + focusOnAfterSubmit + "'); ";
184 } else {
185
186
187 writeParamsScript = writeParamsScript + "writeHiddenToForm('focusId' , ''); ";
188 }
189
190 if (StringUtils.isBlank(jumpToIdAfterSubmit) && StringUtils.isBlank(jumpToNameAfterSubmit)) {
191 jumpToIdAfterSubmit = this.getId();
192 writeParamsScript = writeParamsScript + "writeHiddenToForm('jumpToId' , '" + this.getId() + "'); ";
193 } else if (StringUtils.isNotBlank(jumpToIdAfterSubmit)) {
194 writeParamsScript = writeParamsScript + "writeHiddenToForm('jumpToId' , '" + jumpToIdAfterSubmit
195 + "'); ";
196 } else {
197 writeParamsScript = writeParamsScript + "writeHiddenToForm('jumpToName' , '" + jumpToNameAfterSubmit
198 + "'); ";
199 }
200
201 String postScript = "";
202 if (StringUtils.isNotBlank(clientSideJs)) {
203 postScript = clientSideJs;
204 } else {
205 postScript = "writeHiddenToForm('renderFullView' , 'true'); jq('#kualiForm').submit();";
206 }
207
208 if (includeDirtyCheckScript) {
209 this.setOnClickScript("e.preventDefault(); if (checkDirty(e) == false) { " + prefixScript
210 + writeParamsScript + postScript + " ; } ");
211 } else {
212 this.setOnClickScript("e.preventDefault();" + prefixScript + writeParamsScript + postScript);
213 }
214
215 } else {
216
217
218
219
220 StringBuffer sb = new StringBuffer();
221 sb.append("{");
222 for (String key : actionParameters.keySet()) {
223 String optionValue = actionParameters.get(key);
224 if (sb.length() > 1) {
225 sb.append(",");
226 }
227 if (!key.equals(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME)) {
228 sb.append("\"" + UifPropertyPaths.ACTION_PARAMETERS + "[" + key + "]" + "\"");
229 } else {
230 sb.append("\"" + key + "\"");
231 }
232 sb.append(":");
233 sb.append("\"" + optionValue + "\"");
234 }
235 sb.append("}");
236 lightBoxLookup.setActionParameterMapString(sb.toString());
237 }
238 }
239
240
241
242
243 @Override
244 public List<Component> getComponentsForLifecycle() {
245 List<Component> components = super.getComponentsForLifecycle();
246
247 components.add(actionImage);
248 components.add(lightBoxLookup);
249 components.add(lightBoxDirectInquiry);
250
251 return components;
252 }
253
254
255
256
257
258
259
260
261
262
263
264
265 public String getMethodToCall() {
266 return this.methodToCall;
267 }
268
269
270
271
272
273
274 public void setMethodToCall(String methodToCall) {
275 this.methodToCall = methodToCall;
276 }
277
278
279
280
281
282
283
284
285
286
287
288 public String getActionLabel() {
289 return this.actionLabel;
290 }
291
292
293
294
295
296
297 public void setActionLabel(String actionLabel) {
298 this.actionLabel = actionLabel;
299 }
300
301
302
303
304
305
306
307
308
309
310
311
312 public ImageField getActionImage() {
313 return this.actionImage;
314 }
315
316
317
318
319
320
321 public void setActionImage(ImageField actionImage) {
322 this.actionImage = actionImage;
323 }
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338 public String getNavigateToPageId() {
339 return this.navigateToPageId;
340 }
341
342
343
344
345
346
347 public void setNavigateToPageId(String navigateToPageId) {
348 this.navigateToPageId = navigateToPageId;
349 actionParameters.put(UifParameters.NAVIGATE_TO_PAGE_ID, navigateToPageId);
350 this.methodToCall = UifConstants.MethodToCallNames.NAVIGATE;
351 }
352
353
354
355
356
357
358
359
360
361
362
363
364 public String getActionEvent() {
365 return actionEvent;
366 }
367
368
369
370
371
372
373 public void setActionEvent(String actionEvent) {
374 this.actionEvent = actionEvent;
375 }
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391 public Map<String, String> getActionParameters() {
392 return this.actionParameters;
393 }
394
395
396
397
398
399
400 public void setActionParameters(Map<String, String> actionParameters) {
401 this.actionParameters = actionParameters;
402 }
403
404
405
406
407
408
409
410
411
412 public void addActionParameter(String parameterName, String parameterValue) {
413 if (actionParameters == null) {
414 this.actionParameters = new HashMap<String, String>();
415 }
416
417 this.actionParameters.put(parameterName, parameterValue);
418 }
419
420
421
422
423 public String getActionParameter(String parameterName) {
424 return this.actionParameters.get(parameterName);
425 }
426
427
428
429
430
431
432 @Override
433 public ActionFieldSecurity getComponentSecurity() {
434 return (ActionFieldSecurity) super.getComponentSecurity();
435 }
436
437
438
439
440
441
442 @Override
443 public void setComponentSecurity(ComponentSecurity componentSecurity) {
444 if (!(componentSecurity instanceof ActionFieldSecurity)) {
445 throw new RiceRuntimeException(
446 "Component security for ActionField should be instance of ActionFieldSecurity");
447 }
448
449 super.setComponentSecurity(componentSecurity);
450 }
451
452 @Override
453 protected Class<? extends ComponentSecurity> getComponentSecurityClass() {
454 return ActionFieldSecurity.class;
455 }
456
457
458
459
460 @Override
461 public boolean getSupportsOnClick() {
462 return true;
463 }
464
465
466
467
468
469
470
471 public void setLightBoxLookup(LightBox lightBoxLookup) {
472 this.lightBoxLookup = lightBoxLookup;
473 }
474
475
476
477
478
479
480
481
482
483
484 public LightBox getLightBoxLookup() {
485 return lightBoxLookup;
486 }
487
488
489
490
491 public String getJumpToIdAfterSubmit() {
492 return this.jumpToIdAfterSubmit;
493 }
494
495
496
497
498
499
500
501
502
503
504
505
506
507 public void setJumpToIdAfterSubmit(String jumpToIdAfterSubmit) {
508 this.jumpToIdAfterSubmit = jumpToIdAfterSubmit;
509 }
510
511
512
513
514
515
516
517
518
519
520
521 public String getJumpToNameAfterSubmit() {
522 return this.jumpToNameAfterSubmit;
523 }
524
525
526
527
528
529 public void setJumpToNameAfterSubmit(String jumpToNameAfterSubmit) {
530 this.jumpToNameAfterSubmit = jumpToNameAfterSubmit;
531 }
532
533
534
535
536
537
538
539
540
541 public String getFocusOnAfterSubmit() {
542 return this.focusOnAfterSubmit;
543 }
544
545
546
547
548
549 public void setFocusOnAfterSubmit(String focusOnAfterSubmit) {
550 this.focusOnAfterSubmit = focusOnAfterSubmit;
551 }
552
553
554
555
556
557
558
559
560
561
562
563
564 public String getClientSideJs() {
565 return this.clientSideJs;
566 }
567
568
569
570
571
572 public void setClientSideJs(String clientSideJs) {
573 if (!StringUtils.endsWith(clientSideJs, ";")) {
574 clientSideJs = clientSideJs + ";";
575 }
576 this.clientSideJs = clientSideJs;
577 }
578
579
580
581
582
583
584
585 public void setLightBoxDirectInquiry(LightBox lightBoxDirectInquiry) {
586 this.lightBoxDirectInquiry = lightBoxDirectInquiry;
587 }
588
589
590
591
592
593
594
595
596
597
598 public LightBox getLightBoxDirectInquiry() {
599 return lightBoxDirectInquiry;
600 }
601
602
603
604
605
606 public void setBlockValidateDirty(boolean blockValidateDirty) {
607 this.blockValidateDirty = blockValidateDirty;
608 }
609
610
611
612
613 public boolean isBlockValidateDirty() {
614 return blockValidateDirty;
615 }
616
617
618
619
620
621
622 public boolean isDisabled() {
623 return disabled;
624 }
625
626
627
628
629
630
631
632
633 public String getDisabledReason() {
634 return disabledReason;
635 }
636
637
638
639
640
641
642 public void setDisabledReason(String disabledReason) {
643 this.disabledReason = disabledReason;
644 }
645
646
647
648
649
650
651 public void setDisabled(boolean disabled) {
652 this.disabled = disabled;
653 }
654
655 public String getActionImageLocation() {
656 return actionImageLocation;
657 }
658
659
660
661
662
663
664
665
666 public void setActionImageLocation(String actionImageLocation) {
667 this.actionImageLocation = actionImageLocation;
668 }
669 }