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