1 |
|
package org.kuali.student.lum.program.client.variation.edit; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
import java.util.List; |
5 |
|
|
6 |
|
import org.kuali.student.common.assembly.data.Data; |
7 |
|
import org.kuali.student.common.ui.client.application.Application; |
8 |
|
import org.kuali.student.common.ui.client.application.ViewContext; |
9 |
|
import org.kuali.student.common.ui.client.mvc.Callback; |
10 |
|
import org.kuali.student.common.ui.client.mvc.DataModel; |
11 |
|
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
12 |
|
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
13 |
|
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
14 |
|
import org.kuali.student.common.ui.client.widgets.KSButton; |
15 |
|
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract; |
16 |
|
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
17 |
|
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
18 |
|
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
19 |
|
import org.kuali.student.lum.common.client.widgets.AppLocations; |
20 |
|
import org.kuali.student.lum.program.client.ProgramConstants; |
21 |
|
import org.kuali.student.lum.program.client.ProgramRegistry; |
22 |
|
import org.kuali.student.lum.program.client.ProgramSections; |
23 |
|
import org.kuali.student.lum.program.client.events.ChangeViewEvent; |
24 |
|
import org.kuali.student.lum.program.client.events.ModelLoadedEvent; |
25 |
|
import org.kuali.student.lum.program.client.events.SpecializationCreatedEvent; |
26 |
|
import org.kuali.student.lum.program.client.events.SpecializationSaveEvent; |
27 |
|
import org.kuali.student.lum.program.client.events.SpecializationUpdateEvent; |
28 |
|
import org.kuali.student.lum.program.client.events.StoreSpecRequirementIDsEvent; |
29 |
|
import org.kuali.student.lum.program.client.major.edit.MajorEditController; |
30 |
|
import org.kuali.student.lum.program.client.properties.ProgramProperties; |
31 |
|
import org.kuali.student.lum.program.client.variation.VariationController; |
32 |
|
import org.kuali.student.lum.program.client.widgets.ProgramSideBar; |
33 |
|
|
34 |
|
import com.google.gwt.core.client.GWT; |
35 |
|
import com.google.gwt.event.dom.client.ClickEvent; |
36 |
|
import com.google.gwt.event.dom.client.ClickHandler; |
37 |
|
import com.google.gwt.event.shared.HandlerManager; |
38 |
|
import com.google.gwt.user.client.Window; |
39 |
|
|
40 |
|
|
41 |
|
@author |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 152 (152) |
Complexity: 38 |
Complexity Density: 0.36 |
|
43 |
|
public class VariationEditController extends VariationController { |
44 |
|
|
45 |
|
private final KSButton saveButton = new KSButton(ProgramProperties.get().common_save()); |
46 |
|
private final KSButton cancelButton = new KSButton(ProgramProperties.get().common_cancel(), KSButtonAbstract.ButtonStyle.ANCHOR_LARGE_CENTERED); |
47 |
|
|
48 |
|
private String currentId; |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
50 |
0
|
public VariationEditController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus, MajorEditController majorController) {... |
51 |
0
|
super(programModel, viewContext, eventBus, majorController); |
52 |
0
|
configurer = GWT.create(VariationEditConfigurer.class); |
53 |
0
|
sideBar.setState(ProgramSideBar.State.EDIT); |
54 |
0
|
if (getStringProperty(ProgramConstants.ID) != null) { |
55 |
0
|
setDefaultView(ProgramSections.SUMMARY); |
56 |
|
} |
57 |
0
|
initHandlers(); |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
60 |
0
|
private void initHandlers() {... |
61 |
0
|
saveButton.addClickHandler(new ClickHandler() { |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0
|
@Override... |
64 |
|
public void onClick(ClickEvent event) { |
65 |
0
|
doSave(); |
66 |
|
} |
67 |
|
}); |
68 |
0
|
cancelButton.addClickHandler(new ClickHandler() { |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0
|
@Override... |
71 |
|
public void onClick(ClickEvent event) { |
72 |
0
|
doCancel(); |
73 |
|
} |
74 |
|
}); |
75 |
0
|
ModelLoadedEvent.Handler modelLoadedHandler = new ModelLoadedEvent.Handler() { |
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
76 |
0
|
@Override... |
77 |
|
public void onEvent(ModelLoadedEvent event) { |
78 |
0
|
DataModel dataModel = event.getModel(); |
79 |
0
|
Data variationMap = dataModel.get(ProgramConstants.VARIATIONS); |
80 |
0
|
if (variationMap != null) { |
81 |
0
|
int row = 0; |
82 |
0
|
for (Data.Property property : variationMap) { |
83 |
0
|
final Data variationData = property.getValue(); |
84 |
0
|
if (variationData.get(ProgramConstants.ID).equals(currentId)) { |
85 |
0
|
programModel.setRoot(variationData); |
86 |
0
|
ProgramRegistry.setData(variationData); |
87 |
0
|
ProgramRegistry.setRow(row); |
88 |
0
|
setContentTitle(getProgramName()); |
89 |
0
|
row++; |
90 |
0
|
return; |
91 |
|
} |
92 |
|
} |
93 |
|
} |
94 |
|
} |
95 |
|
}; |
96 |
0
|
ProgramRegistry.addHandler(ModelLoadedEvent.TYPE, modelLoadedHandler); |
97 |
0
|
eventBus.addHandler(ModelLoadedEvent.TYPE, modelLoadedHandler); |
98 |
|
|
99 |
0
|
ChangeViewEvent.Handler changeViewHandler = new ChangeViewEvent.Handler() { |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
100 |
0
|
@Override... |
101 |
|
public void onEvent(ChangeViewEvent event) { |
102 |
0
|
Enum<?> viewToken = event.getViewToken(); |
103 |
0
|
if (!viewToken.name().equals(ProgramSections.SPECIALIZATIONS_EDIT.name())) { |
104 |
0
|
showView(viewToken); |
105 |
|
} |
106 |
|
} |
107 |
|
}; |
108 |
0
|
ProgramRegistry.addHandler(ChangeViewEvent.TYPE, changeViewHandler); |
109 |
0
|
eventBus.addHandler(ChangeViewEvent.TYPE, changeViewHandler); |
110 |
0
|
eventBus.addHandler(SpecializationCreatedEvent.TYPE, new SpecializationCreatedEvent.Handler() { |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
112 |
0
|
@Override... |
113 |
|
public void onEvent(SpecializationCreatedEvent event) { |
114 |
0
|
programModel.getRoot().set(ProgramConstants.ID, event.getSpecializationId()); |
115 |
0
|
showWarnings(); |
116 |
|
} |
117 |
|
}); |
118 |
|
|
119 |
0
|
eventBus.addHandler(SpecializationUpdateEvent.TYPE, new SpecializationUpdateEvent.Handler() { |
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
120 |
0
|
@Override... |
121 |
|
public void onEvent(SpecializationUpdateEvent event) { |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
0
|
String currSpecializationId = programModel.getRoot().get(ProgramConstants.ID); |
126 |
0
|
for (Data.Property prop : event.getSpecializations()) { |
127 |
0
|
String specId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); |
128 |
|
|
129 |
0
|
if (null != specId && specId.equals(currSpecializationId) && prop.getValueType().equals(Data.class)) { |
130 |
|
|
131 |
0
|
programModel.setRoot((Data) prop.getValue()); |
132 |
0
|
showView(getCurrentViewEnum()); |
133 |
|
} |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
0
|
showWarnings(); |
138 |
|
} |
139 |
|
}); |
140 |
|
|
141 |
0
|
StoreSpecRequirementIDsEvent.Handler requirementsHandler = new StoreSpecRequirementIDsEvent.Handler() { |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
142 |
0
|
@Override... |
143 |
|
public void onEvent(StoreSpecRequirementIDsEvent event) { |
144 |
0
|
final String programId = event.getProgramId(); |
145 |
0
|
final List<String> ids = event.getProgramRequirementIds(); |
146 |
|
|
147 |
0
|
requestModel(new ModelRequestCallback<DataModel>() { |
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
148 |
0
|
@Override... |
149 |
|
public void onModelReady(final DataModel model) { |
150 |
0
|
Data programRequirements = null; |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
0
|
Data variationData = model.getRoot(); |
155 |
0
|
if (variationData.get(ProgramConstants.ID).equals(programId)) { |
156 |
0
|
variationData.set(ProgramConstants.PROGRAM_REQUIREMENTS, new Data()); |
157 |
0
|
programRequirements = variationData.get(ProgramConstants.PROGRAM_REQUIREMENTS); |
158 |
|
|
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
0
|
if (programRequirements == null) { |
163 |
0
|
Window.alert("Cannot find program requirements in data model."); |
164 |
0
|
GWT.log("Cannot find program requirements in data model", null); |
165 |
0
|
return; |
166 |
|
} |
167 |
|
|
168 |
0
|
for (String id : ids) { |
169 |
0
|
programRequirements.add(id); |
170 |
|
} |
171 |
0
|
doSave(); |
172 |
|
} |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0
|
@Override... |
175 |
|
public void onRequestFail(Throwable cause) { |
176 |
0
|
GWT.log("Unable to retrieve model for validation and save", cause); |
177 |
|
} |
178 |
|
|
179 |
|
}); |
180 |
|
} |
181 |
|
}; |
182 |
0
|
ProgramRegistry.addHandler(StoreSpecRequirementIDsEvent.TYPE, requirementsHandler); |
183 |
0
|
eventBus.addHandler(StoreSpecRequirementIDsEvent.TYPE, requirementsHandler); |
184 |
|
} |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
186 |
0
|
@Override... |
187 |
|
protected void fireUpdateEvent(Callback<Boolean> okToChange) { |
188 |
0
|
doSave(okToChange); |
189 |
|
} |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
0
|
private void doSave(final Callback<Boolean> okToChange) {... |
192 |
0
|
requestModel(new ModelRequestCallback<DataModel>() { |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
193 |
0
|
@Override... |
194 |
|
public void onModelReady(final DataModel model) { |
195 |
0
|
VariationEditController.this.updateModelFromCurrentView(); |
196 |
0
|
model.setParentPath(ProgramConstants.VARIATIONS + "/" + ProgramRegistry.getRow()); |
197 |
0
|
model.validate(new Callback<List<ValidationResultInfo>>() { |
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
198 |
0
|
@Override... |
199 |
|
public void exec(List<ValidationResultInfo> results) { |
200 |
0
|
boolean isSectionValid = isValid(results, true); |
201 |
0
|
if (isSectionValid) { |
202 |
0
|
saveData(model); |
203 |
0
|
okToChange.exec(true); |
204 |
|
} else { |
205 |
0
|
okToChange.exec(false); |
206 |
0
|
KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); |
207 |
|
} |
208 |
|
} |
209 |
|
}); |
210 |
|
} |
211 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
0
|
@Override... |
213 |
|
public void onRequestFail(Throwable cause) { |
214 |
0
|
GWT.log("Unable to retrieve model for validation and save", cause); |
215 |
|
} |
216 |
|
|
217 |
|
}); |
218 |
|
} |
219 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
220 |
0
|
@Override... |
221 |
|
protected void configureView() { |
222 |
0
|
super.configureView(); |
223 |
0
|
if (!initialized) { |
224 |
0
|
List<Enum<?>> excludedViews = new ArrayList<Enum<?>>(); |
225 |
0
|
excludedViews.add(ProgramSections.PROGRAM_REQUIREMENTS_EDIT); |
226 |
0
|
excludedViews.add(ProgramSections.SUPPORTING_DOCUMENTS_EDIT); |
227 |
0
|
excludedViews.add(ProgramSections.SUMMARY); |
228 |
0
|
addCommonButton(ProgramProperties.get().program_menu_sections(), saveButton, excludedViews); |
229 |
0
|
addCommonButton(ProgramProperties.get().program_menu_sections(), cancelButton, excludedViews); |
230 |
0
|
initialized = true; |
231 |
|
} |
232 |
|
|
233 |
|
} |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
235 |
0
|
@Override... |
236 |
|
protected void resetModel() { |
237 |
0
|
currentId = getStringProperty(ProgramConstants.ID); |
238 |
0
|
programModel.resetRoot(); |
239 |
|
} |
240 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
241 |
0
|
private void doCancel() {... |
242 |
0
|
navigateToParent(ProgramSections.SUMMARY); |
243 |
|
} |
244 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
245 |
0
|
@Override... |
246 |
|
protected void doSave() { |
247 |
0
|
doSave(NO_OP_CALLBACK); |
248 |
|
} |
249 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
250 |
0
|
private void saveData(DataModel model) {... |
251 |
0
|
currentId = model.get(ProgramConstants.ID); |
252 |
0
|
eventBus.fireEvent(new SpecializationSaveEvent(model.getRoot())); |
253 |
0
|
setContentTitle(getProgramName()); |
254 |
0
|
setName(getProgramName()); |
255 |
0
|
resetFieldInteractionFlag(); |
256 |
|
} |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
258 |
0
|
@Override... |
259 |
|
protected void navigateToParent() { |
260 |
0
|
navigateToParent(ProgramSections.SPECIALIZATIONS_EDIT); |
261 |
|
} |
262 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
263 |
0
|
private void navigateToParent(ProgramSections parentSection) {... |
264 |
|
|
265 |
0
|
String path = HistoryManager.appendContext(AppLocations.Locations.EDIT_PROGRAM_SPEC.getLocation(), getViewContext()) + "/" + parentSection; |
266 |
0
|
HistoryManager.navigate(path); |
267 |
|
} |
268 |
|
|
269 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
270 |
0
|
@Override... |
271 |
|
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
272 |
|
|
273 |
0
|
Application.getApplicationContext().clearCrossConstraintsWithStartingPath(null,ProgramConstants.VARIATIONS); |
274 |
|
|
275 |
|
|
276 |
0
|
String newParentPath = ProgramConstants.VARIATIONS+"/"+org.kuali.student.lum.program.client.ProgramRegistry.getRow()+"/"; |
277 |
0
|
Application.getApplicationContext().setParentPath(newParentPath); |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
0
|
Callback<Boolean> finalizeVariationView = new Callback<Boolean>(){ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
283 |
0
|
public void exec(Boolean result) {... |
284 |
|
|
285 |
0
|
for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){ |
286 |
0
|
crossConstraint.reprocessWithUpdatedConstraints(); |
287 |
|
} |
288 |
|
|
289 |
0
|
onReadyCallback.exec(result); |
290 |
|
} |
291 |
|
}; |
292 |
0
|
super.beforeShow(finalizeVariationView); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
297 |
0
|
@Override... |
298 |
|
public <V extends Enum<?>> void showView(V viewType, |
299 |
|
final Callback<Boolean> onReadyCallback) { |
300 |
0
|
Callback<Boolean> updateCrossConstraintsCallback = new Callback<Boolean>(){ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
301 |
0
|
public void exec(Boolean result) {... |
302 |
0
|
onReadyCallback.exec(result); |
303 |
0
|
showWarnings(); |
304 |
|
} |
305 |
|
}; |
306 |
0
|
super.showView(viewType, updateCrossConstraintsCallback); |
307 |
|
} |
308 |
|
|
309 |
|
} |