1 | |
package org.kuali.student.lum.program.client.major.view; |
2 | |
|
3 | |
|
4 | |
|
5 | |
import org.kuali.student.common.assembly.data.Data; |
6 | |
import org.kuali.student.common.assembly.data.Data.Property; |
7 | |
import org.kuali.student.common.ui.client.application.Application; |
8 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
9 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
10 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
11 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
12 | |
import org.kuali.student.common.ui.client.service.SecurityRpcService; |
13 | |
import org.kuali.student.common.ui.client.service.SecurityRpcServiceAsync; |
14 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
15 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
16 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
17 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
18 | |
import org.kuali.student.common.ui.client.widgets.KSRadioButton; |
19 | |
import org.kuali.student.common.ui.shared.IdAttributes; |
20 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
21 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
22 | |
import org.kuali.student.lum.common.client.widgets.DropdownList; |
23 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
24 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
25 | |
import org.kuali.student.lum.program.client.ProgramSections; |
26 | |
import org.kuali.student.lum.program.client.ProgramStatus; |
27 | |
import org.kuali.student.lum.program.client.events.ModelLoadedEvent; |
28 | |
import org.kuali.student.lum.program.client.events.ProgramViewEvent; |
29 | |
import org.kuali.student.lum.program.client.major.ActionType; |
30 | |
import org.kuali.student.lum.program.client.major.MajorController; |
31 | |
|
32 | |
import com.google.gwt.core.client.GWT; |
33 | |
import com.google.gwt.event.dom.client.ChangeEvent; |
34 | |
import com.google.gwt.event.dom.client.ChangeHandler; |
35 | |
import com.google.gwt.event.dom.client.ClickEvent; |
36 | |
import com.google.gwt.event.dom.client.ClickHandler; |
37 | |
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
38 | |
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
39 | |
import com.google.gwt.event.shared.HandlerManager; |
40 | |
import com.google.gwt.user.client.ui.Anchor; |
41 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
42 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
43 | |
|
44 | |
|
45 | 0 | public class MajorViewController extends MajorController { |
46 | |
|
47 | |
|
48 | |
private static final String MSG_GROUP = "program"; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | private final DropdownList actionBox = new DropdownList(ActionType.getValuesForMajorDiscipline(false)); |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private boolean isCurrentVersion; |
61 | |
|
62 | |
private SecurityRpcServiceAsync securityRpc; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public MajorViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) { |
70 | 0 | super(programModel, viewContext, eventBus); |
71 | 0 | configurer = GWT.create(MajorViewConfigurer.class); |
72 | 0 | securityRpc = GWT .create(SecurityRpcService.class); |
73 | |
|
74 | |
|
75 | 0 | initHandlers(); |
76 | 0 | } |
77 | |
|
78 | |
private void initHandlers() { |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | 0 | actionBox.addChangeHandler(new ChangeHandler() { |
84 | |
@Override |
85 | |
public void onChange(ChangeEvent event) { |
86 | |
|
87 | |
|
88 | 0 | ActionType actionType = ActionType.of(actionBox.getSelectedValue()); |
89 | 0 | ViewContext viewContext = getViewContext(); |
90 | |
|
91 | |
|
92 | 0 | if (actionType == ActionType.MODIFY) { |
93 | 0 | processModifyActionType(viewContext); |
94 | |
} |
95 | |
|
96 | 0 | else if (actionType == ActionType.RETIRE) { |
97 | |
|
98 | |
} |
99 | 0 | } |
100 | |
}); |
101 | |
|
102 | |
|
103 | |
|
104 | 0 | eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() { |
105 | |
@Override |
106 | |
public void onEvent(ProgramViewEvent event) { |
107 | 0 | actionBox.setSelectedIndex(0); |
108 | 0 | } |
109 | |
}); |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | 0 | eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() { |
115 | |
@Override |
116 | |
public void onEvent(ModelLoadedEvent event) { |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | 0 | resetActionList(); |
123 | |
|
124 | 0 | String type = context.getAttributes().get(ProgramConstants.TYPE); |
125 | 0 | if (type != null) { |
126 | 0 | context.getAttributes().remove(ProgramConstants.TYPE); |
127 | 0 | if (type.equals(ProgramConstants.VARIATION_TYPE_KEY)) { |
128 | 0 | showVariationView(); |
129 | |
} else { |
130 | |
|
131 | 0 | context.getAttributes().remove(ProgramConstants.VARIATION_ID); |
132 | 0 | showView(ProgramSections.VIEW_ALL); |
133 | |
} |
134 | |
} else { |
135 | 0 | context.getAttributes().remove(ProgramConstants.VARIATION_ID); |
136 | 0 | showView(ProgramSections.VIEW_ALL); |
137 | |
} |
138 | 0 | } |
139 | |
}); |
140 | 0 | } |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
private void processModifyActionType(final ViewContext viewContext) { |
153 | 0 | String principalId = Application.getApplicationContext().getUserId(); |
154 | |
|
155 | 0 | securityRpc.checkAdminPermission(principalId, "useCurriculumReview", new KSAsyncCallback<Boolean>() { |
156 | |
@Override |
157 | |
public void onSuccess(Boolean result) { |
158 | 0 | final boolean isAuthorized = result; |
159 | |
|
160 | |
|
161 | 0 | if (isAuthorized) { |
162 | 0 | buildModifyDialog(viewContext, "/HOME/CURRICULUM_HOME/COURSE_PROPOSAL", programModel); |
163 | |
} else { |
164 | 0 | if (isProgramStatusValidForProposal()) { |
165 | 0 | showModifyProgramWithNewVersionCurriculumReviewView(); |
166 | |
} else { |
167 | 0 | showModifyProgramWithoutVersionView(viewContext); |
168 | |
} |
169 | |
} |
170 | 0 | } |
171 | |
}); |
172 | 0 | } |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
private void buildModifyDialog(final ViewContext viewContext, final String modifyPath, final DataModel model){ |
183 | 0 | final KSLightBox modifyDialog = new KSLightBox(); |
184 | |
|
185 | |
|
186 | 0 | modifyDialog.setTitle((getMessage("modifyProgramSubTitle"))); |
187 | |
|
188 | 0 | final VerticalPanel layout = new VerticalPanel(); |
189 | 0 | layout.addStyleName("ks-form-module-fields"); |
190 | |
|
191 | 0 | final KSButton continueButton = new KSButton(getMessage("continue")); |
192 | |
|
193 | 0 | modifyDialog.addButton(continueButton); |
194 | 0 | Anchor cancelLink = new Anchor("Cancel"); |
195 | |
|
196 | |
|
197 | 0 | cancelLink.addClickHandler(new ClickHandler(){ |
198 | |
public void onClick(ClickEvent event) { |
199 | 0 | modifyDialog.hide(); |
200 | 0 | } |
201 | |
}); |
202 | 0 | modifyDialog.addButton(cancelLink); |
203 | |
|
204 | 0 | HorizontalPanel titlePanel = new HorizontalPanel(); |
205 | 0 | KSLabel titleLabel = new KSLabel(getMessage("modifyProgramSubTitle")); |
206 | 0 | titleLabel.addStyleName("bold"); |
207 | 0 | titlePanel.add(titleLabel); |
208 | |
|
209 | 0 | layout.add(titlePanel); |
210 | |
|
211 | 0 | final KSRadioButton radioOptionModifyNoVersion = new KSRadioButton("modifyCreditProgramButtonGroup", getMessage("modifyProgramNoVersion")); |
212 | 0 | final KSRadioButton radioOptionModifyWithVersion = new KSRadioButton("modifyCreditProgramButtonGroup", getMessage("modifyProgramWithVersion")); |
213 | 0 | final KSCheckBox curriculumReviewOption = new KSCheckBox(getMessage("useCurriculumReview")); |
214 | |
|
215 | |
|
216 | 0 | radioOptionModifyNoVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ |
217 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
218 | 0 | if(event.getValue()){ |
219 | 0 | curriculumReviewOption.setEnabled(false); |
220 | 0 | curriculumReviewOption.setValue(false); |
221 | |
} |
222 | 0 | } |
223 | |
}); |
224 | 0 | radioOptionModifyNoVersion.setValue(true); |
225 | |
|
226 | |
|
227 | 0 | curriculumReviewOption.setEnabled(false); |
228 | |
|
229 | 0 | radioOptionModifyWithVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ |
230 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
231 | 0 | if(event.getValue()){ |
232 | 0 | curriculumReviewOption.setEnabled(true); |
233 | |
} |
234 | 0 | } |
235 | |
}); |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | 0 | continueButton.addClickHandler(new ClickHandler(){ |
241 | |
@Override |
242 | |
public void onClick(ClickEvent event) { |
243 | 0 | if (radioOptionModifyNoVersion.getValue()){ |
244 | |
|
245 | |
|
246 | |
|
247 | 0 | showModifyProgramWithoutVersionView(viewContext); |
248 | 0 | } else if (radioOptionModifyWithVersion.getValue() && curriculumReviewOption.getValue()){ |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | 0 | showModifyProgramWithNewVersionCurriculumReviewView(); |
254 | 0 | } else if (radioOptionModifyWithVersion.getValue()){ |
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
266 | 0 | viewContext.setId(versionIndId); |
267 | 0 | viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); |
268 | |
|
269 | |
|
270 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext); |
271 | |
} |
272 | |
|
273 | |
|
274 | 0 | modifyDialog.hide(); |
275 | 0 | } |
276 | |
}); |
277 | |
|
278 | |
|
279 | |
|
280 | 0 | layout.add(radioOptionModifyNoVersion); |
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | 0 | if (isProgramStatusValidForProposal()) { |
286 | 0 | layout.add(radioOptionModifyWithVersion); |
287 | 0 | layout.add(curriculumReviewOption); |
288 | |
} |
289 | |
|
290 | 0 | modifyDialog.setWidget(layout); |
291 | 0 | modifyDialog.show(); |
292 | 0 | } |
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
private boolean isProgramStatusValidForProposal() { |
302 | 0 | ProgramStatus status = ProgramStatus.of(programModel); |
303 | |
|
304 | 0 | if (isCurrentVersion |
305 | |
&& (status == ProgramStatus.ACTIVE || status == ProgramStatus.APPROVED || status == ProgramStatus.ACTIVE)) { |
306 | 0 | return true; |
307 | |
} |
308 | |
|
309 | 0 | return false; |
310 | |
} |
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
public String getMessage(String programMessageKey) { |
320 | 0 | String msg = Application.getApplicationContext().getMessage(MSG_GROUP, programMessageKey); |
321 | 0 | if (msg == null) { |
322 | 0 | msg = programMessageKey; |
323 | |
} |
324 | 0 | return msg; |
325 | |
} |
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
protected void resetActionList() { |
333 | |
|
334 | |
|
335 | 0 | ProgramStatus status = ProgramStatus.of(programModel); |
336 | |
|
337 | |
|
338 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
339 | |
|
340 | |
|
341 | 0 | Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER); |
342 | |
|
343 | |
|
344 | 0 | actionBox.clear(); |
345 | |
|
346 | |
|
347 | |
|
348 | 0 | programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>(){ |
349 | |
public void onSuccess(Boolean isLatest) { |
350 | |
|
351 | |
|
352 | |
|
353 | 0 | isCurrentVersion = isLatest; |
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | 0 | actionBox.setList(ActionType.getValuesForMajorDiscipline(isLatest)); |
359 | |
|
360 | 0 | if (!isCurrentVersion) { |
361 | 0 | String principalId = Application.getApplicationContext().getUserId(); |
362 | |
|
363 | 0 | securityRpc.checkAdminPermission(principalId, "useCurriculumReview", new KSAsyncCallback<Boolean>() { |
364 | |
@Override |
365 | |
public void onSuccess(Boolean result) { |
366 | 0 | final boolean isAuthorized = result; |
367 | |
|
368 | 0 | if (!isAuthorized) { |
369 | 0 | actionBox.removeItem(ActionType.MODIFY.getValue()); |
370 | |
} |
371 | 0 | } |
372 | |
}); |
373 | |
} |
374 | |
|
375 | 0 | } |
376 | |
}); |
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | 0 | String referenceId = programModel.getRoot().get("id"); |
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | 0 | if (status == ProgramStatus.DRAFT){ |
389 | 0 | programRemoteService.isProposal( "kuali.proposal.referenceType.clu", referenceId, new KSAsyncCallback<Boolean>(){ |
390 | |
public void onSuccess(Boolean isProposal) { |
391 | |
|
392 | |
|
393 | |
|
394 | 0 | if (isProposal){ |
395 | 0 | actionBox.setVisible(false); |
396 | |
} |
397 | |
|
398 | 0 | } |
399 | |
}); |
400 | |
} |
401 | 0 | } |
402 | |
|
403 | |
private void showVariationView() { |
404 | 0 | String variationId = context.getAttributes().get(ProgramConstants.VARIATION_ID); |
405 | 0 | if (variationId != null) { |
406 | 0 | final Data variationMap = getDataProperty(ProgramConstants.VARIATIONS); |
407 | 0 | if (variationMap != null) { |
408 | 0 | int row = 0; |
409 | 0 | for (Property p : variationMap) { |
410 | 0 | final Data variationData = p.getValue(); |
411 | 0 | if (variationData != null) { |
412 | 0 | if (variationData.get(ProgramConstants.ID).equals(variationId)) { |
413 | |
|
414 | |
|
415 | 0 | Data credData = getDataProperty(ProgramConstants.CREDENTIAL_PROGRAM); |
416 | 0 | variationData.set(ProgramConstants.CREDENTIAL_PROGRAM, credData); |
417 | 0 | ProgramRegistry.setData(variationData); |
418 | 0 | ProgramRegistry.setRow(row); |
419 | |
} |
420 | 0 | row++; |
421 | |
} |
422 | 0 | } |
423 | 0 | HistoryManager.navigate(AppLocations.Locations.VIEW_VARIATION.getLocation(), context); |
424 | |
} |
425 | |
} |
426 | 0 | } |
427 | |
|
428 | |
@Override |
429 | |
protected void configureView() { |
430 | 0 | super.configureView(); |
431 | 0 | addContentWidget(actionBox); |
432 | 0 | initialized = true; |
433 | 0 | } |
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
private void showModifyProgramWithoutVersionView(final ViewContext viewContext) { |
442 | 0 | ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum())); |
443 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext); |
444 | 0 | } |
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
private void showModifyProgramWithNewVersionCurriculumReviewView() { |
452 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | 0 | final ViewContext viewContext = new ViewContext(); |
459 | 0 | viewContext.setId(versionIndId); |
460 | 0 | viewContext.setIdType(IdAttributes.IdType.COPY_OF_OBJECT_ID); |
461 | 0 | Application.navigate(AppLocations.Locations.PROGRAM_PROPOSAL.getLocation(), viewContext); |
462 | 0 | } |
463 | |
} |