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.rice.StudentIdentityConstants; |
29 | |
import org.kuali.student.common.rice.authorization.PermissionType; |
30 | |
import org.kuali.student.common.ui.client.application.Application; |
31 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
32 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
33 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.MenuEditableSectionController; |
34 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
35 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; |
36 | |
import org.kuali.student.common.ui.client.event.ActionEvent; |
37 | |
import org.kuali.student.common.ui.client.event.ContentDirtyEvent; |
38 | |
import org.kuali.student.common.ui.client.event.ContentDirtyEventHandler; |
39 | |
import org.kuali.student.common.ui.client.event.SaveActionEvent; |
40 | |
import org.kuali.student.common.ui.client.event.SaveActionHandler; |
41 | |
import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback; |
42 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
43 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
44 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
45 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
46 | |
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
47 | |
import org.kuali.student.common.ui.client.mvc.ModelProvider; |
48 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
49 | |
import org.kuali.student.common.ui.client.mvc.View; |
50 | |
import org.kuali.student.common.ui.client.mvc.WorkQueue; |
51 | |
import org.kuali.student.common.ui.client.mvc.WorkQueue.WorkItem; |
52 | |
import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel; |
53 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
54 | |
import org.kuali.student.common.ui.client.security.AuthorizationCallback; |
55 | |
import org.kuali.student.common.ui.client.security.RequiresAuthorization; |
56 | |
import org.kuali.student.common.ui.client.service.DataSaveResult; |
57 | |
import org.kuali.student.common.ui.client.util.WindowTitleUtils; |
58 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
59 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
60 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.YesNoCancelEnum; |
61 | |
import org.kuali.student.common.ui.client.widgets.dialog.ButtonMessageDialog; |
62 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup; |
63 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.YesNoCancelGroup; |
64 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
65 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
66 | |
import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; |
67 | |
import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; |
68 | |
import org.kuali.student.common.ui.shared.IdAttributes; |
69 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
70 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
71 | |
import org.kuali.student.core.statement.dto.StatementTypeInfo; |
72 | |
import org.kuali.student.core.workflow.ui.client.widgets.WorkflowEnhancedNavController; |
73 | |
import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities; |
74 | |
import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper; |
75 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
76 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseConfigurer; |
77 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel; |
78 | |
import org.kuali.student.lum.lu.ui.course.client.requirements.HasRequirements; |
79 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService; |
80 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync; |
81 | |
import org.kuali.student.lum.lu.ui.course.client.service.CreditCourseProposalRpcService; |
82 | |
import org.kuali.student.lum.lu.ui.course.client.service.CreditCourseProposalRpcServiceAsync; |
83 | |
|
84 | |
import com.google.gwt.core.client.GWT; |
85 | |
import com.google.gwt.event.dom.client.ClickEvent; |
86 | |
import com.google.gwt.event.dom.client.ClickHandler; |
87 | |
import com.google.gwt.user.client.Window; |
88 | |
import com.google.gwt.user.client.rpc.AsyncCallback; |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 0 | public class CourseProposalController extends MenuEditableSectionController implements RequiresAuthorization, WorkflowEnhancedNavController, HasRequirements { |
101 | |
|
102 | |
|
103 | 0 | CreditCourseProposalRpcServiceAsync cluProposalRpcServiceAsync = GWT.create(CreditCourseProposalRpcService.class); |
104 | 0 | CourseRpcServiceAsync courseServiceAsync = GWT.create(CourseRpcService.class); |
105 | |
|
106 | 0 | private final DataModel cluProposalModel = new DataModel("Proposal"); |
107 | 0 | private final DataModel comparisonModel = new DataModel("Original Course"); |
108 | |
|
109 | 0 | CourseConfigurer cfg = GWT.create(CourseConfigurer.class); |
110 | |
|
111 | |
private WorkQueue modelRequestQueue; |
112 | |
|
113 | |
private WorkflowUtilities workflowUtil; |
114 | |
|
115 | 0 | private boolean initialized = false; |
116 | 0 | private boolean isNew = false; |
117 | |
|
118 | |
private static final String UPDATED_KEY = "metaInfo/updateTime"; |
119 | |
private static final String VERSION_KEY = "versionInfo/versionedFromId"; |
120 | |
private static final String MODIFY_TYPE = "kuali.proposal.type.course.modify"; |
121 | |
public static final String CREATE_TYPE = "kuali.proposal.type.course.create"; |
122 | |
public static final String INITIAL_SAVE_VERSION = "1"; |
123 | 0 | private String currentDocType = CREATE_TYPE; |
124 | 0 | private String proposalPath = ""; |
125 | |
private String currentTitle; |
126 | |
|
127 | 0 | private final DateFormat df = DateFormat.getInstance(); |
128 | |
|
129 | 0 | private final BlockingTask initializingTask = new BlockingTask("Loading"); |
130 | 0 | private final BlockingTask loadDataTask = new BlockingTask("Retrieving Data"); |
131 | 0 | private final BlockingTask saving = new BlockingTask("Saving"); |
132 | |
final CourseRequirementsDataModel reqDataModel; |
133 | |
|
134 | |
public CourseProposalController(){ |
135 | 0 | super(); |
136 | 0 | reqDataModel = new CourseRequirementsDataModel(this); |
137 | 0 | initialize(); |
138 | 0 | addStyleName("courseProposal"); |
139 | 0 | } |
140 | |
|
141 | |
@Override |
142 | |
public void setViewContext(ViewContext viewContext) { |
143 | 0 | super.setViewContext(viewContext); |
144 | 0 | if(viewContext.getId() != null && !viewContext.getId().isEmpty()){ |
145 | 0 | if(viewContext.getIdType() != IdType.COPY_OF_OBJECT_ID){ |
146 | 0 | viewContext.setPermissionType(PermissionType.OPEN); |
147 | |
} |
148 | |
else{ |
149 | |
|
150 | 0 | viewContext.setPermissionType(PermissionType.INITIATE); |
151 | |
} |
152 | |
} |
153 | |
else{ |
154 | 0 | viewContext.setPermissionType(PermissionType.INITIATE); |
155 | |
} |
156 | 0 | } |
157 | |
|
158 | |
private void initialize() { |
159 | |
|
160 | 0 | proposalPath = cfg.getProposalPath(); |
161 | 0 | workflowUtil = new WorkflowUtilities(CourseProposalController.this ,proposalPath); |
162 | |
|
163 | 0 | super.setDefaultModelId(cfg.getModelId()); |
164 | 0 | super.registerModel(cfg.getModelId(), new ModelProvider<DataModel>() { |
165 | |
|
166 | |
@Override |
167 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
168 | 0 | if (modelRequestQueue == null){ |
169 | 0 | modelRequestQueue = new WorkQueue(); |
170 | |
} |
171 | |
|
172 | 0 | WorkItem workItem = new WorkItem(){ |
173 | |
@Override |
174 | |
public void exec(Callback<Boolean> workCompleteCallback) { |
175 | 0 | if (cluProposalModel.getRoot() == null || initialized == false){ |
176 | 0 | initModel(callback, workCompleteCallback); |
177 | |
} else { |
178 | 0 | callback.onModelReady(cluProposalModel); |
179 | 0 | workCompleteCallback.exec(true); |
180 | |
} |
181 | 0 | } |
182 | |
}; |
183 | 0 | modelRequestQueue.submit(workItem); |
184 | |
|
185 | 0 | } |
186 | |
|
187 | |
}); |
188 | 0 | super.registerModel("ComparisonModel", new ModelProvider<DataModel>() { |
189 | |
@Override |
190 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
191 | 0 | if(comparisonModel.getRoot() != null && comparisonModel.getRoot().size() != 0){ |
192 | 0 | callback.onModelReady(comparisonModel); |
193 | |
|
194 | |
} |
195 | |
else{ |
196 | 0 | callback.onModelReady(null); |
197 | |
} |
198 | |
|
199 | 0 | } |
200 | |
}); |
201 | 0 | super.addApplicationEventHandler(ContentDirtyEvent.TYPE, new ContentDirtyEventHandler(){ |
202 | |
public void onContentDirty(ContentDirtyEvent event) { |
203 | 0 | setContentWarning("You have unsaved changes"); |
204 | 0 | } |
205 | |
}); |
206 | |
|
207 | 0 | addApplicationEventHandler(SaveActionEvent.TYPE, new SaveActionHandler(){ |
208 | |
public void doSave(SaveActionEvent saveAction) { |
209 | 0 | GWT.log("CluProposalController received save action request.", null); |
210 | 0 | doSaveAction(saveAction); |
211 | 0 | } |
212 | |
}); |
213 | |
|
214 | 0 | } |
215 | |
|
216 | |
private void initModel(final ModelRequestCallback<DataModel> callback, Callback<Boolean> workCompleteCallback){ |
217 | 0 | if(getViewContext().getIdType() == IdType.DOCUMENT_ID){ |
218 | 0 | getCluProposalFromWorkflowId(callback, workCompleteCallback); |
219 | 0 | } else if (getViewContext().getIdType() == IdType.KS_KEW_OBJECT_ID){ |
220 | 0 | getCluProposalFromProposalId(getViewContext().getId(), callback, workCompleteCallback); |
221 | 0 | } else if (getViewContext().getIdType() == IdType.COPY_OF_OBJECT_ID){ |
222 | 0 | createModifyCluProposalModel("versionComment", callback, workCompleteCallback); |
223 | |
} else{ |
224 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
225 | |
} |
226 | 0 | } |
227 | |
|
228 | |
private void getCurrentModel(final ModelRequestCallback<DataModel> callback, Callback<Boolean> workCompleteCallback){ |
229 | 0 | if (cluProposalModel.getRoot() != null && cluProposalModel.getRoot().size() > 0){ |
230 | 0 | String id = cluProposalModel.get(cfg.getProposalPath()+"/id"); |
231 | 0 | if(id != null){ |
232 | 0 | getCluProposalFromProposalId(id, callback, workCompleteCallback); |
233 | |
} |
234 | |
else{ |
235 | 0 | initModel(callback, workCompleteCallback); |
236 | |
} |
237 | 0 | } |
238 | |
else{ |
239 | 0 | initModel(callback, workCompleteCallback); |
240 | |
} |
241 | 0 | } |
242 | |
|
243 | |
private void init(final Callback<Boolean> onReadyCallback) { |
244 | 0 | if (initialized) { |
245 | 0 | onReadyCallback.exec(true); |
246 | |
} else { |
247 | 0 | initialized = true; |
248 | 0 | KSBlockingProgressIndicator.addTask(initializingTask); |
249 | 0 | setContentWarning(""); |
250 | 0 | this.requestModel(new ModelRequestCallback<DataModel>(){ |
251 | |
|
252 | |
@Override |
253 | |
public void onModelReady(DataModel model) { |
254 | |
|
255 | 0 | String idType = null; |
256 | 0 | String viewContextId = ""; |
257 | 0 | if(getViewContext().getIdType() != null){ |
258 | 0 | idType = getViewContext().getIdType().toString(); |
259 | 0 | viewContextId = getViewContext().getId(); |
260 | 0 | if(getViewContext().getIdType()==IdAttributes.IdType.COPY_OF_OBJECT_ID){ |
261 | 0 | viewContextId = null; |
262 | |
} |
263 | |
|
264 | |
} |
265 | 0 | HashMap<String, String> idAttributes = new HashMap<String, String>(); |
266 | 0 | if(idType != null){ |
267 | 0 | idAttributes.put(IdAttributes.ID_TYPE, idType); |
268 | |
} |
269 | 0 | if(cluProposalModel.get(VERSION_KEY) != null && !((String)cluProposalModel.get(VERSION_KEY)).equals("")){ |
270 | 0 | currentDocType = MODIFY_TYPE; |
271 | |
} |
272 | 0 | idAttributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, currentDocType); |
273 | |
|
274 | |
|
275 | 0 | cluProposalRpcServiceAsync.getMetadata(viewContextId, idAttributes, new KSAsyncCallback<Metadata>(){ |
276 | |
@Override |
277 | |
public void handleTimeout(Throwable caught) { |
278 | 0 | initializeFailed(); |
279 | 0 | } |
280 | |
|
281 | |
@Override |
282 | |
public void handleFailure(Throwable caught) { |
283 | 0 | initializeFailed(); |
284 | 0 | throw new RuntimeException("Failed to get model definition.", caught); |
285 | |
} |
286 | |
|
287 | |
public void initializeFailed(){ |
288 | 0 | initialized = false; |
289 | 0 | onReadyCallback.exec(false); |
290 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
291 | 0 | } |
292 | |
|
293 | |
public void onSuccess(Metadata result) { |
294 | 0 | DataModelDefinition def = new DataModelDefinition(result); |
295 | 0 | cluProposalModel.setDefinition(def); |
296 | 0 | comparisonModel.setDefinition(def); |
297 | |
|
298 | 0 | configureScreens(def, onReadyCallback); |
299 | |
|
300 | 0 | } |
301 | |
}); |
302 | |
|
303 | 0 | } |
304 | |
|
305 | |
@Override |
306 | |
public void onRequestFail(Throwable cause) { |
307 | 0 | GWT.log("Failed to get modeld for proposal controller init"); |
308 | 0 | onReadyCallback.exec(false); |
309 | 0 | } |
310 | |
}); |
311 | |
|
312 | |
} |
313 | 0 | } |
314 | |
|
315 | |
private void configureScreens(final DataModelDefinition modelDefinition, final Callback<Boolean> onReadyCallback){ |
316 | 0 | workflowUtil.requestAndSetupModel(); |
317 | |
|
318 | 0 | CourseRequirementsDataModel.getStatementTypes(new Callback<List<StatementTypeInfo>>() { |
319 | |
|
320 | |
@Override |
321 | |
public void exec(List<StatementTypeInfo> stmtTypes) { |
322 | 0 | List<StatementTypeInfo> stmtTypesOut = new ArrayList<StatementTypeInfo>(); |
323 | 0 | if (stmtTypes != null) { |
324 | 0 | for (StatementTypeInfo stmtType : stmtTypes) { |
325 | 0 | if (stmtType.getId().contains("kuali.statement.type.course.enrollmentEligibility") || |
326 | |
stmtType.getId().contains("kuali.statement.type.course.creditConstraints")) { |
327 | 0 | continue; |
328 | |
} |
329 | 0 | stmtTypesOut.add(stmtType); |
330 | |
} |
331 | |
} |
332 | |
|
333 | 0 | cfg.setStatementTypes(stmtTypesOut); |
334 | 0 | cfg.setModelDefinition(modelDefinition); |
335 | 0 | cfg.configure(CourseProposalController.this); |
336 | |
|
337 | |
|
338 | 0 | for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){ |
339 | 0 | crossConstraint.reprocessWithUpdatedConstraints(); |
340 | |
} |
341 | |
|
342 | 0 | onReadyCallback.exec(true); |
343 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
344 | 0 | } |
345 | |
}); |
346 | 0 | } |
347 | |
|
348 | |
@Override |
349 | |
@SuppressWarnings("unchecked") |
350 | |
public void requestModel(Class modelType, final ModelRequestCallback callback) { |
351 | 0 | if(modelType == ReferenceModel.class){ |
352 | 0 | if (cluProposalModel != null){ |
353 | 0 | ReferenceModel ref = new ReferenceModel(); |
354 | |
|
355 | 0 | if(cluProposalModel.get(cfg.getProposalPath()) != null){ |
356 | 0 | ref.setReferenceId((String)cluProposalModel.get(cfg.getProposalPath()+"/id")); |
357 | |
} else { |
358 | 0 | ref.setReferenceId(null); |
359 | |
} |
360 | |
|
361 | |
|
362 | 0 | if(cluProposalModel.get(cfg.getProposalPath()) != null){ |
363 | 0 | Map<String, String> attributes = new HashMap<String, String>(); |
364 | 0 | attributes.put("name", (String)cluProposalModel.get(cfg.getProposalPath()+"/name")); |
365 | 0 | ref.setReferenceAttributes(attributes); |
366 | 0 | } else { |
367 | 0 | ref.setReferenceAttributes(null); |
368 | |
} |
369 | |
|
370 | 0 | ref.setReferenceTypeKey(cfg.getProposalReferenceTypeKey()); |
371 | 0 | ref.setReferenceType(cfg.getProposalReferenceObjectType()); |
372 | 0 | ref.setReferenceState(getViewContext().getState()); |
373 | |
|
374 | 0 | callback.onModelReady(ref); |
375 | 0 | } |
376 | 0 | } else if (modelType == Data.class){ |
377 | 0 | requestModel(cfg.getModelId(), callback); |
378 | |
} else { |
379 | 0 | super.requestModel(modelType, callback); |
380 | |
} |
381 | |
|
382 | 0 | } |
383 | |
|
384 | |
@SuppressWarnings("unchecked") |
385 | |
private void getCluProposalFromWorkflowId(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
386 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
387 | 0 | workflowUtil.getDataIdFromWorkflowId(getViewContext().getId(), new KSAsyncCallback<String>(){ |
388 | |
@Override |
389 | |
public void handleFailure(Throwable caught) { |
390 | 0 | Window.alert("Error loading Proposal from Workflow Document: "+caught.getMessage()); |
391 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
392 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
393 | 0 | } |
394 | |
|
395 | |
@Override |
396 | |
public void onSuccess(String proposalId) { |
397 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
398 | 0 | getCluProposalFromProposalId(proposalId, callback, workCompleteCallback); |
399 | 0 | } |
400 | |
}); |
401 | 0 | } |
402 | |
|
403 | |
@SuppressWarnings("unchecked") |
404 | |
private void getCluProposalFromProposalId(String id, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
405 | 0 | KSBlockingProgressIndicator.addTask(loadDataTask); |
406 | 0 | cluProposalRpcServiceAsync.getData(id, new KSAsyncCallback<Data>(){ |
407 | |
|
408 | |
@Override |
409 | |
public void handleFailure(Throwable caught) { |
410 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
411 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
412 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
413 | 0 | } |
414 | |
|
415 | |
@Override |
416 | |
public void onSuccess(Data result) { |
417 | 0 | cluProposalModel.setRoot(result); |
418 | 0 | setProposalHeaderTitle(); |
419 | 0 | setLastUpdated(); |
420 | 0 | reqDataModel.retrieveStatementTypes(cluProposalModel.<String>get("id"), new Callback<Boolean>() { |
421 | |
@Override |
422 | |
public void exec(Boolean result) { |
423 | 0 | if(result){ |
424 | 0 | getCourseComparisonModel(callback, workCompleteCallback); |
425 | |
} |
426 | 0 | } |
427 | |
}); |
428 | 0 | } |
429 | |
|
430 | |
}); |
431 | 0 | } |
432 | |
|
433 | |
@SuppressWarnings("unchecked") |
434 | |
private void getCourseComparisonModel(final ModelRequestCallback proposalModelRequestCallback, final Callback<Boolean> workCompleteCallback){ |
435 | 0 | if(cluProposalModel.get(VERSION_KEY) != null && !((String)cluProposalModel.get(VERSION_KEY)).equals("")){ |
436 | 0 | courseServiceAsync.getData((String)cluProposalModel.get(VERSION_KEY), new KSAsyncCallback<Data>(){ |
437 | |
|
438 | |
@Override |
439 | |
public void handleFailure(Throwable caught) { |
440 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
441 | 0 | createNewCluProposalModel(proposalModelRequestCallback, workCompleteCallback); |
442 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
443 | 0 | } |
444 | |
|
445 | |
@Override |
446 | |
public void onSuccess(Data result) { |
447 | 0 | if (result != null) { |
448 | 0 | comparisonModel.setRoot(result); |
449 | |
} |
450 | 0 | proposalModelRequestCallback.onModelReady(cluProposalModel); |
451 | 0 | workCompleteCallback.exec(true); |
452 | 0 | reqDataModel.retrieveStatementTypes(cluProposalModel.<String>get("id"), new Callback<Boolean>() { |
453 | |
@Override |
454 | |
public void exec(Boolean result) { |
455 | 0 | if (result) { |
456 | |
|
457 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
458 | |
} |
459 | 0 | } |
460 | |
}); |
461 | |
|
462 | 0 | } |
463 | |
}); |
464 | |
} else { |
465 | 0 | proposalModelRequestCallback.onModelReady(cluProposalModel); |
466 | 0 | workCompleteCallback.exec(true); |
467 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
468 | |
} |
469 | 0 | } |
470 | |
|
471 | |
@SuppressWarnings("unchecked") |
472 | |
private void createNewCluProposalModel(final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
473 | 0 | cluProposalModel.setRoot(new Data()); |
474 | 0 | isNew = true; |
475 | 0 | setProposalHeaderTitle(); |
476 | 0 | setLastUpdated(); |
477 | 0 | callback.onModelReady(cluProposalModel); |
478 | 0 | workCompleteCallback.exec(true); |
479 | 0 | } |
480 | |
|
481 | |
@SuppressWarnings("unchecked") |
482 | |
private void createModifyCluProposalModel(String versionComment, final ModelRequestCallback callback, final Callback<Boolean> workCompleteCallback){ |
483 | 0 | Data data = new Data(); |
484 | |
|
485 | 0 | Data proposalData = new Data(); |
486 | 0 | proposalData.set(new Data.StringKey("type"), MODIFY_TYPE); |
487 | 0 | data.set(new Data.StringKey("proposal"), proposalData); |
488 | |
|
489 | 0 | Data versionData = new Data(); |
490 | 0 | versionData.set(new Data.StringKey("versionIndId"), getViewContext().getId()); |
491 | 0 | versionData.set(new Data.StringKey("versionComment"), versionComment); |
492 | 0 | data.set(new Data.StringKey("versionInfo"), versionData); |
493 | |
|
494 | 0 | cluProposalModel.setRoot(data); |
495 | 0 | cluProposalRpcServiceAsync.saveData(cluProposalModel.getRoot(), new AsyncCallback<DataSaveResult>() { |
496 | |
public void onSuccess(DataSaveResult result) { |
497 | 0 | cluProposalModel.setRoot(result.getValue()); |
498 | 0 | setProposalHeaderTitle(); |
499 | 0 | setLastUpdated(); |
500 | |
|
501 | 0 | ViewContext docContext = new ViewContext(); |
502 | 0 | docContext.setId((String) cluProposalModel.get(cfg.getProposalPath()+"/id")); |
503 | 0 | docContext.setIdType(IdType.KS_KEW_OBJECT_ID); |
504 | 0 | RecentlyViewedHelper.addDocument(getProposalTitle(), |
505 | |
HistoryManager.appendContext(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), docContext) |
506 | |
+ "/SUMMARY"); |
507 | 0 | getCourseComparisonModel(callback, workCompleteCallback); |
508 | |
|
509 | |
|
510 | |
|
511 | 0 | getViewContext().setIdType(docContext.getIdType()); |
512 | 0 | getViewContext().setId(docContext.getId()); |
513 | |
|
514 | 0 | } |
515 | |
|
516 | |
public void onFailure(Throwable caught) { |
517 | 0 | Window.alert("Error loading Proposal: "+caught.getMessage()); |
518 | 0 | createNewCluProposalModel(callback, workCompleteCallback); |
519 | 0 | KSBlockingProgressIndicator.removeTask(loadDataTask); |
520 | 0 | } |
521 | |
}); |
522 | 0 | } |
523 | |
|
524 | |
public void doSaveAction(final SaveActionEvent saveActionEvent){ |
525 | 0 | requestModel(new ModelRequestCallback<DataModel>() { |
526 | |
@Override |
527 | |
public void onModelReady(DataModel model) { |
528 | 0 | CourseProposalController.this.updateModelFromCurrentView(); |
529 | |
|
530 | 0 | if (isStartViewShowing()){ |
531 | |
|
532 | |
|
533 | 0 | getStartPopupView().updateModel(); |
534 | |
} |
535 | |
|
536 | 0 | model.validate(new Callback<List<ValidationResultInfo>>() { |
537 | |
@Override |
538 | |
public void exec(List<ValidationResultInfo> result) { |
539 | |
|
540 | 0 | boolean isSectionValid = isValid(result, true); |
541 | |
|
542 | 0 | if(isSectionValid){ |
543 | 0 | if (startSectionRequired()){ |
544 | 0 | showStartPopup(NO_OP_CALLBACK); |
545 | 0 | saveActionEvent.doActionComplete(); |
546 | |
} |
547 | |
else{ |
548 | 0 | saveProposalClu(saveActionEvent); |
549 | |
} |
550 | |
} |
551 | |
else{ |
552 | |
|
553 | 0 | KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); |
554 | |
} |
555 | |
|
556 | 0 | } |
557 | |
}); |
558 | 0 | } |
559 | |
|
560 | |
@Override |
561 | |
public void onRequestFail(Throwable cause) { |
562 | 0 | saveActionEvent.doActionComplete(); |
563 | 0 | GWT.log("Unable to retrieve model for validation and save", cause); |
564 | 0 | } |
565 | |
|
566 | |
}); |
567 | |
|
568 | 0 | } |
569 | |
|
570 | |
public boolean startSectionRequired(){ |
571 | 0 | String proposalId = cluProposalModel.get(cfg.getProposalPath()+"/id"); |
572 | |
|
573 | |
|
574 | |
|
575 | 0 | String proposalTitle = cluProposalModel.get(cfg.getProposalTitlePath()); |
576 | 0 | String courseTitle = cluProposalModel.get(cfg.getCourseTitlePath()); |
577 | 0 | if (proposalTitle == null || proposalTitle.isEmpty()){ |
578 | 0 | cluProposalModel.set(QueryPath.parse(cfg.getProposalTitlePath()), courseTitle); |
579 | |
} |
580 | |
|
581 | 0 | return proposalId==null && !CourseProposalController.this.isStartViewShowing() && !hasTitles(proposalTitle, courseTitle); |
582 | |
} |
583 | |
|
584 | |
private boolean hasTitles(String proposalTitle, String courseTitle){ |
585 | 0 | return (proposalTitle != null && !proposalTitle.isEmpty()) && (courseTitle != null && !courseTitle.isEmpty()); |
586 | |
} |
587 | |
|
588 | |
public void saveProposalClu(final SaveActionEvent saveActionEvent){ |
589 | 0 | KSBlockingProgressIndicator.addTask(saving); |
590 | 0 | final Callback<Throwable> saveFailedCallback = new Callback<Throwable>() { |
591 | |
|
592 | |
@Override |
593 | |
public void exec(Throwable caught) { |
594 | 0 | GWT.log("Save Failed.", caught); |
595 | 0 | KSBlockingProgressIndicator.removeTask(saving); |
596 | 0 | KSNotifier.add(new KSNotification("Save Failed on server. Please try again.", false, true, 5000)); |
597 | 0 | } |
598 | |
|
599 | |
}; |
600 | |
try { |
601 | 0 | cluProposalRpcServiceAsync.saveData(cluProposalModel.getRoot(), new KSAsyncCallback<DataSaveResult>(){ |
602 | |
@Override |
603 | |
public void handleFailure(Throwable caught) { |
604 | 0 | saveFailedCallback.exec(caught); |
605 | 0 | } |
606 | |
|
607 | |
public void onSuccess(DataSaveResult result) { |
608 | 0 | KSBlockingProgressIndicator.removeTask(saving); |
609 | |
|
610 | 0 | if(result.getValidationResults()!=null && !result.getValidationResults().isEmpty()){ |
611 | 0 | isValid(result.getValidationResults(), false, true); |
612 | 0 | saveActionEvent.setGotoNextView(false); |
613 | 0 | saveActionEvent.doActionComplete(); |
614 | 0 | KSNotifier.add(new KSNotification("Save Failed. There were validation errors.", false, 5000)); |
615 | |
}else{ |
616 | |
|
617 | 0 | saveActionEvent.setSaveSuccessful(true); |
618 | 0 | cluProposalModel.setRoot(result.getValue()); |
619 | 0 | String title = getProposalTitle(); |
620 | |
|
621 | 0 | View currentView = getCurrentView(); |
622 | 0 | if (currentView instanceof SectionView){ |
623 | 0 | ((SectionView)currentView).updateView(cluProposalModel); |
624 | 0 | ((SectionView) currentView).resetDirtyFlags(); |
625 | |
} |
626 | 0 | saveActionEvent.doActionComplete(); |
627 | |
|
628 | 0 | ViewContext context = CourseProposalController.this.getViewContext(); |
629 | 0 | context.setId((String)cluProposalModel.get(proposalPath+"/id")); |
630 | 0 | context.setIdType(IdType.KS_KEW_OBJECT_ID); |
631 | |
|
632 | |
|
633 | |
|
634 | 0 | String proposalVersion = cluProposalModel.get(proposalPath+"/metaInfo/versionInd"); |
635 | 0 | if (INITIAL_SAVE_VERSION.equals(proposalVersion)){ |
636 | 0 | workflowUtil.refresh(); |
637 | |
} |
638 | |
|
639 | 0 | setProposalHeaderTitle(); |
640 | 0 | setLastUpdated(); |
641 | 0 | HistoryManager.logHistoryChange(); |
642 | 0 | if(isNew){ |
643 | 0 | RecentlyViewedHelper.addCurrentDocument(title); |
644 | |
} |
645 | 0 | else if(!currentTitle.equals(title)){ |
646 | 0 | RecentlyViewedHelper.updateTitle(currentTitle, title, (String)cluProposalModel.get(proposalPath+"/id")); |
647 | |
} |
648 | 0 | isNew = false; |
649 | |
|
650 | 0 | if(saveActionEvent.gotoNextView()){ |
651 | 0 | CourseProposalController.this.showNextViewOnMenu(); |
652 | |
} |
653 | 0 | KSNotifier.add(new KSNotification("Save Successful", false, 4000)); |
654 | |
} |
655 | 0 | } |
656 | |
}); |
657 | 0 | } catch (Exception e) { |
658 | 0 | saveFailedCallback.exec(e); |
659 | 0 | } |
660 | |
|
661 | 0 | } |
662 | |
|
663 | |
public void setLastUpdated(){ |
664 | 0 | Date lastUpdated = (Date)cluProposalModel.get(UPDATED_KEY); |
665 | 0 | if(lastUpdated != null){ |
666 | 0 | setContentInfo("Last Updated: " + df.format(lastUpdated)); |
667 | |
} |
668 | |
else{ |
669 | 0 | setContentInfo(""); |
670 | |
} |
671 | 0 | } |
672 | |
|
673 | |
@Override |
674 | |
public void beforeShow(final Callback<Boolean> onReadyCallback){ |
675 | 0 | Application.getApplicationContext().clearCrossConstraintMap(null); |
676 | 0 | Application.getApplicationContext().clearPathToFieldMapping(null); |
677 | 0 | Application.getApplicationContext().setParentPath(""); |
678 | |
|
679 | 0 | init(onReadyCallback); |
680 | 0 | } |
681 | |
|
682 | |
@Override |
683 | |
public void showDefaultView(Callback<Boolean> onReadyCallback) { |
684 | 0 | if(isNew){ |
685 | 0 | super.showFirstView(onReadyCallback); |
686 | |
} |
687 | |
else{ |
688 | 0 | super.showDefaultView(onReadyCallback); |
689 | |
} |
690 | 0 | } |
691 | |
|
692 | |
@Override |
693 | |
public void setParentController(Controller controller) { |
694 | 0 | super.setParentController(controller); |
695 | 0 | } |
696 | |
|
697 | |
@Override |
698 | |
public void checkAuthorization(final PermissionType permissionType, final AuthorizationCallback authCallback) { |
699 | 0 | Map<String,String> attributes = new HashMap<String,String>(); |
700 | |
|
701 | 0 | GWT.log("Attempting Auth Check.", null); |
702 | 0 | if ( (getViewContext().getId() != null) && (!"".equals(getViewContext().getId())) ) { |
703 | 0 | attributes.put(getViewContext().getIdType().toString(), getViewContext().getId()); |
704 | |
} |
705 | |
|
706 | 0 | cluProposalRpcServiceAsync.isAuthorized(permissionType, attributes, new KSAsyncCallback<Boolean>(){ |
707 | |
|
708 | |
@Override |
709 | |
public void handleFailure(Throwable caught) { |
710 | 0 | authCallback.isNotAuthorized("Error checking authorization."); |
711 | 0 | GWT.log("Error checking proposal authorization.", caught); |
712 | 0 | Window.alert("Error Checking Proposal Authorization: "+caught.getMessage()); |
713 | 0 | } |
714 | |
|
715 | |
@Override |
716 | |
public void onSuccess(Boolean result) { |
717 | 0 | GWT.log("Succeeded checking auth for permission type '" + permissionType + "' with result: " + result, null); |
718 | 0 | if (Boolean.TRUE.equals(result)) { |
719 | 0 | authCallback.isAuthorized(); |
720 | |
} |
721 | |
else { |
722 | 0 | authCallback.isNotAuthorized("User is not authorized: " + permissionType); |
723 | |
} |
724 | 0 | } |
725 | |
}); |
726 | 0 | } |
727 | |
|
728 | |
@Override |
729 | |
public boolean isAuthorizationRequired() { |
730 | 0 | return true; |
731 | |
} |
732 | |
|
733 | |
@Override |
734 | |
public void setAuthorizationRequired(boolean required) { |
735 | 0 | throw new UnsupportedOperationException(); |
736 | |
} |
737 | |
|
738 | |
protected void setProposalHeaderTitle(){ |
739 | |
String title; |
740 | 0 | if (cluProposalModel.get(cfg.getProposalTitlePath()) != null){ |
741 | 0 | title = getProposalTitle(); |
742 | |
} |
743 | |
else{ |
744 | 0 | title = "New Course (Proposal)"; |
745 | |
} |
746 | 0 | this.setContentTitle(title); |
747 | 0 | this.setName(title); |
748 | 0 | WindowTitleUtils.setContextTitle(title); |
749 | 0 | currentTitle = title; |
750 | 0 | } |
751 | |
|
752 | |
@Override |
753 | |
public WorkflowUtilities getWfUtilities() { |
754 | 0 | return workflowUtil; |
755 | |
} |
756 | |
|
757 | |
@Override |
758 | |
public void beforeViewChange(Enum<?> viewChangingTo, final Callback<Boolean> okToChange) { |
759 | |
|
760 | |
|
761 | |
|
762 | |
|
763 | 0 | super.beforeViewChange(viewChangingTo, new Callback<Boolean>(){ |
764 | |
|
765 | |
@Override |
766 | |
public void exec(Boolean result) { |
767 | 0 | if(result){ |
768 | 0 | if(getCurrentView() instanceof SectionView && ((SectionView)getCurrentView()).isDirty()){ |
769 | 0 | ButtonGroup<YesNoCancelEnum> buttonGroup = new YesNoCancelGroup(); |
770 | 0 | final ButtonMessageDialog<YesNoCancelEnum> dialog = new ButtonMessageDialog<YesNoCancelEnum>("Warning", "You may have unsaved changes. Save changes?", buttonGroup); |
771 | 0 | buttonGroup.addCallback(new Callback<YesNoCancelEnum>(){ |
772 | |
|
773 | |
@Override |
774 | |
public void exec(YesNoCancelEnum result) { |
775 | 0 | switch(result){ |
776 | |
case YES: |
777 | 0 | dialog.hide(); |
778 | 0 | final SaveActionEvent e = new SaveActionEvent(); |
779 | 0 | e.setActionCompleteCallback(new ActionCompleteCallback(){ |
780 | |
|
781 | |
@Override |
782 | |
public void onActionComplete(ActionEvent action) { |
783 | 0 | if(e.isSaveSuccessful()){ |
784 | 0 | okToChange.exec(true); |
785 | |
} |
786 | |
else{ |
787 | 0 | okToChange.exec(false); |
788 | |
} |
789 | 0 | } |
790 | |
|
791 | |
}); |
792 | 0 | fireApplicationEvent(e); |
793 | 0 | break; |
794 | |
case NO: |
795 | |
|
796 | 0 | getCurrentModel(new ModelRequestCallback<DataModel>(){ |
797 | |
|
798 | |
@Override |
799 | |
public void onModelReady(DataModel model) { |
800 | 0 | if (getCurrentView()instanceof Section){ |
801 | 0 | ((Section) getCurrentView()).resetFieldInteractionFlags(); |
802 | |
} |
803 | 0 | okToChange.exec(true); |
804 | 0 | dialog.hide(); |
805 | 0 | } |
806 | |
|
807 | |
@Override |
808 | |
public void onRequestFail(Throwable cause) { |
809 | |
|
810 | |
|
811 | 0 | okToChange.exec(false); |
812 | 0 | dialog.hide(); |
813 | 0 | GWT.log("Unable to retrieve model for data restore on view change with no save", cause); |
814 | 0 | }}, |
815 | |
NO_OP_CALLBACK); |
816 | |
|
817 | 0 | break; |
818 | |
case CANCEL: |
819 | 0 | okToChange.exec(false); |
820 | 0 | dialog.hide(); |
821 | |
|
822 | 0 | HistoryManager.logHistoryChange(); |
823 | |
break; |
824 | |
} |
825 | 0 | } |
826 | |
}); |
827 | 0 | dialog.show(); |
828 | 0 | } |
829 | |
else{ |
830 | 0 | okToChange.exec(true); |
831 | |
} |
832 | |
} |
833 | |
else{ |
834 | 0 | okToChange.exec(false); |
835 | |
} |
836 | 0 | } |
837 | |
}); |
838 | 0 | } |
839 | |
|
840 | |
public KSButton getSaveButton(){ |
841 | 0 | if(currentDocType != MODIFY_TYPE){ |
842 | 0 | return new KSButton("Save and Continue", new ClickHandler(){ |
843 | |
public void onClick(ClickEvent event) { |
844 | 0 | CourseProposalController.this.fireApplicationEvent(new SaveActionEvent(true)); |
845 | 0 | } |
846 | |
}); |
847 | |
} |
848 | |
else{ |
849 | 0 | return new KSButton("Save", new ClickHandler(){ |
850 | |
public void onClick(ClickEvent event) { |
851 | 0 | CourseProposalController.this.fireApplicationEvent(new SaveActionEvent(false)); |
852 | 0 | } |
853 | |
}); |
854 | |
} |
855 | |
} |
856 | |
|
857 | |
public KSButton getCancelButton(final Enum<?> summaryView){ |
858 | |
|
859 | 0 | return new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ |
860 | |
public void onClick(ClickEvent event) { |
861 | 0 | if(!isNew){ |
862 | 0 | CourseProposalController.this.showView(summaryView); |
863 | |
} |
864 | |
else{ |
865 | 0 | Application.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation()); |
866 | |
} |
867 | 0 | } |
868 | |
}); |
869 | |
|
870 | |
} |
871 | |
|
872 | |
@Override |
873 | |
public void onHistoryEvent(String historyStack) { |
874 | 0 | super.onHistoryEvent(historyStack); |
875 | |
|
876 | |
|
877 | 0 | if(cluProposalModel.get(cfg.getProposalTitlePath()) != null && |
878 | |
this.getViewContext().getIdType() != IdType.COPY_OF_OBJECT_ID){ |
879 | 0 | RecentlyViewedHelper.addCurrentDocument(getProposalTitle()); |
880 | |
} |
881 | 0 | } |
882 | |
|
883 | |
private String getProposalTitle(){ |
884 | 0 | StringBuffer sb = new StringBuffer(); |
885 | 0 | sb.append(cluProposalModel.get(cfg.getProposalTitlePath())); |
886 | 0 | sb.append(" (Proposal)"); |
887 | 0 | return sb.toString(); |
888 | |
} |
889 | |
|
890 | |
public String getCourseId(){ |
891 | 0 | return cluProposalModel.<String>get("id"); |
892 | |
} |
893 | |
|
894 | |
public boolean isNew() { |
895 | 0 | return isNew; |
896 | |
} |
897 | |
|
898 | |
public CourseRequirementsDataModel getReqDataModel() { |
899 | 0 | return reqDataModel; |
900 | |
} |
901 | |
} |