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