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