1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.uif.widget; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.krad.uif.UifConstants; |
20 | |
import org.kuali.rice.krad.uif.UifParameters; |
21 | |
import org.kuali.rice.krad.uif.field.InputField; |
22 | |
import org.kuali.rice.krad.uif.view.View; |
23 | |
import org.kuali.rice.krad.uif.component.BindingInfo; |
24 | |
import org.kuali.rice.krad.uif.component.Component; |
25 | |
import org.kuali.rice.krad.uif.field.ActionField; |
26 | |
import org.kuali.rice.krad.util.UrlFactory; |
27 | |
|
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
import java.util.Map.Entry; |
31 | |
import java.util.Properties; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class DirectInquiry extends Inquiry { |
39 | |
private static final long serialVersionUID = -2490979579285984314L; |
40 | |
|
41 | |
private ActionField directInquiryActionField; |
42 | |
|
43 | |
private boolean adjustInquiryParameters; |
44 | |
private BindingInfo fieldBindingInfo; |
45 | |
|
46 | |
public DirectInquiry() { |
47 | 0 | super(); |
48 | |
|
49 | 0 | adjustInquiryParameters = false; |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Override |
57 | |
public void performFinalize(View view, Object model, Component parent) { |
58 | 0 | super.performFinalize(view, model, parent); |
59 | |
|
60 | |
|
61 | 0 | if (!isRender() || isReadOnly()) { |
62 | 0 | return; |
63 | |
} |
64 | |
|
65 | |
|
66 | 0 | setRender(false); |
67 | |
|
68 | 0 | InputField field = (InputField) parent; |
69 | |
|
70 | |
|
71 | 0 | if (StringUtils.isBlank(getDataObjectClassName()) |
72 | |
|| (getInquiryParameters() == null) |
73 | |
|| getInquiryParameters().isEmpty()) { |
74 | |
|
75 | 0 | adjustInquiryParameters = true; |
76 | 0 | fieldBindingInfo = field.getBindingInfo(); |
77 | |
} |
78 | |
|
79 | 0 | setupLink(view, model, field); |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public void buildInquiryLink(Object dataObject, String propertyName, |
96 | |
Class<?> inquiryObjectClass, Map<String, String> inquiryParms) { |
97 | 0 | Properties urlParameters = new Properties(); |
98 | |
|
99 | 0 | urlParameters.put(UifParameters.DATA_OBJECT_CLASS_NAME, |
100 | |
inquiryObjectClass.getName()); |
101 | 0 | urlParameters.put(UifParameters.METHOD_TO_CALL, |
102 | |
UifConstants.MethodToCallNames.START); |
103 | |
|
104 | |
|
105 | 0 | String inquiryUrl = UrlFactory.parameterizeUrl(getBaseInquiryUrl(), |
106 | |
urlParameters); |
107 | 0 | StringBuilder paramMapString = new StringBuilder(); |
108 | |
|
109 | |
|
110 | 0 | String lightBoxOptions = ""; |
111 | 0 | boolean lightBoxShow = directInquiryActionField.getLightBoxDirectInquiry() != null; |
112 | 0 | if (lightBoxShow) { |
113 | 0 | lightBoxOptions = directInquiryActionField.getLightBoxDirectInquiry() |
114 | |
.getComponentOptionsJSString(); |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | 0 | for (Entry<String, String> inquiryParameter : inquiryParms.entrySet()) { |
120 | 0 | String inquiryParameterFrom = inquiryParameter.getKey(); |
121 | 0 | if (adjustInquiryParameters && (fieldBindingInfo != null)) { |
122 | 0 | inquiryParameterFrom = fieldBindingInfo.getPropertyAdjustedBindingPath(inquiryParameterFrom); |
123 | |
} |
124 | 0 | paramMapString.append(inquiryParameterFrom); |
125 | 0 | paramMapString.append(":"); |
126 | 0 | paramMapString.append(inquiryParameter.getValue()); |
127 | 0 | paramMapString.append(","); |
128 | 0 | } |
129 | 0 | paramMapString.deleteCharAt(paramMapString.length() - 1); |
130 | |
|
131 | |
|
132 | |
|
133 | 0 | StringBuilder onClickScript = new StringBuilder("showDirectInquiry(\""); |
134 | 0 | onClickScript.append(inquiryUrl); |
135 | 0 | onClickScript.append("\", \""); |
136 | 0 | onClickScript.append(paramMapString); |
137 | 0 | onClickScript.append("\", "); |
138 | 0 | onClickScript.append(lightBoxShow); |
139 | 0 | onClickScript.append(", "); |
140 | 0 | onClickScript.append(lightBoxOptions); |
141 | 0 | onClickScript.append(");"); |
142 | |
|
143 | 0 | directInquiryActionField.setBlockValidateDirty(true); |
144 | 0 | directInquiryActionField.setClientSideJs(onClickScript.toString()); |
145 | |
|
146 | 0 | setRender(true); |
147 | 0 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
@Override |
153 | |
public List<Component> getComponentsForLifecycle() { |
154 | 0 | List<Component> components = super.getComponentsForLifecycle(); |
155 | |
|
156 | 0 | components.add(directInquiryActionField); |
157 | |
|
158 | 0 | return components; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public ActionField getDirectInquiryActionField() { |
165 | 0 | return this.directInquiryActionField; |
166 | |
} |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
public void setDirectInquiryActionField(ActionField directInquiryActionField) { |
172 | 0 | this.directInquiryActionField = directInquiryActionField; |
173 | 0 | } |
174 | |
|
175 | |
} |