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.text.DateFormat; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Date; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import org.kuali.student.common.assembly.data.Data; |
26 | |
import org.kuali.student.common.assembly.data.Metadata; |
27 | |
import org.kuali.student.common.assembly.data.QueryPath; |
28 | |
import org.kuali.student.common.dto.DtoConstants; |
29 | |
import org.kuali.student.common.rice.StudentIdentityConstants; |
30 | |
import org.kuali.student.common.rice.authorization.PermissionType; |
31 | |
import org.kuali.student.common.ui.client.application.Application; |
32 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
33 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
34 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
35 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.MenuEditableSectionController; |
36 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection; |
37 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
38 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; |
39 | |
import org.kuali.student.common.ui.client.event.ActionEvent; |
40 | |
import org.kuali.student.common.ui.client.event.ContentDirtyEvent; |
41 | |
import org.kuali.student.common.ui.client.event.ContentDirtyEventHandler; |
42 | |
import org.kuali.student.common.ui.client.event.SaveActionEvent; |
43 | |
import org.kuali.student.common.ui.client.event.SaveActionHandler; |
44 | |
import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback; |
45 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
46 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
47 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
48 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
49 | |
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
50 | |
import org.kuali.student.common.ui.client.mvc.ModelProvider; |
51 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
52 | |
import org.kuali.student.common.ui.client.mvc.View; |
53 | |
import org.kuali.student.common.ui.client.mvc.WorkQueue; |
54 | |
import org.kuali.student.common.ui.client.mvc.WorkQueue.WorkItem; |
55 | |
import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel; |
56 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
57 | |
import org.kuali.student.common.ui.client.security.AuthorizationCallback; |
58 | |
import org.kuali.student.common.ui.client.security.RequiresAuthorization; |
59 | |
import org.kuali.student.common.ui.client.service.BaseDataOrchestrationRpcServiceAsync; |
60 | |
import org.kuali.student.common.ui.client.service.DataSaveResult; |
61 | |
import org.kuali.student.common.ui.client.util.ExportElement; |
62 | |
import org.kuali.student.common.ui.client.util.ExportUtils; |
63 | |
import org.kuali.student.common.ui.client.util.WindowTitleUtils; |
64 | |
import org.kuali.student.common.ui.client.validator.ValidatorClientUtils; |
65 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
66 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
67 | |
import org.kuali.student.common.ui.client.widgets.KSDropDown; |
68 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
69 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
70 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.YesNoCancelEnum; |
71 | |
import org.kuali.student.common.ui.client.widgets.dialog.ButtonMessageDialog; |
72 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup; |
73 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.YesNoCancelGroup; |
74 | |
import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; |
75 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
76 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
77 | |
import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; |
78 | |
import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; |
79 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
80 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection; |
81 | |
import org.kuali.student.common.ui.shared.IdAttributes; |
82 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
83 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
84 | |
import org.kuali.student.core.statement.dto.StatementTypeInfo; |
85 | |
import org.kuali.student.core.workflow.ui.client.widgets.WorkflowEnhancedNavController; |
86 | |
import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities; |
87 | |
import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper; |
88 | |
import org.kuali.student.lum.common.client.lu.LUUIConstants; |
89 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
90 | |
import org.kuali.student.lum.lu.LUConstants; |
91 | |
import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants; |
92 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer; |
93 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer.CourseSections; |
94 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel; |
95 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.HasRequirements; |
96 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService; |
97 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync; |
98 | |
import org.kuali.student.lum.lu.ui.course.client.service.CreditCourseProposalRpcService; |
99 | |
import org.kuali.student.lum.lu.ui.course.client.service.CreditCourseProposalRpcServiceAsync; |
100 | |
|
101 | |
import com.google.gwt.core.client.GWT; |
102 | |
import com.google.gwt.event.dom.client.ClickEvent; |
103 | |
import com.google.gwt.event.dom.client.ClickHandler; |
104 | |
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
105 | |
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
106 | |
import com.google.gwt.user.client.Window; |
107 | |
import com.google.gwt.user.client.rpc.AsyncCallback; |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | 0 | public class CourseProposalController extends MenuEditableSectionController implements RequiresAuthorization, WorkflowEnhancedNavController, HasRequirements { |
120 | |
|
121 | |
|
122 | 0 | protected CreditCourseProposalRpcServiceAsync cluProposalRpcServiceAsync = GWT.create(CreditCourseProposalRpcService.class); |
123 | 0 | protected CourseRpcServiceAsync courseServiceAsync = GWT.create(CourseRpcService.class); |
124 | |
|
125 | 0 | protected final DataModel cluProposalModel = new DataModel("Proposal"); |
126 | 0 | protected final DataModel comparisonModel = new DataModel("Original Course"); |
127 | |
|
128 | |
protected CourseProposalConfigurer cfg; |
129 | |
|
130 | |
private WorkQueue modelRequestQueue; |
131 | |
|
132 | |
protected WorkflowUtilities workflowUtil; |
133 | |
|
134 | 0 | private boolean initialized = false; |
135 | 0 | protected boolean isNew = false; |
136 | |
|
137 | |
private static final String UPDATED_KEY = "metaInfo/updateTime"; |
138 | |
private static final String VERSION_KEY = "versionInfo/versionedFromId"; |
139 | |
private static final String MSG_GROUP = "course"; |
140 | |
|
141 | 0 | protected String currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_CREATE; |
142 | 0 | protected String proposalPath = ""; |
143 | |
protected String currentTitle; |
144 | |
|
145 | 0 | private final DateFormat df = DateFormat.getInstance(); |
146 | |
|
147 | 0 | private final BlockingTask initializingTask = new BlockingTask("Loading"); |
148 | 0 | protected final BlockingTask loadDataTask = new BlockingTask("Retrieving Data"); |
149 | 0 | private final BlockingTask saving = new BlockingTask("Saving"); |
150 | |
|
151 | |
protected CourseRequirementsDataModel reqDataModel; |
152 | |
protected CourseRequirementsDataModel reqDataModelComp; |
153 | |
|
154 | |
public CourseProposalController(){ |
155 | 0 | super(); |
156 | 0 | initializeController(); |
157 | 0 | } |
158 | |
|
159 | |
protected void initializeController() { |
160 | 0 | cfg = GWT.create(CourseProposalConfigurer.class); |
161 | 0 | proposalPath = cfg.getProposalPath(); |
162 | 0 | workflowUtil = new WorkflowUtilities(CourseProposalController.this, proposalPath, "Proposal Actions", |
163 | |
CourseProposalConfigurer.CourseSections.WF_APPROVE_DIALOG,"", cfg.getModelId()); |
164 | 0 | cfg.setState(DtoConstants.STATE_DRAFT); |
165 | |
|
166 | |
|
167 | 0 | workflowUtil.getAdditionalItems().add(new KSMenuItemData(this.getMessage("cluCopyItem"), new ClickHandler(){ |
168 | |
@Override |
169 | |
public void onClick(ClickEvent event) { |
170 | 0 | if(getViewContext() != null && getViewContext().getId() != null && !getViewContext().getId().isEmpty()){ |
171 | 0 | getViewContext().setId((String)cluProposalModel.get(cfg.getProposalPath()+"/id")); |
172 | 0 | getViewContext().setIdType(IdType.COPY_OF_KS_KEW_OBJECT_ID); |
173 | 0 | getViewContext().getAttributes().remove(StudentIdentityConstants.DOCUMENT_TYPE_NAME); |
174 | 0 | cluProposalModel.resetRoot(); |
175 | |
} |
176 | 0 | HistoryManager.navigate("/HOME/CURRICULUM_HOME/COURSE_PROPOSAL", getViewContext()); |
177 | 0 | } |
178 | |
})); |
179 | |
|
180 | 0 | super.setDefaultModelId(cfg.getModelId()); |
181 | 0 | registerModelsAndHandlers(); |
182 | |
|
183 | 0 | addStyleName("courseProposal"); |
184 | 0 | } |
185 | |
|
186 | |
protected void registerModelsAndHandlers(){ |
187 | 0 | reqDataModel = new CourseRequirementsDataModel(this); |
188 | 0 | reqDataModelComp = new CourseRequirementsDataModel(this); |
189 | |
|
190 | 0 | super.registerModel(super.getDefaultModelId(), new ModelProvider<DataModel>() { |
191 | |
|
192 | |
@Override |
193 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
194 | 0 | if (modelRequestQueue == null){ |
195 | 0 | modelRequestQueue = new WorkQueue(); |
196 | |
} |
197 | |
|
198 | 0 | WorkItem workItem = new WorkItem(){ |
199 | |
@Override |
200 | |
public void exec(Callback<Boolean> workCompleteCallback) { |
201 | 0 | if (cluProposalModel.getRoot() == null || initialized == false){ |
202 | 0 | populateModel(callback, workCompleteCallback); |
203 | |
} else { |
204 | 0 | callback.onModelReady(cluProposalModel); |
205 | 0 | workCompleteCallback.exec(true); |
206 | |
} |
207 | 0 | } |
208 | |
}; |
209 | 0 | modelRequestQueue.submit(workItem); |
210 | |
|
211 | 0 | } |
212 | |
|
213 | |
}); |
214 | 0 | super.registerModel("ComparisonModel", new ModelProvider<DataModel>() { |
215 | |
@Override |
216 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
217 | 0 | if(comparisonModel.getRoot() != null && comparisonModel.getRoot().size() != 0){ |
218 | 0 | callback.onModelReady(comparisonModel); |
219 | |
|
220 | |
} |
221 | |
else{ |
222 | 0 | callback.onModelReady(null); |
223 | |
} |
224 | |
|
225 | 0 | } |
226 | |
}); |
227 | 0 | super.addApplicationEventHandler(ContentDirtyEvent.TYPE, new ContentDirtyEventHandler(){ |
228 | |
public void onContentDirty(ContentDirtyEvent event) { |
229 | 0 | setContentWarning("You have unsaved changes"); |
230 | 0 | } |
231 | |
}); |
232 | |
|
233 | 0 | super.addApplicationEventHandler(SaveActionEvent.TYPE, new SaveActionHandler(){ |
234 | |
public void doSave(SaveActionEvent saveAction) { |
235 | 0 | GWT.log("CluProposalController received save action request.", null); |
236 | 0 | doSaveAction(saveAction); |
237 | 0 | } |
238 | |
}); |
239 | 0 | } |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
private void populateModel(final ModelRequestCallback<DataModel> callback, Callback<Boolean> workCompleteCallback){ |
248 | 0 | if(getViewContext().getIdType() == IdType.DOCUMENT_ID){ |
249 | 0 | getCluProposalFromWorkflowId(callback, workCompleteCallback); |
250 | 0 | } else if (getViewContext().getIdType() == IdType.KS_KEW_OBJECT_ID || getViewContext().getIdType() == IdType.OBJECT_ID){ |
251 | 0 | getCluProposalFromProposalId(getViewContext().getId(), callback, workCompleteCallback); |
252 | 0 | } else if (getViewContext().getIdType() == IdType.COPY_OF_OBJECT_ID){ |
253 | 0 | if(LUConstants.PROPOSAL_TYPE_COURSE_MODIFY.equals(getViewContext().getAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME))|| |
254 | |
LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN.equals(getViewContext().getAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME))){ |
255 | 0 | createModifyCluProposalModel("versionComment", callback, workCompleteCallback); |
256 | |
}else{ |
257 | 0 | createCopyCourseModel(getViewContext().getId(), callback, workCompleteCallback); |
258 | |
} |
259 | 0 | } else if (getViewContext().getIdType() == IdType.COPY_OF_KS_KEW_OBJECT_ID){ |
260 | 0 | createCopyCourseProposalModel(getViewContext().getId(), callback, workCompleteCallback); |
261 | |
} else{ |
262 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
263 | |
} |
264 | 0 | } |
265 | |
|
266 | |
protected void getCurrentModel(final ModelRequestCallback<DataModel> callback, Callback<Boolean> workCompleteCallback){ |
267 | 0 | if (cluProposalModel.getRoot() != null && cluProposalModel.getRoot().size() > 0){ |
268 | 0 | String id = cluProposalModel.get(cfg.getProposalPath()+"/id"); |
269 | 0 | if(id != null){ |
270 | 0 | getCluProposalFromProposalId(id, callback, workCompleteCallback); |
271 | |
} |
272 | |
else{ |
273 | 0 | populateModel(callback, workCompleteCallback); |
274 | |
} |
275 | 0 | } |
276 | |
else{ |
277 | 0 | populateModel(callback, workCompleteCallback); |
278 | |
} |
279 | 0 | } |
280 | |
|
281 | |
private void intializeView(final Callback<Boolean> onReadyCallback) { |
282 | 0 | if (initialized) { |
283 | 0 | onReadyCallback.exec(true); |
284 | |
} else { |
285 | 0 | initialized = true; |
286 | 0 | KSBlockingProgressIndicator.addTask(initializingTask); |
287 | 0 | setContentWarning(""); |
288 | 0 | this.requestModel(new ModelRequestCallback<DataModel>(){ |
289 | |
|
290 | |
@Override |
291 | |
public void onModelReady(DataModel model) { |
292 | |
|
293 | |
|
294 | 0 | String idType = null; |
295 | 0 | String viewContextId = ""; |
296 | 0 | if(getViewContext().getIdType() != null){ |
297 | 0 | idType = getViewContext().getIdType().toString(); |
298 | 0 | viewContextId = getViewContext().getId(); |
299 | 0 | if(getViewContext().getIdType()==IdAttributes.IdType.COPY_OF_OBJECT_ID){ |
300 | 0 | viewContextId = null; |
301 | |
} |
302 | |
|
303 | |
} |
304 | |
|
305 | |
|
306 | 0 | if(cluProposalModel.get(VERSION_KEY) != null && !((String)cluProposalModel.get(VERSION_KEY)).equals("") && !LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN.equals(currentDocType)){ |
307 | 0 | currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_MODIFY; |
308 | |
} |
309 | |
|
310 | 0 | if(LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN.equals(cluProposalModel.get(cfg.getProposalPath()+"/type"))){ |
311 | 0 | currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN; |
312 | |
} |
313 | |
|
314 | |
|
315 | 0 | String dtoState = getStateforSaveAction(cluProposalModel); |
316 | |
|
317 | |
|
318 | 0 | String workflowNode = cluProposalModel.get(cfg.getProposalPath()+"/workflowNode"); |
319 | |
|
320 | |
|
321 | 0 | HashMap<String, String> idAttributes = new HashMap<String, String>(); |
322 | 0 | if(idType != null){ |
323 | 0 | idAttributes.put(IdAttributes.ID_TYPE, idType); |
324 | |
} |
325 | 0 | idAttributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, currentDocType); |
326 | 0 | idAttributes.put(DtoConstants.DTO_STATE, dtoState); |
327 | 0 | idAttributes.put(DtoConstants.DTO_NEXT_STATE, cfg.getNextState()); |
328 | 0 | if (LUConstants.PROPOSAL_TYPE_COURSE_MODIFY.equalsIgnoreCase(currentDocType) || |
329 | |
LUConstants.PROPOSAL_TYPE_COURSE_CREATE.equals(currentDocType)){ |
330 | 0 | idAttributes.put(DtoConstants.DTO_WORKFLOW_NODE, workflowNode); |
331 | |
} |
332 | |
|
333 | |
|
334 | |
|
335 | 0 | getCourseProposalRpcService().getMetadata(viewContextId, idAttributes, new KSAsyncCallback<Metadata>(){ |
336 | |
@Override |
337 | |
public void handleTimeout(Throwable caught) { |
338 | 0 | initializeFailed(); |
339 | 0 | } |
340 | |
|
341 | |
@Override |
342 | |
public void handleFailure(Throwable caught) { |
343 | 0 | initializeFailed(); |
344 | 0 | throw new RuntimeException("Failed to get model definition.", caught); |
345 | |
} |
346 | |
|
347 | |
public void initializeFailed(){ |
348 | 0 | initialized = false; |
349 | 0 | onReadyCallback.exec(false); |
350 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
351 | 0 | } |
352 | |
|
353 | |
public void onSuccess(Metadata result) { |
354 | 0 | DataModelDefinition def = new DataModelDefinition(result); |
355 | 0 | cluProposalModel.setDefinition(def); |
356 | 0 | comparisonModel.setDefinition(def); |
357 | |
|
358 | 0 | configureScreens(def, onReadyCallback); |
359 | |
|
360 | 0 | } |
361 | |
}); |
362 | |
|
363 | 0 | } |
364 | |
|
365 | |
@Override |
366 | |
public void onRequestFail(Throwable cause) { |
367 | 0 | GWT.log("Failed to get modeld for proposal controller init"); |
368 | 0 | onReadyCallback.exec(false); |
369 | 0 | } |
370 | |
}); |
371 | |
|
372 | |
} |
373 | 0 | } |
374 | |
|
375 | |
@Override |
376 | |
public void getMetadataForFinalState(final KSAsyncCallback<Metadata> callback){ |
377 | |
|
378 | 0 | String idType = null; |
379 | 0 | String viewContextId = ""; |
380 | 0 | if(getViewContext().getIdType() != null){ |
381 | 0 | idType = getViewContext().getIdType().toString(); |
382 | 0 | viewContextId = getViewContext().getId(); |
383 | 0 | if(getViewContext().getIdType()==IdAttributes.IdType.COPY_OF_OBJECT_ID){ |
384 | 0 | viewContextId = null; |
385 | |
} |
386 | |
} |
387 | 0 | HashMap<String, String> idAttributes = new HashMap<String, String>(); |
388 | 0 | if(idType != null){ |
389 | 0 | idAttributes.put(IdAttributes.ID_TYPE, idType); |
390 | |
} |
391 | |
|
392 | 0 | idAttributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, currentDocType); |
393 | 0 | idAttributes.put(DtoConstants.DTO_STATE, cfg.getState()); |
394 | 0 | idAttributes.put(DtoConstants.DTO_NEXT_STATE, cfg.getNextState()); |
395 | 0 | idAttributes.put(DtoConstants.DTO_WORKFLOW_NODE, "Publication Review"); |
396 | |
|
397 | |
|
398 | 0 | getCourseProposalRpcService().getMetadata(viewContextId, idAttributes, new KSAsyncCallback<Metadata>(){ |
399 | |
@Override |
400 | |
public void onSuccess(Metadata result) { |
401 | 0 | callback.onSuccess(result); |
402 | 0 | } |
403 | |
}); |
404 | 0 | } |
405 | |
|
406 | |
protected void configureScreens(final DataModelDefinition modelDefinition, final Callback<Boolean> onReadyCallback){ |
407 | 0 | if (workflowUtil != null){ |
408 | 0 | workflowUtil.requestAndSetupModel(NO_OP_CALLBACK); |
409 | |
} |
410 | |
|
411 | 0 | CourseRequirementsDataModel.getStatementTypes(new Callback<List<StatementTypeInfo>>() { |
412 | |
|
413 | |
@Override |
414 | |
public void exec(List<StatementTypeInfo> stmtTypes) { |
415 | 0 | List<StatementTypeInfo> stmtTypesOut = new ArrayList<StatementTypeInfo>(); |
416 | 0 | if (stmtTypes != null) { |
417 | 0 | for (StatementTypeInfo stmtType : stmtTypes) { |
418 | 0 | if (stmtType.getId().contains("kuali.statement.type.course.enrollmentEligibility") || |
419 | |
stmtType.getId().contains("kuali.statement.type.course.creditConstraints")) { |
420 | 0 | continue; |
421 | |
} |
422 | 0 | stmtTypesOut.add(stmtType); |
423 | |
} |
424 | |
} |
425 | |
|
426 | 0 | cfg.setStatementTypes(stmtTypesOut); |
427 | 0 | cfg.setModelDefinition(modelDefinition); |
428 | 0 | cfg.configure(CourseProposalController.this); |
429 | |
|
430 | |
|
431 | 0 | if(workflowUtil!=null){ |
432 | 0 | requestModel(new ModelRequestCallback<DataModel>(){ |
433 | |
public void onModelReady(DataModel model) { |
434 | |
|
435 | 0 | String versionedFromId = model.get("versionInfo/versionedFromId"); |
436 | 0 | if(versionedFromId!=null && !versionedFromId.isEmpty()){ |
437 | 0 | KSLabel descLabel = new KSLabel(); |
438 | 0 | descLabel.setText(Application.getApplicationContext().getUILabel("course", LUUIConstants.FINAL_APPROVAL_DIALOG)); |
439 | 0 | if (workflowUtil.getApproveDialogue() != null) { |
440 | 0 | workflowUtil.getApproveDialogue().addWidget(descLabel); |
441 | |
} |
442 | 0 | workflowUtil.addApproveDialogField("", "startTerm", cfg.generateMessageInfo(LUUIConstants.PROPOSAL_START_TERM), modelDefinition, true, true); |
443 | 0 | workflowUtil.addApproveDialogField("proposal", "prevEndTerm", cfg.generateMessageInfo(LUUIConstants.PROPOSAL_PREV_END_TERM), modelDefinition, false); |
444 | |
|
445 | 0 | workflowUtil.updateApproveFields(); |
446 | 0 | workflowUtil.progressiveEnableFields(); |
447 | 0 | }else{ |
448 | |
|
449 | 0 | workflowUtil.addIgnoreDialogField("proposal/prevEndTerm"); |
450 | |
} |
451 | 0 | } |
452 | |
public void onRequestFail(Throwable cause) { |
453 | 0 | } |
454 | |
}); |
455 | |
} |
456 | |
|
457 | 0 | progressiveEnableFields(); |
458 | |
|
459 | 0 | onReadyCallback.exec(true); |
460 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
461 | 0 | } |
462 | |
}); |
463 | 0 | } |
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
protected void progressiveEnableFields(){ |
471 | 0 | final FieldDescriptor endTerm = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.END_TERM); |
472 | 0 | final FieldDescriptor pilotCourse = Application.getApplicationContext().getPathToFieldMapping(null,CreditCourseConstants.PILOT_COURSE); |
473 | |
|
474 | 0 | if (pilotCourse != null && endTerm != null){ |
475 | |
|
476 | 0 | Boolean enableEndTerm = Boolean.TRUE.equals(cluProposalModel.get(CreditCourseConstants.PILOT_COURSE)) |
477 | |
|| DtoConstants.STATE_RETIRED.equalsIgnoreCase((String)cluProposalModel.get(CreditCourseConstants.STATE)); |
478 | |
|
479 | 0 | BaseSection.progressiveEnableAndRequireFields(enableEndTerm, endTerm); |
480 | |
|
481 | |
|
482 | 0 | KSCheckBox pilotCheckbox = ((KSCheckBox)pilotCourse.getFieldWidget()); |
483 | 0 | pilotCheckbox.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
484 | |
@Override |
485 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
486 | |
|
487 | 0 | BaseSection.progressiveEnableAndRequireFields(event.getValue(), endTerm); |
488 | |
|
489 | |
|
490 | 0 | if (!event.getValue()){ |
491 | 0 | ((KSDropDown)((KSPicker)endTerm.getFieldWidget()).getInputWidget()).clear(); |
492 | |
} |
493 | 0 | } |
494 | |
}); |
495 | |
} |
496 | 0 | } |
497 | |
|
498 | |
@Override |
499 | |
@SuppressWarnings("unchecked") |
500 | |
public void requestModel(Class modelType, final ModelRequestCallback callback) { |
501 | 0 | if(modelType == ReferenceModel.class){ |
502 | 0 | if (cluProposalModel != null){ |
503 | 0 | ReferenceModel ref = new ReferenceModel(); |
504 | |
|
505 | 0 | if(cluProposalModel.get(cfg.getProposalPath()) != null){ |
506 | 0 | ref.setReferenceId((String)cluProposalModel.get(cfg.getProposalPath()+"/id")); |
507 | |
} else { |
508 | 0 | ref.setReferenceId(null); |
509 | |
} |
510 | |
|
511 | |
|
512 | 0 | if(cluProposalModel.get(cfg.getProposalPath()) != null){ |
513 | 0 | Map<String, String> attributes = new HashMap<String, String>(); |
514 | 0 | attributes.put("name", (String)cluProposalModel.get(cfg.getProposalPath()+"/name")); |
515 | 0 | ref.setReferenceAttributes(attributes); |
516 | 0 | } else { |
517 | 0 | ref.setReferenceAttributes(null); |
518 | |
} |
519 | |
|
520 | 0 | ref.setReferenceTypeKey(cfg.getProposalReferenceTypeKey()); |
521 | 0 | ref.setReferenceType(cfg.getProposalReferenceObjectType()); |
522 | 0 | ref.setReferenceState(getViewContext().getState()); |
523 | |
|
524 | 0 | callback.onModelReady(ref); |
525 | 0 | } |
526 | 0 | } else if (modelType == Data.class){ |
527 | 0 | requestModel(cfg.getModelId(), callback); |
528 | |
} else { |
529 | 0 | super.requestModel(modelType, callback); |
530 | |
} |
531 | |
|
532 | 0 | } |
533 | |
|
534 | |
private void getCluProposalFromWorkflowId(@SuppressWarnings("rawtypes") final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
535 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
536 | 0 | workflowUtil.getDataIdFromWorkflowId(getViewContext().getId(), new KSAsyncCallback<String>(){ |
537 | |
@Override |
538 | |
public void handleFailure(Throwable caught) { |
539 | 0 | Window.alert("Error loading Proposal from Workflow Document: "+caught.getMessage()); |
540 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
541 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
542 | 0 | } |
543 | |
|
544 | |
@Override |
545 | |
public void onSuccess(String proposalId) { |
546 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
547 | 0 | getCluProposalFromProposalId(proposalId, callback, workCompleteCallback); |
548 | 0 | } |
549 | |
}); |
550 | 0 | } |
551 | |
|
552 | |
protected void getCluProposalFromProposalId(String id, @SuppressWarnings("rawtypes") final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
553 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
554 | 0 | getCourseProposalRpcService().getData(id, new KSAsyncCallback<Data>(){ |
555 | |
|
556 | |
@Override |
557 | |
public void handleFailure(Throwable caught) { |
558 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
559 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
560 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
561 | 0 | } |
562 | |
|
563 | |
@Override |
564 | |
public void onSuccess(Data result) { |
565 | 0 | cluProposalModel.setRoot(result); |
566 | 0 | setHeaderTitle(); |
567 | 0 | setLastUpdated(); |
568 | 0 | reqDataModel.retrieveStatementTypes(cluProposalModel.<String>get("id"), new Callback<Boolean>() { |
569 | |
@Override |
570 | |
public void exec(Boolean result) { |
571 | 0 | if(result){ |
572 | 0 | getCourseComparisonModelAndReqs(callback, workCompleteCallback); |
573 | |
} |
574 | 0 | } |
575 | |
}); |
576 | 0 | } |
577 | |
|
578 | |
}); |
579 | 0 | } |
580 | |
|
581 | |
@SuppressWarnings("unchecked") |
582 | |
protected void getCourseComparisonModelAndReqs(final ModelRequestCallback proposalModelRequestCallback, final Callback<Boolean> workCompleteCallback){ |
583 | 0 | if(cluProposalModel.get(VERSION_KEY) != null && !((String)cluProposalModel.get(VERSION_KEY)).equals("")){ |
584 | 0 | courseServiceAsync.getData((String)cluProposalModel.get(VERSION_KEY), new KSAsyncCallback<Data>(){ |
585 | |
|
586 | |
@Override |
587 | |
public void handleFailure(Throwable caught) { |
588 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
589 | 0 | createNewCluProposalModel(proposalModelRequestCallback, workCompleteCallback); |
590 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
591 | 0 | } |
592 | |
|
593 | |
@Override |
594 | |
public void onSuccess(Data result) { |
595 | |
|
596 | 0 | if (result != null) |
597 | 0 | comparisonModel.setRoot(result); |
598 | |
|
599 | 0 | reqDataModel.retrieveStatementTypes(cluProposalModel.<String>get("id"), new Callback<Boolean>() { |
600 | |
@Override |
601 | |
public void exec(Boolean result) { |
602 | 0 | if (result) { |
603 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
604 | 0 | reqDataModelComp.retrieveStatementTypes(comparisonModel.<String>get("id"), new Callback<Boolean>() { |
605 | |
@Override |
606 | |
public void exec(Boolean result) { |
607 | 0 | if (result) { |
608 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
609 | |
} |
610 | 0 | } |
611 | |
}); |
612 | 0 | proposalModelRequestCallback.onModelReady(cluProposalModel); |
613 | 0 | workCompleteCallback.exec(true); |
614 | |
} |
615 | 0 | } |
616 | |
}); |
617 | 0 | } |
618 | |
}); |
619 | |
} else { |
620 | 0 | proposalModelRequestCallback.onModelReady(cluProposalModel); |
621 | 0 | workCompleteCallback.exec(true); |
622 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
623 | |
} |
624 | 0 | } |
625 | |
|
626 | |
@SuppressWarnings("unchecked") |
627 | |
protected void createNewCluProposalModel(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
628 | 0 | Data data = new Data(); |
629 | 0 | cluProposalModel.setRoot(data); |
630 | |
|
631 | 0 | Data proposalData = new Data(); |
632 | 0 | proposalData.set(new Data.StringKey("type"), currentDocType); |
633 | 0 | data.set(new Data.StringKey("proposal"), proposalData); |
634 | 0 | if (cfg.getNextState() == null || cfg.getNextState().isEmpty()){ |
635 | 0 | proposalData.set(new Data.StringKey("workflowNode"), "PreRoute"); |
636 | |
} |
637 | |
|
638 | 0 | isNew = true; |
639 | 0 | setHeaderTitle(); |
640 | 0 | setLastUpdated(); |
641 | 0 | callback.onModelReady(cluProposalModel); |
642 | 0 | workCompleteCallback.exec(true); |
643 | 0 | } |
644 | |
|
645 | |
private void createModifyCluProposalModel(String versionComment, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
646 | 0 | Data data = new Data(); |
647 | 0 | cluProposalModel.setRoot(data); |
648 | |
|
649 | 0 | this.currentDocType = getViewContext().getAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME); |
650 | 0 | Data proposalData = new Data(); |
651 | 0 | proposalData.set(new Data.StringKey("type"), currentDocType); |
652 | 0 | data.set(new Data.StringKey("proposal"), proposalData); |
653 | 0 | if (cfg.getNextState() == null && cfg.getNextState().isEmpty()){ |
654 | 0 | proposalData.set(new Data.StringKey("workflowNode"), "PreRoute"); |
655 | |
} |
656 | |
|
657 | 0 | Data versionData = new Data(); |
658 | 0 | versionData.set(new Data.StringKey("versionIndId"), getViewContext().getId()); |
659 | 0 | versionData.set(new Data.StringKey("versionComment"), versionComment); |
660 | 0 | data.set(new Data.StringKey("versionInfo"), versionData); |
661 | |
|
662 | 0 | cluProposalRpcServiceAsync.saveData(cluProposalModel.getRoot(), new AsyncCallback<DataSaveResult>() { |
663 | |
public void onSuccess(DataSaveResult result) { |
664 | 0 | cluProposalModel.setRoot(result.getValue()); |
665 | 0 | setHeaderTitle(); |
666 | 0 | setLastUpdated(); |
667 | |
|
668 | 0 | ViewContext docContext = new ViewContext(); |
669 | 0 | docContext.setId((String) cluProposalModel.get(cfg.getProposalPath()+"/id")); |
670 | 0 | docContext.setIdType(IdType.KS_KEW_OBJECT_ID); |
671 | |
|
672 | |
|
673 | |
|
674 | 0 | getCourseComparisonModelAndReqs(callback, workCompleteCallback); |
675 | |
|
676 | |
|
677 | |
|
678 | 0 | getViewContext().setIdType(docContext.getIdType()); |
679 | 0 | getViewContext().setId(docContext.getId()); |
680 | |
|
681 | 0 | } |
682 | |
|
683 | |
public void onFailure(Throwable caught) { |
684 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
685 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
686 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
687 | 0 | } |
688 | |
}); |
689 | 0 | } |
690 | |
|
691 | |
@SuppressWarnings("unchecked") |
692 | |
private void createCopyCourseModel(String originalCluId, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
693 | |
|
694 | 0 | cluProposalRpcServiceAsync.createCopyCourse(originalCluId, new AsyncCallback<DataSaveResult>() { |
695 | |
public void onSuccess(DataSaveResult result) { |
696 | 0 | cluProposalModel.setRoot(result.getValue()); |
697 | |
|
698 | |
|
699 | 0 | Data proposalData = new Data(); |
700 | 0 | cluProposalModel.getRoot().set(new Data.StringKey("proposal"), proposalData); |
701 | 0 | if (cfg.getNextState() == null || cfg.getNextState().isEmpty()){ |
702 | 0 | proposalData.set(new Data.StringKey("workflowNode"), "PreRoute"); |
703 | |
} |
704 | |
|
705 | 0 | isNew = true; |
706 | 0 | setHeaderTitle(); |
707 | 0 | setLastUpdated(); |
708 | |
|
709 | 0 | callback.onModelReady(cluProposalModel); |
710 | 0 | workCompleteCallback.exec(true); |
711 | 0 | } |
712 | |
|
713 | |
public void onFailure(Throwable caught) { |
714 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
715 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
716 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
717 | 0 | } |
718 | |
}); |
719 | 0 | } |
720 | |
|
721 | |
@SuppressWarnings("unchecked") |
722 | |
private void createCopyCourseProposalModel(String originalProposalId, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
723 | |
|
724 | 0 | cluProposalRpcServiceAsync.createCopyCourseProposal(originalProposalId, new AsyncCallback<DataSaveResult>() { |
725 | |
public void onSuccess(DataSaveResult result) { |
726 | 0 | cluProposalModel.setRoot(result.getValue()); |
727 | 0 | setHeaderTitle(); |
728 | 0 | setLastUpdated(); |
729 | |
|
730 | 0 | ViewContext docContext = new ViewContext(); |
731 | 0 | docContext.setId((String) cluProposalModel.get(cfg.getProposalPath()+"/id")); |
732 | 0 | docContext.setIdType(IdType.KS_KEW_OBJECT_ID); |
733 | 0 | RecentlyViewedHelper.addDocument(getProposalTitle(), |
734 | |
HistoryManager.appendContext(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), docContext) |
735 | |
+ "/COURSE_INFO"); |
736 | |
|
737 | |
|
738 | |
|
739 | 0 | getViewContext().setIdType(docContext.getIdType()); |
740 | 0 | getViewContext().setId(docContext.getId()); |
741 | |
|
742 | 0 | callback.onModelReady(cluProposalModel); |
743 | 0 | workCompleteCallback.exec(true); |
744 | 0 | } |
745 | |
|
746 | |
public void onFailure(Throwable caught) { |
747 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
748 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
749 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
750 | 0 | } |
751 | |
}); |
752 | 0 | } |
753 | |
|
754 | |
public void doSaveAction(final SaveActionEvent saveActionEvent){ |
755 | 0 | requestModel(new ModelRequestCallback<DataModel>() { |
756 | |
@Override |
757 | |
public void onModelReady(DataModel model) { |
758 | 0 | CourseProposalController.this.updateModelFromCurrentView(); |
759 | |
|
760 | 0 | if (isStartViewShowing()){ |
761 | |
|
762 | |
|
763 | 0 | getStartPopupView().updateModel(); |
764 | |
} |
765 | |
|
766 | 0 | model.validate(new Callback<List<ValidationResultInfo>>() { |
767 | |
@Override |
768 | |
public void exec(List<ValidationResultInfo> result) { |
769 | |
|
770 | 0 | boolean isSectionValid = isValid(result, true); |
771 | |
|
772 | 0 | if(isSectionValid){ |
773 | 0 | if (startSectionRequired()){ |
774 | 0 | showStartPopup(NO_OP_CALLBACK); |
775 | 0 | saveActionEvent.doActionComplete(); |
776 | |
} |
777 | |
else{ |
778 | 0 | saveProposalClu(saveActionEvent); |
779 | |
} |
780 | |
} |
781 | |
else{ |
782 | |
|
783 | 0 | KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); |
784 | |
} |
785 | |
|
786 | 0 | } |
787 | |
}); |
788 | 0 | } |
789 | |
|
790 | |
@Override |
791 | |
public void onRequestFail(Throwable cause) { |
792 | 0 | saveActionEvent.doActionComplete(); |
793 | 0 | GWT.log("Unable to retrieve model for validation and save", cause); |
794 | 0 | } |
795 | |
|
796 | |
}); |
797 | |
|
798 | 0 | } |
799 | |
|
800 | |
public boolean startSectionRequired(){ |
801 | 0 | String proposalId = cluProposalModel.get(cfg.getProposalPath()+"/id"); |
802 | |
|
803 | |
|
804 | |
|
805 | 0 | String proposalTitle = cluProposalModel.get(cfg.getProposalTitlePath()); |
806 | 0 | String courseTitle = cluProposalModel.get(cfg.getCourseTitlePath()); |
807 | 0 | if (proposalTitle == null || proposalTitle.isEmpty()){ |
808 | 0 | cluProposalModel.set(QueryPath.parse(cfg.getProposalTitlePath()), courseTitle); |
809 | |
} |
810 | |
|
811 | 0 | return proposalId==null && !CourseProposalController.this.isStartViewShowing() && !hasTitles(proposalTitle, courseTitle); |
812 | |
} |
813 | |
|
814 | |
private boolean hasTitles(String proposalTitle, String courseTitle){ |
815 | 0 | return (proposalTitle != null && !proposalTitle.isEmpty()) && (courseTitle != null && !courseTitle.isEmpty()); |
816 | |
} |
817 | |
|
818 | |
public void saveProposalClu(final SaveActionEvent saveActionEvent){ |
819 | 0 | KSBlockingProgressIndicator.addTask(saving); |
820 | 0 | getCourseProposalRpcService().saveData(cluProposalModel.getRoot(), new KSAsyncCallback<DataSaveResult>(){ |
821 | |
|
822 | |
@Override |
823 | |
public void handleFailure(Throwable caught) { |
824 | 0 | GWT.log("Save Failed.", caught); |
825 | 0 | KSBlockingProgressIndicator.removeTask(saving); |
826 | 0 | KSNotifier.add(new KSNotification("Save Failed on server. Please try again.", false, true, 5000)); |
827 | 0 | } |
828 | |
|
829 | |
@Override |
830 | |
public void handleVersionMismatch(Throwable caught) { |
831 | 0 | super.handleVersionMismatch(caught); |
832 | 0 | KSBlockingProgressIndicator.removeTask(saving); |
833 | 0 | } |
834 | |
|
835 | |
public void onSuccess(DataSaveResult result) { |
836 | 0 | KSBlockingProgressIndicator.removeTask(saving); |
837 | |
|
838 | 0 | Application.getApplicationContext().clearValidationWarnings(); |
839 | 0 | Application.getApplicationContext().addValidationWarnings(result.getValidationResults()); |
840 | |
|
841 | 0 | if(ValidatorClientUtils.hasErrors(result.getValidationResults())){ |
842 | 0 | isValid(result.getValidationResults(), false, true); |
843 | 0 | saveActionEvent.setGotoNextView(false); |
844 | 0 | saveActionEvent.doActionComplete(); |
845 | 0 | KSNotifier.add(new KSNotification("Save Failed. There were validation errors.", false, true, 5000)); |
846 | |
}else{ |
847 | |
|
848 | 0 | saveActionEvent.setSaveSuccessful(true); |
849 | 0 | cluProposalModel.setRoot(result.getValue()); |
850 | 0 | String title = getProposalTitle(); |
851 | 0 | View currentView = getCurrentView(); |
852 | 0 | if (currentView instanceof SectionView){ |
853 | 0 | ((SectionView)currentView).updateView(cluProposalModel); |
854 | 0 | ((SectionView) currentView).resetDirtyFlags(); |
855 | |
} |
856 | 0 | saveActionEvent.doActionComplete(); |
857 | |
|
858 | 0 | ViewContext context = CourseProposalController.this.getViewContext(); |
859 | 0 | context.setId((String)cluProposalModel.get(proposalPath+"/id")); |
860 | 0 | context.setIdType(IdType.KS_KEW_OBJECT_ID); |
861 | |
|
862 | |
|
863 | 0 | if(workflowUtil != null){ |
864 | 0 | workflowUtil.refresh(); |
865 | |
} |
866 | |
|
867 | 0 | setHeaderTitle(); |
868 | 0 | setLastUpdated(); |
869 | 0 | HistoryManager.logHistoryChange(); |
870 | 0 | if(isNew){ |
871 | 0 | RecentlyViewedHelper.addDocument(getProposalTitle(), |
872 | |
HistoryManager.appendContext(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), context) |
873 | |
+ "/SUMMARY"); |
874 | |
} |
875 | 0 | else if(!currentTitle.equals(title)){ |
876 | 0 | RecentlyViewedHelper.updateTitle(currentTitle, title, (String)cluProposalModel.get(proposalPath+"/id")); |
877 | |
} |
878 | 0 | isNew = false; |
879 | |
|
880 | 0 | if(saveActionEvent.gotoNextView()){ |
881 | 0 | CourseProposalController.this.showNextViewOnMenu(); |
882 | |
} |
883 | |
|
884 | 0 | if (ValidatorClientUtils.hasWarnings(result.getValidationResults())){ |
885 | 0 | if (!saveActionEvent.gotoNextView()){ |
886 | |
|
887 | 0 | isValid(result.getValidationResults(), false, true); |
888 | |
} |
889 | 0 | KSNotifier.show("Saved with Warnings"); |
890 | |
} else { |
891 | 0 | KSNotifier.show("Save Successful"); |
892 | |
} |
893 | |
} |
894 | 0 | } |
895 | |
}); |
896 | |
|
897 | 0 | } |
898 | |
|
899 | |
public void setLastUpdated(){ |
900 | 0 | Date lastUpdated = (Date)cluProposalModel.get(UPDATED_KEY); |
901 | 0 | if(lastUpdated != null){ |
902 | 0 | setContentInfo("Last Updated: " + df.format(lastUpdated)); |
903 | |
} |
904 | |
else{ |
905 | 0 | setContentInfo(""); |
906 | |
} |
907 | 0 | } |
908 | |
|
909 | |
@Override |
910 | |
public void beforeShow(final Callback<Boolean> onReadyCallback){ |
911 | 0 | Application.getApplicationContext().clearCrossConstraintMap(null); |
912 | 0 | Application.getApplicationContext().clearPathToFieldMapping(null); |
913 | 0 | Application.getApplicationContext().clearValidationWarnings(); |
914 | 0 | Application.getApplicationContext().setParentPath(""); |
915 | |
|
916 | 0 | intializeView(onReadyCallback); |
917 | 0 | } |
918 | |
|
919 | |
|
920 | |
|
921 | |
|
922 | |
@Override |
923 | |
public <V extends Enum<?>> void showView(final V viewType, final Callback<Boolean> onReadyCallback) { |
924 | 0 | Callback<Boolean> finalizeView = new Callback<Boolean>(){ |
925 | |
|
926 | |
public void exec(Boolean result) { |
927 | |
|
928 | |
|
929 | 0 | for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){ |
930 | 0 | crossConstraint.reprocessWithUpdatedConstraints(); |
931 | |
} |
932 | |
|
933 | |
|
934 | |
|
935 | 0 | if (viewType == CourseSections.SUMMARY){ |
936 | |
|
937 | 0 | KSBlockingProgressIndicator.addTask(initializingTask); |
938 | |
|
939 | 0 | courseServiceAsync.validate(cluProposalModel.getRoot(), new KSAsyncCallback<List<ValidationResultInfo>>(){ |
940 | |
|
941 | |
@Override |
942 | |
public void onSuccess(List<ValidationResultInfo> result) { |
943 | |
|
944 | 0 | Application.getApplicationContext().clearValidationWarnings(); |
945 | 0 | Application.getApplicationContext().addValidationWarnings(result); |
946 | |
|
947 | 0 | showWarnings(); |
948 | |
|
949 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
950 | 0 | } |
951 | |
}); |
952 | |
} else { |
953 | |
|
954 | 0 | showWarnings(); |
955 | |
} |
956 | |
|
957 | 0 | onReadyCallback.exec(result); |
958 | 0 | } |
959 | |
}; |
960 | |
|
961 | 0 | super.showView(viewType, finalizeView); |
962 | 0 | } |
963 | |
|
964 | |
|
965 | |
@Override |
966 | |
public void showDefaultView(Callback<Boolean> onReadyCallback) { |
967 | 0 | if(isNew){ |
968 | 0 | super.showFirstView(onReadyCallback); |
969 | |
} |
970 | |
else{ |
971 | 0 | super.showDefaultView(onReadyCallback); |
972 | |
} |
973 | 0 | } |
974 | |
|
975 | |
@Override |
976 | |
public void setParentController(Controller controller) { |
977 | 0 | super.setParentController(controller); |
978 | 0 | } |
979 | |
|
980 | |
@Override |
981 | |
|
982 | |
|
983 | |
|
984 | |
|
985 | |
|
986 | |
public void checkAuthorization(final PermissionType permissionType, final AuthorizationCallback authCallback) { |
987 | 0 | GWT.log("Attempting Auth Check.", null); |
988 | |
|
989 | |
|
990 | 0 | Map<String,String> attributes = new HashMap<String,String>(); |
991 | 0 | addPermissionAttributes(attributes); |
992 | |
|
993 | |
|
994 | |
|
995 | |
|
996 | 0 | cluProposalRpcServiceAsync.isAuthorized(permissionType, attributes, new KSAsyncCallback<Boolean>(){ |
997 | |
|
998 | |
@Override |
999 | |
public void handleFailure(Throwable caught) { |
1000 | 0 | authCallback.isNotAuthorized("Error checking authorization."); |
1001 | 0 | GWT.log("Error checking proposal authorization.", caught); |
1002 | 0 | Window.alert("Error Checking Proposal Authorization: "+caught.getMessage()); |
1003 | 0 | } |
1004 | |
|
1005 | |
@Override |
1006 | |
public void onSuccess(Boolean result) { |
1007 | 0 | GWT.log("Succeeded checking auth for permission type '" + permissionType + "' with result: " + result, null); |
1008 | 0 | if (Boolean.TRUE.equals(result)) { |
1009 | 0 | authCallback.isAuthorized(); |
1010 | |
} |
1011 | |
else { |
1012 | 0 | authCallback.isNotAuthorized("User is not authorized: " + permissionType); |
1013 | |
} |
1014 | 0 | } |
1015 | |
}); |
1016 | 0 | } |
1017 | |
|
1018 | |
|
1019 | |
|
1020 | |
|
1021 | |
public void addPermissionAttributes(Map<String, String> attributes){ |
1022 | 0 | ViewContext viewContext = getViewContext(); |
1023 | |
|
1024 | |
|
1025 | |
|
1026 | 0 | if ( (viewContext.getId() != null) && (!"".equals(viewContext.getId())) ) { |
1027 | 0 | attributes.put(viewContext.getIdType().toString(), viewContext.getId()); |
1028 | |
} |
1029 | |
|
1030 | |
|
1031 | 0 | if(viewContext.getId() != null && !viewContext.getId().isEmpty()){ |
1032 | 0 | if(viewContext.getIdType() != IdType.COPY_OF_OBJECT_ID && viewContext.getIdType() != IdType.COPY_OF_KS_KEW_OBJECT_ID){ |
1033 | |
|
1034 | 0 | viewContext.setPermissionType(PermissionType.OPEN); |
1035 | 0 | attributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_COURSE_CREATE); |
1036 | |
} else{ |
1037 | |
|
1038 | 0 | viewContext.setPermissionType(PermissionType.INITIATE); |
1039 | 0 | attributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_COURSE_MODIFY); |
1040 | |
} |
1041 | |
} else{ |
1042 | |
|
1043 | 0 | viewContext.setPermissionType(PermissionType.INITIATE); |
1044 | 0 | attributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_COURSE_CREATE); |
1045 | |
} |
1046 | 0 | } |
1047 | |
|
1048 | |
@Override |
1049 | |
public boolean isAuthorizationRequired() { |
1050 | 0 | return true; |
1051 | |
} |
1052 | |
|
1053 | |
@Override |
1054 | |
public void setAuthorizationRequired(boolean required) { |
1055 | 0 | throw new UnsupportedOperationException(); |
1056 | |
} |
1057 | |
|
1058 | |
protected void setHeaderTitle(){ |
1059 | |
String title; |
1060 | 0 | if (cluProposalModel.get(cfg.getProposalTitlePath()) != null){ |
1061 | 0 | title = getProposalTitle(); |
1062 | |
} |
1063 | |
else{ |
1064 | 0 | title = "New Course (Proposal)"; |
1065 | |
} |
1066 | 0 | this.setContentTitle(title); |
1067 | 0 | this.setName(title); |
1068 | 0 | WindowTitleUtils.setContextTitle(title); |
1069 | 0 | currentTitle = title; |
1070 | 0 | } |
1071 | |
|
1072 | |
@Override |
1073 | |
public WorkflowUtilities getWfUtilities() { |
1074 | 0 | return workflowUtil; |
1075 | |
} |
1076 | |
|
1077 | |
@Override |
1078 | |
public void beforeViewChange(final Enum<?> viewChangingTo, final Callback<Boolean> okToChange) { |
1079 | |
|
1080 | 0 | final Callback<Boolean> reallyOkToChange = new Callback<Boolean>(){ |
1081 | |
@Override |
1082 | |
public void exec(Boolean result) { |
1083 | 0 | if(result){ |
1084 | 0 | if(CourseSections.GOVERNANCE.equals(viewChangingTo)){ |
1085 | 0 | getView(CourseSections.COURSE_INFO, new Callback<View>(){ |
1086 | |
@Override |
1087 | |
public void exec(final View view) { |
1088 | 0 | if(view!=null && view instanceof SectionView){ |
1089 | 0 | requestModel(new ModelRequestCallback<DataModel>(){ |
1090 | |
public void onModelReady(DataModel model) { |
1091 | 0 | ((SectionView)view).updateWidgetData(model); |
1092 | 0 | okToChange.exec(true); |
1093 | 0 | } |
1094 | |
public void onRequestFail(Throwable cause) { |
1095 | 0 | okToChange.exec(false); |
1096 | 0 | } |
1097 | |
}); |
1098 | |
}else{ |
1099 | 0 | okToChange.exec(true); |
1100 | |
} |
1101 | 0 | }}); |
1102 | |
} else |
1103 | 0 | okToChange.exec(true); |
1104 | |
} else |
1105 | 0 | okToChange.exec(false); |
1106 | 0 | } |
1107 | |
}; |
1108 | |
|
1109 | |
|
1110 | |
|
1111 | |
|
1112 | |
|
1113 | 0 | super.beforeViewChange(viewChangingTo, new Callback<Boolean>(){ |
1114 | |
|
1115 | |
@Override |
1116 | |
public void exec(Boolean result) { |
1117 | 0 | if(result){ |
1118 | 0 | if(getCurrentView() instanceof SectionView && ((SectionView)getCurrentView()).isDirty()){ |
1119 | 0 | ButtonGroup<YesNoCancelEnum> buttonGroup = new YesNoCancelGroup(); |
1120 | 0 | final ButtonMessageDialog<YesNoCancelEnum> dialog = new ButtonMessageDialog<YesNoCancelEnum>("Warning", "You may have unsaved changes. Save changes?", buttonGroup); |
1121 | 0 | buttonGroup.addCallback(new Callback<YesNoCancelEnum>(){ |
1122 | |
|
1123 | |
@Override |
1124 | |
public void exec(YesNoCancelEnum result) { |
1125 | 0 | switch(result){ |
1126 | |
case YES: |
1127 | 0 | dialog.hide(); |
1128 | 0 | final SaveActionEvent e = new SaveActionEvent(); |
1129 | 0 | e.setActionCompleteCallback(new ActionCompleteCallback(){ |
1130 | |
|
1131 | |
@Override |
1132 | |
public void onActionComplete(ActionEvent action) { |
1133 | 0 | if(e.isSaveSuccessful()){ |
1134 | 0 | reallyOkToChange.exec(true); |
1135 | |
} |
1136 | |
else{ |
1137 | 0 | reallyOkToChange.exec(false); |
1138 | |
} |
1139 | 0 | } |
1140 | |
|
1141 | |
}); |
1142 | 0 | fireApplicationEvent(e); |
1143 | 0 | break; |
1144 | |
case NO: |
1145 | |
|
1146 | 0 | getCurrentModel(new ModelRequestCallback<DataModel>(){ |
1147 | |
|
1148 | |
@Override |
1149 | |
public void onModelReady(DataModel model) { |
1150 | 0 | if (getCurrentView()instanceof Section){ |
1151 | 0 | ((Section) getCurrentView()).resetFieldInteractionFlags(); |
1152 | |
} |
1153 | 0 | reallyOkToChange.exec(true); |
1154 | 0 | dialog.hide(); |
1155 | 0 | } |
1156 | |
|
1157 | |
@Override |
1158 | |
public void onRequestFail(Throwable cause) { |
1159 | |
|
1160 | |
|
1161 | 0 | reallyOkToChange.exec(false); |
1162 | 0 | dialog.hide(); |
1163 | 0 | GWT.log("Unable to retrieve model for data restore on view change with no save", cause); |
1164 | 0 | }}, |
1165 | |
NO_OP_CALLBACK); |
1166 | |
|
1167 | 0 | break; |
1168 | |
case CANCEL: |
1169 | 0 | reallyOkToChange.exec(false); |
1170 | 0 | dialog.hide(); |
1171 | |
|
1172 | 0 | HistoryManager.logHistoryChange(); |
1173 | |
break; |
1174 | |
} |
1175 | 0 | } |
1176 | |
}); |
1177 | 0 | dialog.addCloseLinkClickHandler(new ClickHandler() { |
1178 | |
|
1179 | |
@Override |
1180 | |
public void onClick(ClickEvent event) { |
1181 | 0 | okToChange.exec(false); |
1182 | 0 | dialog.hide(); |
1183 | |
|
1184 | 0 | HistoryManager.logHistoryChange(); |
1185 | 0 | } |
1186 | |
}); |
1187 | 0 | dialog.show(); |
1188 | 0 | } |
1189 | |
else{ |
1190 | 0 | reallyOkToChange.exec(true); |
1191 | |
} |
1192 | |
} |
1193 | |
else{ |
1194 | 0 | reallyOkToChange.exec(false); |
1195 | |
} |
1196 | 0 | } |
1197 | |
}); |
1198 | 0 | } |
1199 | |
|
1200 | |
public KSButton getSaveButton(){ |
1201 | 0 | if(currentDocType != LUConstants.PROPOSAL_TYPE_COURSE_MODIFY && currentDocType != LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN){ |
1202 | 0 | return new KSButton("Save and Continue", new ClickHandler(){ |
1203 | |
public void onClick(ClickEvent event) { |
1204 | 0 | CourseProposalController.this.fireApplicationEvent(new SaveActionEvent(true)); |
1205 | 0 | } |
1206 | |
}); |
1207 | |
} |
1208 | |
else{ |
1209 | 0 | return new KSButton("Save", new ClickHandler(){ |
1210 | |
public void onClick(ClickEvent event) { |
1211 | 0 | CourseProposalController.this.fireApplicationEvent(new SaveActionEvent(false)); |
1212 | 0 | } |
1213 | |
}); |
1214 | |
} |
1215 | |
} |
1216 | |
|
1217 | |
public KSButton getCancelButton(final Enum<?> summaryView){ |
1218 | |
|
1219 | 0 | return new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ |
1220 | |
public void onClick(ClickEvent event) { |
1221 | 0 | if(!isNew){ |
1222 | 0 | CourseProposalController.this.showView(summaryView); |
1223 | |
} |
1224 | |
else{ |
1225 | 0 | Application.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation()); |
1226 | |
} |
1227 | 0 | } |
1228 | |
}); |
1229 | |
|
1230 | |
} |
1231 | |
|
1232 | |
@Override |
1233 | |
public void onHistoryEvent(String historyStack) { |
1234 | 0 | super.onHistoryEvent(historyStack); |
1235 | |
|
1236 | |
|
1237 | 0 | if(cluProposalModel.get(cfg.getProposalTitlePath()) != null && |
1238 | |
this.getViewContext().getIdType() != IdType.COPY_OF_OBJECT_ID){ |
1239 | 0 | RecentlyViewedHelper.addCurrentDocument(getProposalTitle()); |
1240 | |
} |
1241 | 0 | } |
1242 | |
|
1243 | |
private String getProposalTitle(){ |
1244 | 0 | StringBuffer sb = new StringBuffer(); |
1245 | 0 | sb.append(cluProposalModel.get(cfg.getProposalTitlePath())); |
1246 | 0 | sb.append(" (Proposal)"); |
1247 | 0 | return sb.toString(); |
1248 | |
} |
1249 | |
|
1250 | |
public String getCourseId(){ |
1251 | 0 | return cluProposalModel.<String>get("id"); |
1252 | |
} |
1253 | |
|
1254 | |
public String getCourseState(){ |
1255 | 0 | return cluProposalModel.<String>get("state"); |
1256 | |
} |
1257 | |
|
1258 | |
public boolean isNew() { |
1259 | 0 | return isNew; |
1260 | |
} |
1261 | |
|
1262 | |
public CourseRequirementsDataModel getReqDataModel() { |
1263 | 0 | return reqDataModel; |
1264 | |
} |
1265 | |
|
1266 | |
public CourseRequirementsDataModel getReqDataModelComp() { |
1267 | 0 | return reqDataModelComp; |
1268 | |
} |
1269 | |
|
1270 | |
@Override |
1271 | |
public DataModel getExportDataModel() { |
1272 | 0 | return cluProposalModel; |
1273 | |
} |
1274 | |
|
1275 | |
|
1276 | |
|
1277 | |
|
1278 | |
|
1279 | |
@Override |
1280 | |
public String getExportTemplateName() { |
1281 | 0 | if (LUConstants.PROPOSAL_TYPE_COURSE_CREATE.equals(currentDocType)){ |
1282 | 0 | return "base.template"; |
1283 | |
} |
1284 | 0 | return "proposal.template"; |
1285 | |
} |
1286 | |
|
1287 | |
@Override |
1288 | |
public List<ExportElement> getExportElementsFromView() { |
1289 | 0 | List<ExportElement> exportElements = new ArrayList<ExportElement>(); |
1290 | 0 | if (this.getCurrentViewEnum().equals(CourseSections.SUMMARY)) { |
1291 | 0 | SummaryTableSection tableSection = this.cfg.getSummaryConfigurer().getTableSection(); |
1292 | 0 | ExportElement heading = new ExportElement(); |
1293 | 0 | heading.setFieldLabel(""); |
1294 | 0 | heading.setFieldValue(cluProposalModel.getModelName()); |
1295 | 0 | heading.setFieldValue2(comparisonModel.getModelName()); |
1296 | 0 | exportElements.add(heading); |
1297 | 0 | exportElements.addAll(ExportUtils.getDetailsForWidget(tableSection.getSummaryTable())); |
1298 | |
} |
1299 | 0 | return exportElements; |
1300 | |
} |
1301 | |
|
1302 | |
@Override |
1303 | |
public boolean isExportButtonActive() { |
1304 | 0 | if (this.getCurrentViewEnum() != null && this.getCurrentViewEnum().equals(CourseSections.SUMMARY)) { |
1305 | 0 | return true; |
1306 | |
} else { |
1307 | 0 | return false; |
1308 | |
} |
1309 | |
|
1310 | |
} |
1311 | |
|
1312 | |
|
1313 | |
|
1314 | |
|
1315 | |
|
1316 | |
|
1317 | |
protected String getStateforSaveAction(DataModel model){ |
1318 | |
|
1319 | 0 | String state = (String)model.get(CreditCourseConstants.STATE); |
1320 | |
|
1321 | |
|
1322 | |
|
1323 | 0 | if (state == null){ |
1324 | 0 | state = cfg.getState(); |
1325 | |
} |
1326 | |
|
1327 | 0 | return state; |
1328 | |
} |
1329 | |
|
1330 | |
public String getMessage(String courseMessageKey) { |
1331 | 0 | String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey); |
1332 | 0 | if (msg == null) { |
1333 | 0 | msg = courseMessageKey; |
1334 | |
} |
1335 | 0 | return msg; |
1336 | |
} |
1337 | |
|
1338 | |
|
1339 | |
|
1340 | |
|
1341 | |
|
1342 | |
|
1343 | |
|
1344 | |
|
1345 | |
|
1346 | |
|
1347 | |
protected BaseDataOrchestrationRpcServiceAsync getCourseProposalRpcService(){ |
1348 | 0 | return cluProposalRpcServiceAsync; |
1349 | |
} |
1350 | |
|
1351 | |
public CourseProposalConfigurer getCourseProposalConfigurer() { |
1352 | 0 | return cfg; |
1353 | |
} |
1354 | |
} |