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