1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.lu.ui.course.client.controllers; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.student.common.assembly.data.Data; |
22 | |
import org.kuali.student.common.assembly.data.Metadata; |
23 | |
import org.kuali.student.common.dto.DtoConstants; |
24 | |
import org.kuali.student.common.rice.authorization.PermissionType; |
25 | |
import org.kuali.student.common.ui.client.application.Application; |
26 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
27 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
28 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.DocumentLayoutController; |
29 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.TabMenuController; |
30 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
31 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
32 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
33 | |
import org.kuali.student.common.ui.client.mvc.ModelProvider; |
34 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
35 | |
import org.kuali.student.common.ui.client.mvc.WorkQueue; |
36 | |
import org.kuali.student.common.ui.client.mvc.WorkQueue.WorkItem; |
37 | |
import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel; |
38 | |
import org.kuali.student.common.ui.client.util.ExportElement; |
39 | |
import org.kuali.student.common.ui.client.util.ExportUtils; |
40 | |
import org.kuali.student.common.ui.client.util.WindowTitleUtils; |
41 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
42 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
43 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
44 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
45 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
46 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
47 | |
import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; |
48 | |
import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; |
49 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection; |
50 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
51 | |
import org.kuali.student.core.statement.dto.StatementTypeInfo; |
52 | |
import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper; |
53 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer; |
54 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.ViewCourseConfigurer; |
55 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.ViewCourseConfigurer.ViewCourseSections; |
56 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel; |
57 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.HasRequirements; |
58 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService; |
59 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync; |
60 | |
import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList; |
61 | |
|
62 | |
import com.google.gwt.core.client.GWT; |
63 | |
import com.google.gwt.event.dom.client.ClickEvent; |
64 | |
import com.google.gwt.event.dom.client.ClickHandler; |
65 | |
import com.google.gwt.event.logical.shared.CloseEvent; |
66 | |
import com.google.gwt.event.logical.shared.CloseHandler; |
67 | |
import com.google.gwt.user.client.Window; |
68 | |
import com.google.gwt.user.client.ui.Widget; |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | 0 | public class ViewCourseController extends TabMenuController implements DocumentLayoutController, HasRequirements{ |
77 | 0 | private final DataModel cluModel = new DataModel(); |
78 | |
|
79 | |
private WorkQueue modelRequestQueue; |
80 | |
|
81 | 0 | private String cluType = "kuali.lu.type.CreditCourse"; |
82 | 0 | private String courseId = null; |
83 | |
|
84 | |
private static final String CLU_STATE = DtoConstants.STATE_ACTIVE; |
85 | |
private static final String MSG_GROUP = "course"; |
86 | |
|
87 | 0 | private final String REFERENCE_TYPE = "referenceType.clu"; |
88 | 0 | private boolean initialized = false; |
89 | 0 | CourseRpcServiceAsync rpcServiceAsync = GWT.create(CourseRpcService.class); |
90 | |
|
91 | 0 | private final BlockingTask loadDataTask = new BlockingTask("Retrieving Data...."); |
92 | 0 | private final BlockingTask initTask = new BlockingTask("Initializing...."); |
93 | 0 | private final KSLabel statusLabel = new KSLabel(""); |
94 | |
|
95 | 0 | private final List<CourseWorkflowActionList> actionDropDownWidgets = new ArrayList<CourseWorkflowActionList>(); |
96 | |
|
97 | |
private final CourseRequirementsDataModel reqDataModel; |
98 | |
|
99 | 0 | final ViewCourseConfigurer cfg = GWT.create(ViewCourseConfigurer.class); |
100 | |
|
101 | |
public ViewCourseController(Enum<?> viewType){ |
102 | 0 | super(CourseProposalController.class.getName()); |
103 | 0 | initialize(); |
104 | 0 | addStyleName("courseView"); |
105 | 0 | reqDataModel = new CourseRequirementsDataModel(this); |
106 | 0 | this.tabPanel.addStyleName("standard-content-padding"); |
107 | 0 | this.setViewEnum(viewType); |
108 | 0 | } |
109 | |
|
110 | |
@Override |
111 | |
public void setViewContext(ViewContext viewContext) { |
112 | 0 | super.setViewContext(viewContext); |
113 | 0 | if(viewContext.getId() != null && !viewContext.getId().isEmpty()){ |
114 | 0 | viewContext.setPermissionType(PermissionType.OPEN); |
115 | 0 | this.setCourseId(viewContext.getId()); |
116 | |
} |
117 | 0 | } |
118 | |
|
119 | |
private void initialize() { |
120 | 0 | super.setDefaultModelId(CourseProposalConfigurer.COURSE_PROPOSAL_MODEL); |
121 | 0 | super.registerModel(CourseProposalConfigurer.COURSE_PROPOSAL_MODEL, new ModelProvider<DataModel>() { |
122 | |
|
123 | |
@Override |
124 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
125 | 0 | if (modelRequestQueue == null){ |
126 | 0 | modelRequestQueue = new WorkQueue(); |
127 | |
} |
128 | |
|
129 | 0 | WorkItem workItem = new WorkItem(){ |
130 | |
@Override |
131 | |
public void exec(Callback<Boolean> workCompleteCallback) { |
132 | 0 | if (cluModel.getRoot() == null || cluModel.getRoot().size() == 0){ |
133 | 0 | if (courseId != null){ |
134 | 0 | getCourseFromCluId(callback, workCompleteCallback); |
135 | |
} else{ |
136 | 0 | createNewCluModel(callback, workCompleteCallback); |
137 | |
} |
138 | |
} else { |
139 | 0 | callback.onModelReady(cluModel); |
140 | 0 | workCompleteCallback.exec(true); |
141 | |
} |
142 | 0 | } |
143 | |
}; |
144 | 0 | modelRequestQueue.submit(workItem); |
145 | |
|
146 | 0 | } |
147 | |
|
148 | |
}); |
149 | |
|
150 | |
|
151 | 0 | } |
152 | |
|
153 | |
|
154 | |
public Widget generateActionDropDown(){ |
155 | 0 | CourseWorkflowActionList actionList = new CourseWorkflowActionList(this.getMessage("cluActionsLabel"), getViewContext(), "/HOME/CURRICULUM_HOME/COURSE_PROPOSAL", cluModel, new Callback<String>() { |
156 | |
@Override |
157 | |
public void exec(String newState) { |
158 | 0 | if (newState != null) { |
159 | 0 | KSNotifier.add(new KSNotification(getMessage("cluStateChangeNotification" + newState), false, 5000)); |
160 | |
|
161 | 0 | statusLabel.setText("Course Status: " + newState); |
162 | |
} else { |
163 | 0 | KSNotifier.add(new KSNotification(getMessage("cluStateChangeFailedNotification"), false, 5000)); |
164 | |
} |
165 | 0 | } |
166 | |
}); |
167 | 0 | actionDropDownWidgets.add(actionList); |
168 | |
|
169 | 0 | return actionList; |
170 | |
} |
171 | |
|
172 | |
private void init(final Callback<Boolean> onReadyCallback) { |
173 | |
|
174 | 0 | if (initialized) { |
175 | 0 | onReadyCallback.exec(true); |
176 | |
} else { |
177 | 0 | KSBlockingProgressIndicator.addTask(initTask); |
178 | 0 | this.setContentTitle("View Course"); |
179 | 0 | this.setName("Course"); |
180 | 0 | String idType = null; |
181 | 0 | String viewContextId = null; |
182 | |
|
183 | |
|
184 | 0 | if(getViewContext().getIdType() != null){ |
185 | 0 | idType = getViewContext().getIdType().toString(); |
186 | 0 | viewContextId = getViewContext().getId(); |
187 | 0 | if(getViewContext().getIdType()==IdType.COPY_OF_OBJECT_ID){ |
188 | 0 | viewContextId = null; |
189 | |
} |
190 | |
|
191 | |
} |
192 | |
|
193 | 0 | rpcServiceAsync.getMetadata("", null, new KSAsyncCallback<Metadata>(){ |
194 | |
|
195 | |
@Override |
196 | |
public void handleFailure(Throwable caught) { |
197 | 0 | initialized = false; |
198 | 0 | onReadyCallback.exec(false); |
199 | 0 | KSBlockingProgressIndicator.removeTask(initTask); |
200 | 0 | throw new RuntimeException("Failed to get model definition.", caught); |
201 | |
} |
202 | |
|
203 | |
public void onSuccess(Metadata result) { |
204 | 0 | DataModelDefinition def = new DataModelDefinition(result); |
205 | 0 | cluModel.setDefinition(def); |
206 | 0 | init(def, onReadyCallback); |
207 | 0 | } |
208 | |
}); |
209 | |
|
210 | |
} |
211 | 0 | } |
212 | |
|
213 | |
private void updateCourseActionItems() { |
214 | |
|
215 | 0 | for(CourseWorkflowActionList widget: actionDropDownWidgets){ |
216 | 0 | widget.updateCourseActionItems(cluModel); |
217 | |
} |
218 | 0 | } |
219 | |
|
220 | |
private void init(final DataModelDefinition modelDefinition, final Callback<Boolean> onReadyCallback){ |
221 | |
|
222 | 0 | CourseRequirementsDataModel.getStatementTypes(new Callback<List<StatementTypeInfo>>() { |
223 | |
|
224 | |
@Override |
225 | |
public void exec(List<StatementTypeInfo> stmtTypes) { |
226 | 0 | List<StatementTypeInfo> stmtTypesOut = new ArrayList<StatementTypeInfo>(); |
227 | 0 | if (stmtTypes != null) { |
228 | 0 | for (StatementTypeInfo stmtType : stmtTypes) { |
229 | 0 | if (stmtType.getId().contains("kuali.statement.type.course.enrollmentEligibility") || |
230 | |
stmtType.getId().contains("kuali.statement.type.course.creditConstraints")) { |
231 | 0 | continue; |
232 | |
} |
233 | 0 | stmtTypesOut.add(stmtType); |
234 | |
} |
235 | |
} |
236 | 0 | if(!initialized){ |
237 | 0 | initialized = true; |
238 | 0 | cfg.setStatementTypes(stmtTypesOut); |
239 | 0 | cfg.setModelDefinition(modelDefinition); |
240 | 0 | cfg.generateLayout(ViewCourseController.this); |
241 | |
} |
242 | 0 | onReadyCallback.exec(true); |
243 | 0 | KSBlockingProgressIndicator.removeTask(initTask); |
244 | 0 | } |
245 | |
}); |
246 | 0 | } |
247 | |
|
248 | |
@SuppressWarnings("unchecked") |
249 | |
@Override |
250 | |
public void requestModel(Class modelType, final ModelRequestCallback callback) { |
251 | 0 | if(modelType == ReferenceModel.class){ |
252 | 0 | if (cluModel != null){ |
253 | 0 | ReferenceModel ref = new ReferenceModel(); |
254 | |
|
255 | 0 | if(cluModel.get("course/id") != null){ |
256 | 0 | ref.setReferenceId((String)cluModel.get("course/id")); |
257 | |
} else{ |
258 | 0 | ref.setReferenceId(null); |
259 | |
} |
260 | |
|
261 | 0 | ref.setReferenceTypeKey(REFERENCE_TYPE); |
262 | 0 | ref.setReferenceType(cluType); |
263 | 0 | ref.setReferenceState(CLU_STATE); |
264 | |
|
265 | 0 | callback.onModelReady(ref); |
266 | 0 | } |
267 | 0 | }else if (modelType == Data.class){ |
268 | 0 | requestModel(CourseProposalConfigurer.COURSE_PROPOSAL_MODEL, callback); |
269 | |
} else { |
270 | 0 | super.requestModel(modelType, callback); |
271 | |
} |
272 | 0 | } |
273 | |
|
274 | |
@SuppressWarnings("unchecked") |
275 | |
private void getCourseFromCluId(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
276 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
277 | |
|
278 | 0 | rpcServiceAsync.getData(courseId, new KSAsyncCallback<Data>(){ |
279 | |
|
280 | |
@Override |
281 | |
public void handleFailure(Throwable caught) { |
282 | 0 | Window.alert("Error loading Course: "+caught.getMessage()); |
283 | 0 | createNewCluModel(callback, workCompleteCallback); |
284 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
285 | 0 | } |
286 | |
|
287 | |
@Override |
288 | |
public void onSuccess(Data result) { |
289 | 0 | cluModel.setRoot(result); |
290 | |
|
291 | 0 | setHeaderTitle(); |
292 | 0 | updateCourseActionItems(); |
293 | 0 | callback.onModelReady(cluModel); |
294 | 0 | workCompleteCallback.exec(true); |
295 | 0 | reqDataModel.retrieveStatementTypes(cluModel.<String>get("id"), new Callback<Boolean>() { |
296 | |
@Override |
297 | |
public void exec(Boolean result) { |
298 | 0 | if (result) { |
299 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
300 | |
} |
301 | 0 | } |
302 | |
}); |
303 | |
|
304 | 0 | } |
305 | |
|
306 | |
}); |
307 | 0 | } |
308 | |
|
309 | |
@SuppressWarnings("unchecked") |
310 | |
private void getCurrentVersion(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback) { |
311 | 0 | rpcServiceAsync.getData(courseId, new KSAsyncCallback<Data>(){ |
312 | |
|
313 | |
@Override |
314 | |
public void handleFailure(Throwable caught) { |
315 | 0 | Window.alert("Error loading Course: "+caught.getMessage()); |
316 | 0 | createNewCluModel(callback, workCompleteCallback); |
317 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
318 | 0 | } |
319 | |
|
320 | |
@Override |
321 | |
public void onSuccess(Data result) { |
322 | 0 | cluModel.setRoot(result); |
323 | |
|
324 | 0 | setHeaderTitle(); |
325 | 0 | updateCourseActionItems(); |
326 | 0 | callback.onModelReady(cluModel); |
327 | 0 | workCompleteCallback.exec(true); |
328 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
329 | 0 | } |
330 | |
|
331 | |
}); |
332 | 0 | } |
333 | |
|
334 | |
@SuppressWarnings("unchecked") |
335 | |
private void createNewCluModel(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
336 | 0 | cluModel.setRoot(new Data()); |
337 | 0 | callback.onModelReady(cluModel); |
338 | 0 | workCompleteCallback.exec(true); |
339 | 0 | } |
340 | |
|
341 | |
public String getCourseId() { |
342 | 0 | return courseId; |
343 | |
} |
344 | |
|
345 | |
public String getVersionIndId() { |
346 | 0 | return (String)cluModel.get("versionInfo/versionIndId"); |
347 | |
} |
348 | |
|
349 | |
public void setCourseId(String courseId) { |
350 | 0 | this.courseId = courseId; |
351 | 0 | this.cluModel.setRoot(new Data()); |
352 | 0 | } |
353 | |
|
354 | |
public void clear(String cluType){ |
355 | 0 | super.clear(); |
356 | 0 | this.cluType = cluType; |
357 | 0 | if (cluModel != null){ |
358 | 0 | this.cluModel.setRoot(new Data()); |
359 | |
} |
360 | 0 | this.courseId = null; |
361 | 0 | } |
362 | |
|
363 | |
@Override |
364 | |
public void showDefaultView(final Callback<Boolean> onReadyCallback) { |
365 | 0 | init(new Callback<Boolean>() { |
366 | |
|
367 | |
@Override |
368 | |
public void exec(Boolean result) { |
369 | 0 | if (result) { |
370 | 0 | ViewCourseController.super.showDefaultView(onReadyCallback); |
371 | |
} else { |
372 | 0 | onReadyCallback.exec(false); |
373 | |
} |
374 | 0 | } |
375 | |
}); |
376 | 0 | } |
377 | |
|
378 | |
@Override |
379 | |
public void beforeShow(Callback<Boolean> onReadyCallback) { |
380 | 0 | showDefaultView(onReadyCallback); |
381 | 0 | } |
382 | |
|
383 | |
private KSButton getQuitButton(){ |
384 | 0 | return new KSButton("Quit", new ClickHandler(){ |
385 | |
public void onClick(ClickEvent event) { |
386 | 0 | Application.navigate("/HOME/CURRICULUM_HOME"); |
387 | 0 | } |
388 | |
}); |
389 | |
} |
390 | |
|
391 | |
|
392 | |
protected void setHeaderTitle() { |
393 | |
|
394 | |
String title; |
395 | 0 | if (cluModel.get("transcriptTitle") != null){ |
396 | 0 | title = getCourseTitle(); |
397 | |
} |
398 | |
else{ |
399 | 0 | title = "Course"; |
400 | |
} |
401 | |
|
402 | 0 | updateStatus(); |
403 | |
|
404 | 0 | this.setContentTitle(title); |
405 | 0 | this.setName(title); |
406 | 0 | WindowTitleUtils.setContextTitle(title); |
407 | 0 | } |
408 | |
|
409 | |
private void updateStatus() { |
410 | 0 | if(cluModel.get("state") != null){ |
411 | 0 | statusLabel.setText(getMessage("courseStatusLabel") + ": " + cluModel.get("state")); |
412 | |
} |
413 | 0 | } |
414 | |
|
415 | |
private CloseHandler<KSLightBox> createActionSubmitSuccessHandler() { |
416 | 0 | CloseHandler<KSLightBox> handler = new CloseHandler<KSLightBox>(){ |
417 | |
@Override |
418 | |
public void onClose(CloseEvent<KSLightBox> event) { |
419 | |
|
420 | 0 | Window.Location.reload(); |
421 | 0 | } |
422 | |
}; |
423 | 0 | return handler; |
424 | |
} |
425 | |
|
426 | |
public String getMessage(String courseMessageKey) { |
427 | 0 | String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey); |
428 | 0 | if (msg == null) { |
429 | 0 | msg = courseMessageKey; |
430 | |
} |
431 | 0 | return msg; |
432 | |
} |
433 | |
|
434 | |
public Widget getStatusLabel() { |
435 | 0 | statusLabel.setStyleName("courseStatusLabel"); |
436 | 0 | return statusLabel; |
437 | |
} |
438 | |
|
439 | |
public Widget getVersionHistoryWidget(){ |
440 | 0 | KSButton button = new KSButton("Version History", ButtonStyle.DEFAULT_ANCHOR, new ClickHandler(){ |
441 | |
|
442 | |
@Override |
443 | |
public void onClick(ClickEvent event) { |
444 | 0 | parentController.showView(ViewCourseParentController.Views.VERSIONS); |
445 | 0 | } |
446 | |
}); |
447 | 0 | button.addStyleName("versionHistoryLink"); |
448 | 0 | return button; |
449 | |
|
450 | |
} |
451 | |
|
452 | |
@Override |
453 | |
public void onHistoryEvent(String historyStack) { |
454 | 0 | super.onHistoryEvent(historyStack); |
455 | 0 | if (cluModel.get("courseTitle") != null){ |
456 | 0 | RecentlyViewedHelper.addCurrentDocument(getCourseTitle()); |
457 | |
} |
458 | 0 | } |
459 | |
|
460 | |
public String getCourseTitle(){ |
461 | 0 | return cluModel.get("courseTitle"); |
462 | |
} |
463 | |
|
464 | |
|
465 | |
public String getCurrentId() { |
466 | 0 | return cluModel.get("id"); |
467 | |
} |
468 | |
|
469 | |
@Override |
470 | |
public CourseRequirementsDataModel getReqDataModel() { |
471 | 0 | return reqDataModel; |
472 | |
} |
473 | |
|
474 | |
@Override |
475 | |
public DataModel getExportDataModel() { |
476 | 0 | return cluModel; |
477 | |
} |
478 | |
|
479 | |
@Override |
480 | |
public boolean isExportButtonActive() { |
481 | 0 | if (this.getCurrentViewEnum() != null && this.getCurrentViewEnum().equals(ViewCourseSections.DETAILED)) { |
482 | 0 | return true; |
483 | |
} |
484 | 0 | return false; |
485 | |
} |
486 | |
|
487 | |
@Override |
488 | |
public ArrayList<ExportElement> getExportElementsFromView() { |
489 | 0 | ArrayList<ExportElement> exportElements = new ArrayList<ExportElement>(); |
490 | 0 | if (this.getCurrentViewEnum().equals(ViewCourseSections.DETAILED)) { |
491 | 0 | SummaryTableSection tableSection = this.cfg.getSummaryConfigurer().getTableSection(); |
492 | 0 | ExportElement heading = new ExportElement(); |
493 | 0 | heading.setFieldLabel(""); |
494 | 0 | heading.setFieldValue(tableSection.getTitle()); |
495 | 0 | exportElements.add(heading); |
496 | 0 | exportElements = ExportUtils.getDetailsForWidget(tableSection, exportElements); |
497 | |
} |
498 | 0 | return exportElements; |
499 | |
} |
500 | |
} |