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