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