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