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 super();
48
49 adjustInquiryParameters = false;
50 }
51
52
53
54
55
56 @Override
57 public void performFinalize(View view, Object model, Component parent) {
58 super.performFinalize(view, model, parent);
59
60
61 if (!isRender() || isReadOnly()) {
62 return;
63 }
64
65
66 setRender(false);
67
68 InputField field = (InputField) parent;
69
70
71 if (StringUtils.isBlank(getDataObjectClassName())
72 || (getInquiryParameters() == null)
73 || getInquiryParameters().isEmpty()) {
74
75 adjustInquiryParameters = true;
76 fieldBindingInfo = field.getBindingInfo();
77 }
78
79 setupLink(view, model, field);
80 }
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 Properties urlParameters = new Properties();
98
99 urlParameters.put(UifParameters.DATA_OBJECT_CLASS_NAME,
100 inquiryObjectClass.getName());
101 urlParameters.put(UifParameters.METHOD_TO_CALL,
102 UifConstants.MethodToCallNames.START);
103
104
105 String inquiryUrl = UrlFactory.parameterizeUrl(getBaseInquiryUrl(),
106 urlParameters);
107 StringBuilder paramMapString = new StringBuilder();
108
109
110 String lightBoxOptions = "";
111 boolean lightBoxShow = directInquiryActionField.getLightBoxDirectInquiry() != null;
112 if (lightBoxShow) {
113 lightBoxOptions = directInquiryActionField.getLightBoxDirectInquiry()
114 .getComponentOptionsJSString();
115 }
116
117
118
119 for (Entry<String, String> inquiryParameter : inquiryParms.entrySet()) {
120 String inquiryParameterFrom = inquiryParameter.getKey();
121 if (adjustInquiryParameters && (fieldBindingInfo != null)) {
122 inquiryParameterFrom = fieldBindingInfo.getPropertyAdjustedBindingPath(inquiryParameterFrom);
123 }
124 paramMapString.append(inquiryParameterFrom);
125 paramMapString.append(":");
126 paramMapString.append(inquiryParameter.getValue());
127 paramMapString.append(",");
128 }
129 paramMapString.deleteCharAt(paramMapString.length() - 1);
130
131
132
133 StringBuilder onClickScript = new StringBuilder("showDirectInquiry(\"");
134 onClickScript.append(inquiryUrl);
135 onClickScript.append("\", \"");
136 onClickScript.append(paramMapString);
137 onClickScript.append("\", ");
138 onClickScript.append(lightBoxShow);
139 onClickScript.append(", ");
140 onClickScript.append(lightBoxOptions);
141 onClickScript.append(");");
142
143 directInquiryActionField.setBlockValidateDirty(true);
144 directInquiryActionField.setClientSideJs(onClickScript.toString());
145
146 setRender(true);
147 }
148
149
150
151
152 @Override
153 public List<Component> getComponentsForLifecycle() {
154 List<Component> components = super.getComponentsForLifecycle();
155
156 components.add(directInquiryActionField);
157
158 return components;
159 }
160
161
162
163
164 public ActionField getDirectInquiryActionField() {
165 return this.directInquiryActionField;
166 }
167
168
169
170
171 public void setDirectInquiryActionField(ActionField directInquiryActionField) {
172 this.directInquiryActionField = directInquiryActionField;
173 }
174
175 }