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