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