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