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