1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle.finalize;
17
18 import java.util.Map;
19
20 import org.kuali.rice.core.api.CoreApiServiceLocator;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
23 import org.kuali.rice.krad.uif.lifecycle.FinalizeComponentPhase;
24 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
25 import org.kuali.rice.krad.uif.lifecycle.ViewLifecyclePhase;
26 import org.kuali.rice.krad.uif.util.ScriptUtils;
27 import org.kuali.rice.krad.uif.view.View;
28 import org.kuali.rice.krad.uif.view.ViewModel;
29 import org.kuali.rice.krad.util.KRADConstants;
30
31
32
33
34
35
36 public class FinalizeViewTask extends ViewLifecycleTaskBase<View> {
37
38
39
40
41
42
43 public FinalizeViewTask(ViewLifecyclePhase phase) {
44 super(phase, View.class);
45 }
46
47
48
49
50 @Override
51 public FinalizeComponentPhase getElementState() {
52 return (FinalizeComponentPhase) super.getElementState();
53 }
54
55
56
57
58 @Override
59 protected void performLifecycleTask() {
60 View view = (View) getElementState().getElement();
61 assert view == ViewLifecycle.getView();
62 Object model = ViewLifecycle.getModel();
63
64 view.setPreLoadScript(ScriptUtils.appendScript(
65 view.getPreLoadScript(), buildClientSideStateScript(model)));
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79 protected String buildClientSideStateScript(Object model) {
80 Map<String, Object> clientSideState = ((ViewModel) model).getClientStateForSyncing();
81
82
83 String clientStateScript = "";
84 if (!clientSideState.isEmpty()) {
85 clientStateScript = ScriptUtils.buildFunctionCall(UifConstants.JsFunctions.INITIALIZE_VIEW_STATE,
86 clientSideState);
87 }
88
89
90 String kradImageLocation = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
91 UifConstants.ConfigProperties.KRAD_IMAGES_URL);
92 clientStateScript += ScriptUtils.buildFunctionCall(UifConstants.JsFunctions.SET_CONFIG_PARM,
93 UifConstants.ClientSideVariables.KRAD_IMAGE_LOCATION, kradImageLocation);
94
95 String kradURL = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
96 UifConstants.ConfigProperties.KRAD_URL);
97 clientStateScript += ScriptUtils.buildFunctionCall(UifConstants.JsFunctions.SET_CONFIG_PARM,
98 UifConstants.ClientSideVariables.KRAD_URL, kradURL);
99
100 String applicationURL = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
101 KRADConstants.ConfigParameters.APPLICATION_URL);
102 clientStateScript += ScriptUtils.buildFunctionCall(UifConstants.JsFunctions.SET_CONFIG_PARM,
103 UifConstants.ClientSideVariables.APPLICATION_URL, applicationURL);
104
105 String scriptCleanup = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
106 KRADConstants.ConfigParameters.KRAD_SCRIPT_CLEANUP);
107 clientStateScript += ScriptUtils.buildFunctionCall(UifConstants.JsFunctions.SET_CONFIG_PARM,
108 UifConstants.ClientSideVariables.KRAD_SCRIPT_CLEANUP, scriptCleanup);
109
110 return clientStateScript;
111 }
112
113 }