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