1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.kuali.student.core.workflow.ui.client.widgets; |
16 | |
|
17 | |
import java.util.ArrayList; |
18 | |
import java.util.HashSet; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.student.common.assembly.data.Metadata; |
22 | |
import org.kuali.student.common.assembly.data.MetadataInterrogator; |
23 | |
import org.kuali.student.common.assembly.data.ModelDefinition; |
24 | |
import org.kuali.student.common.assembly.data.QueryPath; |
25 | |
import org.kuali.student.common.dto.DtoConstants.DtoState; |
26 | |
import org.kuali.student.common.dto.RichTextInfo; |
27 | |
import org.kuali.student.common.ui.client.application.Application; |
28 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
29 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
30 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptorReadOnly; |
31 | |
import org.kuali.student.common.ui.client.configurable.mvc.LayoutController; |
32 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
33 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
34 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
35 | |
import org.kuali.student.common.ui.client.event.ActionEvent; |
36 | |
import org.kuali.student.common.ui.client.event.SaveActionEvent; |
37 | |
import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback; |
38 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
39 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
40 | |
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
41 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
42 | |
import org.kuali.student.common.ui.client.util.SearchUtils; |
43 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
44 | |
import org.kuali.student.common.ui.client.widgets.KSDropDown; |
45 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
46 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
47 | |
import org.kuali.student.common.ui.client.widgets.KSRichEditor; |
48 | |
import org.kuali.student.common.ui.client.widgets.StylishDropDown; |
49 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.AcknowledgeCancelGroup; |
50 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations; |
51 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.AcknowledgeCancelEnum; |
52 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.ConfirmCancelEnum; |
53 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.RejectCancelEnum; |
54 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ConfirmCancelGroup; |
55 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.RejectCancelGroup; |
56 | |
import org.kuali.student.common.ui.client.widgets.dialog.ConfirmationDialog; |
57 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ActionCancelGroup; |
58 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrPanel; |
59 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; |
60 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract; |
61 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
62 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
63 | |
import org.kuali.student.common.ui.client.widgets.list.impl.SimpleListItems; |
64 | |
import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; |
65 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
66 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
67 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
68 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
69 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel; |
70 | |
import org.kuali.student.core.comment.dto.CommentInfo; |
71 | |
import org.kuali.student.core.comments.ui.client.service.CommentRpcService; |
72 | |
import org.kuali.student.core.comments.ui.client.service.CommentRpcServiceAsync; |
73 | |
import org.kuali.student.core.proposal.dto.ProposalInfo; |
74 | |
import org.kuali.student.core.proposal.ui.client.service.ProposalRpcService; |
75 | |
import org.kuali.student.core.proposal.ui.client.service.ProposalRpcServiceAsync; |
76 | |
import org.kuali.student.core.workflow.ui.client.WorkflowConstants; |
77 | |
import org.kuali.student.core.workflow.ui.client.service.WorkflowRpcService; |
78 | |
import org.kuali.student.core.workflow.ui.client.service.WorkflowRpcServiceAsync; |
79 | |
|
80 | |
import com.google.gwt.core.client.GWT; |
81 | |
import com.google.gwt.event.dom.client.ClickEvent; |
82 | |
import com.google.gwt.event.dom.client.ClickHandler; |
83 | |
import com.google.gwt.event.dom.client.KeyUpEvent; |
84 | |
import com.google.gwt.event.dom.client.KeyUpHandler; |
85 | |
import com.google.gwt.user.client.Window; |
86 | |
import com.google.gwt.user.client.rpc.AsyncCallback; |
87 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
88 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
89 | |
import com.google.gwt.user.client.ui.Widget; |
90 | |
|
91 | 0 | public class WorkflowUtilities{ |
92 | |
|
93 | |
|
94 | |
public static final String PROPOSAL_REF_TYPE_KEY = "referenceType.clu.proposal"; |
95 | |
|
96 | 0 | public static enum DecisionRationaleDetail { |
97 | 0 | APPROVE("kuali.comment.type.workflowDecisionRationale.approve", "Approved"), |
98 | 0 | REJECT("kuali.comment.type.workflowDecisionRationale.reject", "Rejected"), |
99 | 0 | RETURN_TO_PREVIOUS("kuali.comment.type.workflowDecisionRationale.return", "Sent for Revisions"), |
100 | 0 | WITHDRAW("kuali.comment.type.workflowDecisionRationale.withdraw", "Withdrawn"), |
101 | 0 | ACKNOWLEDGE("kuali.comment.type.workflowDecisionRationale.acknowledge", "Acknowledged"), |
102 | 0 | FYI("kuali.comment.type.workflowDecisionRationale.fyi", "FYI"), |
103 | 0 | CANCEL_WORKFLOW("kuali.comment.type.workflowDecisionRationale.cancelWorkflow", "Cancelled"), |
104 | 0 | BLANKET_APPROVE("kuali.comment.type.workflowDecisionRationale.blanketApprove", "Blanket Approved") |
105 | |
; |
106 | |
|
107 | 0 | private String type = ""; |
108 | 0 | private String label = ""; |
109 | |
|
110 | |
|
111 | |
|
112 | 0 | private DecisionRationaleDetail(String type, String label) { |
113 | 0 | this.type = type; |
114 | 0 | this.label = label; |
115 | 0 | } |
116 | |
|
117 | |
public String getType() { |
118 | 0 | return type; |
119 | |
} |
120 | |
|
121 | |
public String getLabel() { |
122 | 0 | return label; |
123 | |
} |
124 | |
|
125 | |
public static DecisionRationaleDetail getByType(String type) { |
126 | 0 | for (DecisionRationaleDetail detail : DecisionRationaleDetail.values()) { |
127 | 0 | if (detail.getType().equals(type)) { |
128 | 0 | return detail; |
129 | |
} |
130 | |
} |
131 | 0 | return null; |
132 | |
} |
133 | |
|
134 | |
} |
135 | |
|
136 | 0 | DataModel dataModel=null; |
137 | |
|
138 | |
|
139 | |
|
140 | 0 | boolean loaded=false; |
141 | |
|
142 | 0 | private boolean workflowWidgetsEnabled = true; |
143 | |
|
144 | |
private KSMenuItemData wfApproveItem; |
145 | |
private KSMenuItemData wfDisApproveItem; |
146 | |
private KSMenuItemData wfAcknowledgeItem; |
147 | |
private KSMenuItemData wfStartWorkflowItem; |
148 | |
private KSMenuItemData wfCancelWorkflowItem; |
149 | |
private KSMenuItemData wfFYIWorkflowItem; |
150 | |
private KSMenuItemData wfWithdrawItem; |
151 | |
private KSMenuItemData wfReturnToPreviousItem; |
152 | |
private KSMenuItemData wfBlanketApproveItem; |
153 | |
|
154 | 0 | private final List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); |
155 | 0 | private final List<KSMenuItemData> additionalItems = new ArrayList<KSMenuItemData>(); |
156 | |
|
157 | |
|
158 | |
SaveActionEvent approveSaveActionEvent; |
159 | |
SaveActionEvent startWorkflowSaveActionEvent; |
160 | |
|
161 | 0 | WorkflowRpcServiceAsync workflowRpcServiceAsync = GWT.create(WorkflowRpcService.class); |
162 | 0 | private final CommentRpcServiceAsync commentServiceAsync = GWT.create(CommentRpcService.class); |
163 | 0 | private final ProposalRpcServiceAsync proposalServiceAsync = GWT.create(ProposalRpcService.class); |
164 | |
|
165 | |
private String modelName; |
166 | |
private String proposalPath; |
167 | 0 | private String proposalId = ""; |
168 | |
private String workflowId; |
169 | 0 | private String proposalName=""; |
170 | 0 | private String workflowActions=""; |
171 | |
|
172 | 0 | private final List<StylishDropDown> workflowWidgets = new ArrayList<StylishDropDown>(); |
173 | |
private Callback<Boolean> submitCallback; |
174 | 0 | private final ConfirmationDialog dialog = new ConfirmationDialog("Submit Proposal", "Are you sure you want to submit the proposal to workflow?", "Submit"); |
175 | |
private AbbrPanel required; |
176 | |
private KSLightBox submitSuccessDialog; |
177 | |
private VerticalPanel dialogPanel; |
178 | |
private VerticalSectionView approveDialogView; |
179 | |
private VerticalSectionView blanketApproveDialogView; |
180 | 0 | private HashSet<String> ignoredApproveDialogFields = new HashSet<String>(); |
181 | |
|
182 | 0 | private final KSLabel workflowStatusLabel = new KSLabel(""); |
183 | |
|
184 | 0 | private final KSLabel proposalStatusLabel = new KSLabel(""); |
185 | |
|
186 | |
private final LayoutController parentController; |
187 | |
|
188 | 0 | private String dropDownLabel = "Workflow Actions"; |
189 | |
|
190 | 0 | ActionCancelGroup approveCancelButtons = new ActionCancelGroup(ButtonEnumerations.ApproveCancelEnum.APPROVE, ButtonEnumerations.ApproveCancelEnum.CANCEL); |
191 | |
|
192 | 0 | public WorkflowUtilities(LayoutController parentController, String proposalPath) { |
193 | 0 | this.parentController = parentController; |
194 | 0 | this.proposalPath = proposalPath; |
195 | 0 | setupWFButtons(); |
196 | 0 | setupDialog(); |
197 | 0 | } |
198 | |
|
199 | 0 | public WorkflowUtilities(LayoutController parentController, String proposalPath, String dropDownLabel) { |
200 | 0 | this.dropDownLabel = dropDownLabel; |
201 | 0 | this.parentController = parentController; |
202 | 0 | this.proposalPath = proposalPath; |
203 | 0 | setupWFButtons(); |
204 | 0 | setupDialog(); |
205 | 0 | } |
206 | |
|
207 | 0 | public WorkflowUtilities(LayoutController parentController, String proposalPath, String dropDownLabel, Enum<?> viewEnum, String name, String modelId) { |
208 | 0 | this.dropDownLabel = dropDownLabel; |
209 | 0 | this.parentController = parentController; |
210 | 0 | this.proposalPath = proposalPath; |
211 | |
|
212 | 0 | approveDialogView = new VerticalSectionView(viewEnum, name, modelId); |
213 | 0 | approveDialogView.setController(parentController); |
214 | |
|
215 | 0 | blanketApproveDialogView = new VerticalSectionView(viewEnum, name, modelId); |
216 | 0 | blanketApproveDialogView.setController(parentController); |
217 | |
|
218 | 0 | setupWFButtons(); |
219 | 0 | setupDialog(); |
220 | 0 | } |
221 | |
|
222 | |
public void addApproveDialogMsg(String messageText) { |
223 | 0 | KSLabel textArea = new KSLabel(); |
224 | 0 | textArea.setText(messageText); |
225 | |
|
226 | 0 | approveDialogView.addWidget(textArea); |
227 | 0 | } |
228 | |
|
229 | |
public FieldDescriptor addApproveDialogField(String parentPath, String fieldKey, MessageKeyInfo messageKey, ModelDefinition modelDefinition, boolean forceAdd){ |
230 | 0 | return addApproveDialogField(parentPath, fieldKey, messageKey, modelDefinition, forceAdd, false, null); |
231 | |
|
232 | |
} |
233 | |
|
234 | |
public FieldDescriptor addApproveDialogField(String parentPath, String fieldKey, MessageKeyInfo messageKey, ModelDefinition modelDefinition, boolean forceAdd, boolean readOnly){ |
235 | 0 | return addApproveDialogField(parentPath, fieldKey, messageKey, modelDefinition, forceAdd, readOnly, null); |
236 | |
|
237 | |
} |
238 | |
|
239 | |
public FieldDescriptor addApproveDialogField(String parentPath, String fieldKey, MessageKeyInfo messageKey, ModelDefinition modelDefinition, boolean forceAdd, boolean readOnly, Widget widget){ |
240 | |
|
241 | 0 | QueryPath path = QueryPath.concat(parentPath, fieldKey); |
242 | 0 | Metadata meta = modelDefinition.getMetadata(path); |
243 | |
|
244 | |
FieldDescriptor blanketApproveFd; |
245 | |
FieldDescriptor approveFd; |
246 | |
|
247 | |
|
248 | 0 | if(blanketApproveDialogView != null){ |
249 | 0 | if(!readOnly){ |
250 | 0 | blanketApproveFd = new FieldDescriptor(path.toString(), messageKey, meta); |
251 | |
} else { |
252 | 0 | blanketApproveFd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta); |
253 | |
} |
254 | 0 | blanketApproveFd.setHasHadFocus(true); |
255 | 0 | blanketApproveDialogView.addField(blanketApproveFd); |
256 | |
} |
257 | |
|
258 | |
|
259 | 0 | if(approveDialogView != null){ |
260 | 0 | if(forceAdd || |
261 | |
(meta.isCanEdit() && |
262 | |
(MetadataInterrogator.isRequiredForNextState(meta) || |
263 | |
(meta.getConstraints() != null && meta.getConstraints().get(0)!=null && meta.getConstraints().get(0).getMinOccurs()!= null && meta.getConstraints().get(0).getMinOccurs()>0)))){ |
264 | 0 | if(!readOnly){ |
265 | 0 | approveFd = new FieldDescriptor(path.toString(), messageKey, meta); |
266 | |
} else { |
267 | 0 | approveFd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta); |
268 | |
} |
269 | 0 | approveFd.setHasHadFocus(true); |
270 | 0 | approveDialogView.addField(approveFd); |
271 | 0 | return approveFd; |
272 | |
} |
273 | |
} |
274 | 0 | return null; |
275 | |
} |
276 | |
|
277 | |
public void updateApproveFields(){ |
278 | 0 | parentController.requestModel(new ModelRequestCallback<DataModel>(){ |
279 | |
public void onModelReady(final DataModel model) { |
280 | 0 | if(approveDialogView!=null){ |
281 | 0 | approveDialogView.updateView(model); |
282 | 0 | for (final FieldDescriptor fd:approveDialogView.getFields()){ |
283 | 0 | updateCrossField(fd,model); |
284 | |
} |
285 | |
} |
286 | 0 | if(blanketApproveDialogView!=null){ |
287 | 0 | blanketApproveDialogView.updateView(model); |
288 | 0 | for (final FieldDescriptor fd:blanketApproveDialogView.getFields()){ |
289 | 0 | updateCrossField(fd,model); |
290 | |
} |
291 | |
} |
292 | 0 | } |
293 | |
public void onRequestFail(Throwable cause) { |
294 | 0 | } |
295 | |
|
296 | |
}); |
297 | 0 | } |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
public static void updateCrossField(final FieldDescriptor fd, final DataModel dataModel){ |
310 | |
|
311 | 0 | if (fd.getFieldWidget() instanceof KSPicker && ((KSPicker) fd.getFieldWidget()).getInputWidget() instanceof KSSelectItemWidgetAbstract) { |
312 | 0 | if (fd.getFieldWidget() instanceof HasCrossConstraints) { |
313 | 0 | HashSet<String> constraints = ((HasCrossConstraints) fd.getFieldWidget()).getCrossConstraints(); |
314 | 0 | if (constraints != null) { |
315 | 0 | for (String path : constraints) { |
316 | 0 | final String finalPath = SearchUtils.resolvePath(path); |
317 | 0 | final FieldDescriptor crossField = Application.getApplicationContext().getPathToFieldMapping(null, finalPath); |
318 | 0 | if (crossField != null) { |
319 | 0 | final ModelWidgetBinding mwb = crossField.getModelWidgetBinding(); |
320 | 0 | if (mwb != null) { |
321 | |
|
322 | |
|
323 | 0 | if (crossField.getFieldWidget() instanceof KSPicker && ((KSPicker) crossField.getFieldWidget()).getInputWidget() instanceof KSSelectItemWidgetAbstract) { |
324 | 0 | ((KSSelectItemWidgetAbstract) ((KSPicker) crossField.getFieldWidget()).getInputWidget()).addWidgetReadyCallback(new Callback<Widget>() { |
325 | |
public void exec(Widget result) { |
326 | 0 | mwb.setWidgetValue(crossField.getFieldWidget(), dataModel, finalPath); |
327 | 0 | ((HasCrossConstraints) fd.getFieldWidget()).reprocessWithUpdatedConstraints(); |
328 | 0 | } |
329 | |
}); |
330 | |
} else { |
331 | 0 | mwb.setWidgetValue(crossField.getFieldWidget(), dataModel, finalPath); |
332 | |
} |
333 | |
} |
334 | |
} |
335 | 0 | } |
336 | |
} |
337 | 0 | ((HasCrossConstraints) fd.getFieldWidget()).reprocessWithUpdatedConstraints(); |
338 | |
} |
339 | |
} |
340 | 0 | } |
341 | |
public void requestAndSetupModel(final Callback<Boolean> onModelReadyCallback) { |
342 | |
|
343 | 0 | if(null==dataModel){ |
344 | |
|
345 | 0 | parentController.requestModel(modelName, new ModelRequestCallback<DataModel>() { |
346 | |
|
347 | |
@Override |
348 | |
public void onRequestFail(Throwable cause) { |
349 | 0 | Window.alert("Model Request Failed. "+cause.getMessage()); |
350 | 0 | } |
351 | |
|
352 | |
@Override |
353 | |
public void onModelReady(DataModel model) { |
354 | |
|
355 | 0 | dataModel = model; |
356 | 0 | updateWorkflow(dataModel); |
357 | 0 | onModelReadyCallback.exec(true); |
358 | 0 | } |
359 | |
}); |
360 | |
}else{ |
361 | |
|
362 | |
|
363 | 0 | updateWorkflow(dataModel); |
364 | 0 | onModelReadyCallback.exec(true); |
365 | |
} |
366 | 0 | } |
367 | |
|
368 | |
private void setupWFButtons() { |
369 | 0 | wfApproveItem = getApproveItem(); |
370 | 0 | wfDisApproveItem = getDisApproveItem(); |
371 | 0 | wfAcknowledgeItem = getAcknowledgeItem(); |
372 | 0 | wfStartWorkflowItem = getStartItem(); |
373 | 0 | wfCancelWorkflowItem = getCancelWorkflowItem(); |
374 | 0 | wfFYIWorkflowItem = getFYIWorkflowItem(); |
375 | 0 | wfWithdrawItem = getWithdrawItem(); |
376 | 0 | wfReturnToPreviousItem = getReturnToPreviousItem(); |
377 | 0 | wfBlanketApproveItem = getBlanketApproveItem(); |
378 | 0 | } |
379 | |
|
380 | |
private void setupSubmitSuccessDialog(){ |
381 | 0 | if(submitSuccessDialog==null){ |
382 | 0 | submitSuccessDialog= new KSLightBox(); |
383 | 0 | submitSuccessDialog.setSize(580, 480); |
384 | 0 | dialogPanel = new VerticalPanel(); |
385 | 0 | submitSuccessDialog.setWidget(dialogPanel); |
386 | |
|
387 | |
} |
388 | |
|
389 | 0 | } |
390 | |
|
391 | |
private void setupDialog(){ |
392 | |
|
393 | 0 | dialog.getConfirmButton().addClickHandler(new ClickHandler(){ |
394 | |
|
395 | |
@Override |
396 | |
public void onClick(ClickEvent event) { |
397 | 0 | dialog.getConfirmButton().setEnabled(false); |
398 | 0 | workflowRpcServiceAsync.submitDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){ |
399 | |
@Override |
400 | |
public void handleFailure(Throwable caught) { |
401 | 0 | Window.alert("Error starting Proposal workflow"); |
402 | 0 | dialog.getConfirmButton().setEnabled(true); |
403 | 0 | } |
404 | |
public void onSuccess(Boolean result) { |
405 | 0 | if (result){ |
406 | 0 | updateWorkflow(dataModel); |
407 | 0 | dialog.hide(); |
408 | 0 | dialog.getConfirmButton().setEnabled(true); |
409 | 0 | if(submitCallback != null){ |
410 | 0 | submitCallback.exec(true); |
411 | |
} |
412 | |
|
413 | 0 | KSNotifier.add(new KSNotification("Proposal has been routed to workflow", false)); |
414 | |
} else { |
415 | 0 | Window.alert("Error starting Proposal workflow"); |
416 | |
} |
417 | 0 | } |
418 | |
}); |
419 | |
|
420 | 0 | } |
421 | |
}); |
422 | 0 | } |
423 | |
|
424 | |
public Widget getWorkflowActionsWidget(){ |
425 | |
|
426 | 0 | StylishDropDown workflowActionsDropDown = new StylishDropDown(dropDownLabel ); |
427 | 0 | workflowActionsDropDown.makeAButtonWhenOneItem(true); |
428 | 0 | workflowActionsDropDown.addStyleName("KS-Workflow-DropDown"); |
429 | 0 | workflowWidgets.add(workflowActionsDropDown); |
430 | 0 | workflowActionsDropDown.setVisible(false); |
431 | 0 | updateWorkflow(dataModel); |
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | 0 | return workflowActionsDropDown; |
437 | |
} |
438 | |
|
439 | |
public void enableWorkflowActionsWidgets(boolean enable) { |
440 | 0 | workflowWidgetsEnabled = enable; |
441 | 0 | updateWorkflowActionsWidget(); |
442 | 0 | } |
443 | |
|
444 | |
public void doValidationCheck(Callback<List<ValidationResultInfo>> callback){ |
445 | 0 | dataModel.validateNextState(callback); |
446 | 0 | } |
447 | |
|
448 | |
public KSLabel getWorkflowStatusLabel(){ |
449 | 0 | return workflowStatusLabel; |
450 | |
} |
451 | |
|
452 | |
public KSLabel getProposalStatusLabel() { |
453 | 0 | return proposalStatusLabel; |
454 | |
} |
455 | |
|
456 | |
private void updateWorkflowIdFromModel(final DataModel model) { |
457 | 0 | if(model!=null){ |
458 | 0 | String modelProposalId = model.get(QueryPath.parse(proposalPath + "/id")); |
459 | |
|
460 | |
|
461 | 0 | if (modelProposalId != null && !modelProposalId.isEmpty() && !modelProposalId.equals(proposalId)){ |
462 | 0 | proposalId = modelProposalId; |
463 | 0 | workflowId = model.get(QueryPath.parse(proposalPath + "/workflowId")); |
464 | 0 | proposalName = model.get(QueryPath.parse(proposalPath + "/name")); |
465 | |
} |
466 | |
} |
467 | 0 | } |
468 | |
|
469 | |
private void updateWorkflow(DataModel model){ |
470 | 0 | updateWorkflowIdFromModel(model); |
471 | |
|
472 | 0 | if (workflowId != null && !workflowId.isEmpty()){ |
473 | |
|
474 | 0 | workflowRpcServiceAsync.getActionsRequested(workflowId, new KSAsyncCallback<String>(){ |
475 | |
|
476 | |
public void onSuccess(String result) { |
477 | 0 | workflowActions = result; |
478 | 0 | updateWorkflowActionsWidget(); |
479 | 0 | } |
480 | |
}); |
481 | |
|
482 | 0 | workflowRpcServiceAsync.getDocumentStatus(workflowId, new KSAsyncCallback<String>(){ |
483 | |
@Override |
484 | |
public void handleFailure(Throwable caught) { |
485 | 0 | setWorkflowStatus("Unknown"); |
486 | 0 | } |
487 | |
|
488 | |
@Override |
489 | |
public void onSuccess(String result) { |
490 | 0 | setWorkflowStatus(result); |
491 | 0 | } |
492 | |
}); |
493 | 0 | proposalServiceAsync.getProposalByWorkflowId(workflowId, new KSAsyncCallback<ProposalInfo>() { |
494 | |
@Override |
495 | |
public void handleFailure(Throwable caught) { |
496 | 0 | setProposalStatus("Unknown"); |
497 | 0 | } |
498 | |
|
499 | |
@Override |
500 | |
public void onSuccess(ProposalInfo result) { |
501 | 0 | setProposalStatus(result.getState()); |
502 | 0 | } |
503 | |
}); |
504 | |
} else { |
505 | 0 | setWorkflowStatus("Draft"); |
506 | 0 | setProposalStatus("Draft"); |
507 | |
} |
508 | 0 | } |
509 | |
|
510 | |
private void updateWorkflowActionsWidget(){ |
511 | 0 | items.clear(); |
512 | |
|
513 | |
|
514 | |
|
515 | 0 | if (workflowWidgetsEnabled){ |
516 | |
|
517 | 0 | String workflowNode = null; |
518 | 0 | if(dataModel!=null){ |
519 | 0 | workflowNode = dataModel.get("proposal/workflowNode"); |
520 | |
} |
521 | |
|
522 | 0 | if(workflowActions.contains("S")){ |
523 | 0 | items.add(wfStartWorkflowItem); |
524 | |
} |
525 | 0 | if(workflowActions.contains("C")){ |
526 | 0 | items.add(wfCancelWorkflowItem); |
527 | |
} |
528 | 0 | if(workflowActions.contains("A")){ |
529 | 0 | items.add(wfApproveItem); |
530 | |
|
531 | 0 | if("PreRoute".equals(workflowNode)){ |
532 | 0 | wfApproveItem.setLabel("Resubmit Proposal"); |
533 | |
}else{ |
534 | 0 | wfApproveItem.setLabel("Approve Proposal"); |
535 | |
|
536 | 0 | items.add(wfDisApproveItem); |
537 | |
} |
538 | |
} |
539 | 0 | if(workflowActions.contains("K")){ |
540 | 0 | items.add(wfAcknowledgeItem); |
541 | |
} |
542 | 0 | if(workflowActions.contains("F")){ |
543 | 0 | items.add(wfFYIWorkflowItem); |
544 | |
} |
545 | 0 | if(workflowActions.contains("R")){ |
546 | |
|
547 | |
|
548 | 0 | if(!"PreRoute".equals(workflowNode)){ |
549 | 0 | items.add(wfReturnToPreviousItem); |
550 | |
} |
551 | |
} |
552 | 0 | if(workflowActions.contains("B")){ |
553 | 0 | items.add(wfBlanketApproveItem); |
554 | |
} |
555 | 0 | if(workflowActions.contains("W")){ |
556 | 0 | items.add(wfWithdrawItem); |
557 | |
} |
558 | 0 | } else { |
559 | 0 | if(workflowActions.contains("C")){ |
560 | 0 | items.add(wfCancelWorkflowItem); |
561 | |
} |
562 | 0 | if(workflowActions.contains("K")){ |
563 | 0 | items.add(wfAcknowledgeItem); |
564 | |
} |
565 | 0 | if(workflowActions.contains("F")){ |
566 | 0 | items.add(wfFYIWorkflowItem); |
567 | |
} |
568 | 0 | if(workflowActions.contains("W")){ |
569 | 0 | items.add(wfWithdrawItem); |
570 | |
} |
571 | 0 | if(workflowActions.contains("A")){ |
572 | 0 | items.add(wfDisApproveItem); |
573 | |
} |
574 | |
} |
575 | |
|
576 | |
|
577 | 0 | items.addAll(additionalItems); |
578 | |
|
579 | 0 | for(StylishDropDown widget: workflowWidgets){ |
580 | |
|
581 | 0 | widget.setItems(items); |
582 | 0 | widget.setEnabled(true); |
583 | 0 | if(items.isEmpty()){ |
584 | 0 | widget.setVisible(false); |
585 | |
} |
586 | |
else{ |
587 | 0 | widget.setVisible(true); |
588 | |
} |
589 | |
} |
590 | 0 | } |
591 | |
|
592 | |
private KSMenuItemData getFYIWorkflowItem() { |
593 | |
KSMenuItemData wfFYIWorkflowItem; |
594 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
595 | 0 | wfFYIWorkflowItem = new KSMenuItemData("FYI Proposal", new ClickHandler(){ |
596 | |
public void onClick(ClickEvent event) { |
597 | 0 | addRationale(rationaleEditor,DecisionRationaleDetail.FYI.getType()); |
598 | 0 | workflowRpcServiceAsync.fyiDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){ |
599 | |
@Override |
600 | |
public void handleFailure(Throwable caught) { |
601 | 0 | Window.alert("Error FYIing Proposal"); |
602 | 0 | } |
603 | |
public void onSuccess( |
604 | |
Boolean result) { |
605 | 0 | if(result){ |
606 | 0 | updateWorkflow(dataModel); |
607 | 0 | if(submitCallback != null){ |
608 | 0 | submitCallback.exec(true); |
609 | |
} |
610 | |
|
611 | 0 | KSNotifier.add(new KSNotification("Proposal was FYIed", false)); |
612 | |
}else{ |
613 | 0 | Window.alert("Error FYIing Proposal"); |
614 | |
} |
615 | 0 | } |
616 | |
|
617 | |
}); |
618 | 0 | } |
619 | |
}); |
620 | 0 | return wfFYIWorkflowItem; |
621 | |
} |
622 | |
|
623 | |
private KSMenuItemData getAcknowledgeItem() { |
624 | |
KSMenuItemData wfAcknowledgeItem; |
625 | 0 | wfAcknowledgeItem = new KSMenuItemData("Acknowledge Proposal", new ClickHandler(){ |
626 | |
public void onClick(ClickEvent event) { |
627 | 0 | setupSubmitSuccessDialog(); |
628 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
629 | 0 | final AcknowledgeCancelGroup approvalButton = new AcknowledgeCancelGroup(new Callback<AcknowledgeCancelEnum>(){ |
630 | |
|
631 | |
@Override |
632 | |
public void exec(AcknowledgeCancelEnum result) { |
633 | 0 | if(!result.name().equals("CANCEL")){ |
634 | 0 | addRationale(rationaleEditor,DecisionRationaleDetail.ACKNOWLEDGE.getType()); |
635 | 0 | workflowRpcServiceAsync.acknowledgeDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){ |
636 | |
@Override |
637 | |
public void handleFailure(Throwable caught) { |
638 | 0 | submitSuccessDialog.hide(); |
639 | 0 | Window.alert("Error acknowledging Proposal"); |
640 | 0 | } |
641 | |
public void onSuccess(Boolean result) { |
642 | 0 | submitSuccessDialog.hide(); |
643 | 0 | if(result){ |
644 | 0 | updateWorkflow(dataModel); |
645 | 0 | if(submitCallback != null){ |
646 | 0 | submitCallback.exec(true); |
647 | |
} |
648 | |
|
649 | 0 | KSNotifier.add(new KSNotification("Proposal was acknowledged", false)); |
650 | |
}else{ |
651 | 0 | Window.alert("Error acknowledging Proposal"); |
652 | |
} |
653 | 0 | } |
654 | |
}); |
655 | |
} |
656 | |
else{ |
657 | 0 | submitSuccessDialog.hide(); |
658 | |
} |
659 | 0 | } |
660 | |
}); |
661 | |
|
662 | 0 | approvalButton.getButton(ButtonEnumerations.AcknowledgeCancelEnum.ACKNOWLEDGE).setEnabled(false); |
663 | |
|
664 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
665 | |
|
666 | |
@Override |
667 | |
public void onKeyUp(KeyUpEvent event) { |
668 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
669 | 0 | approvalButton.getButton(ButtonEnumerations.AcknowledgeCancelEnum.ACKNOWLEDGE).setEnabled(true); |
670 | |
} else { |
671 | 0 | approvalButton.getButton(ButtonEnumerations.AcknowledgeCancelEnum.ACKNOWLEDGE).setEnabled(false); |
672 | |
} |
673 | 0 | } |
674 | |
|
675 | |
}); |
676 | |
|
677 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Acknowledge Proposal"); |
678 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are acknowledging the " + proposalName +" proposal"); |
679 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
680 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
681 | 0 | dialogPanel.clear(); |
682 | 0 | dialogPanel.add(headerTitle); |
683 | 0 | dialogPanel.add(dialogLabel); |
684 | 0 | dialogPanel.add(fieldLabel); |
685 | 0 | dialogPanel.add(rationaleEditor); |
686 | 0 | dialogPanel.add(approvalButton); |
687 | 0 | submitSuccessDialog.show(); |
688 | 0 | } |
689 | |
}); |
690 | 0 | return wfAcknowledgeItem; |
691 | |
} |
692 | |
|
693 | |
private KSMenuItemData getDisApproveItem() { |
694 | |
KSMenuItemData wfDisApproveItem; |
695 | 0 | wfDisApproveItem = new KSMenuItemData("Reject Proposal", new ClickHandler(){ |
696 | |
public void onClick(ClickEvent event) { |
697 | 0 | setupSubmitSuccessDialog(); |
698 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
699 | |
|
700 | 0 | final RejectCancelGroup disapprovalButton = new RejectCancelGroup(new Callback<RejectCancelEnum>(){ |
701 | |
|
702 | |
@Override |
703 | |
public void exec(RejectCancelEnum result) { |
704 | 0 | if(!result.name().equals("CANCEL")){ |
705 | 0 | if(rationaleEditor.getText().trim().equals("")){ |
706 | 0 | required.setText("Please enter the decision rationale"); |
707 | |
} |
708 | |
else{ |
709 | 0 | addRationale(rationaleEditor,DecisionRationaleDetail.REJECT.getType()); |
710 | 0 | workflowRpcServiceAsync.disapproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){ |
711 | |
@Override |
712 | |
public void handleFailure(Throwable caught) { |
713 | 0 | submitSuccessDialog.hide(); |
714 | 0 | Window.alert("Error rejecting Proposal"); |
715 | 0 | } |
716 | |
public void onSuccess(Boolean result) { |
717 | 0 | submitSuccessDialog.hide(); |
718 | 0 | if(submitCallback != null){ |
719 | 0 | submitCallback.exec(result); |
720 | |
} |
721 | 0 | if(result){ |
722 | 0 | KSNotifier.add(new KSNotification("Proposal was rejected", false)); |
723 | 0 | updateWorkflow(dataModel); |
724 | |
}else{ |
725 | 0 | Window.alert("Error rejecting Proposal"); |
726 | |
} |
727 | 0 | } |
728 | |
|
729 | |
}); |
730 | |
} |
731 | |
|
732 | |
} |
733 | |
else{ |
734 | 0 | submitSuccessDialog.hide(); |
735 | |
} |
736 | 0 | } |
737 | |
}); |
738 | |
|
739 | 0 | disapprovalButton.getButton(ButtonEnumerations.RejectCancelEnum.REJECT).setEnabled(false); |
740 | |
|
741 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
742 | |
|
743 | |
@Override |
744 | |
public void onKeyUp(KeyUpEvent event) { |
745 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
746 | 0 | disapprovalButton.getButton(ButtonEnumerations.RejectCancelEnum.REJECT).setEnabled(true); |
747 | |
} else { |
748 | 0 | disapprovalButton.getButton(ButtonEnumerations.RejectCancelEnum.REJECT).setEnabled(false); |
749 | |
} |
750 | 0 | } |
751 | |
|
752 | |
}); |
753 | |
|
754 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Reject Proposal"); |
755 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are rejecting the " + proposalName +" proposal"); |
756 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
757 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
758 | 0 | required.setVisible(true); |
759 | |
|
760 | |
|
761 | |
|
762 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
763 | 0 | dialogPanel.clear(); |
764 | 0 | dialogPanel.add(headerTitle); |
765 | 0 | dialogPanel.add(dialogLabel); |
766 | 0 | dialogPanel.add(fieldLabel); |
767 | 0 | dialogPanel.add(required); |
768 | 0 | dialogPanel.add(rationaleEditor); |
769 | 0 | dialogPanel.add(disapprovalButton); |
770 | 0 | submitSuccessDialog.setWidget(dialogPanel); |
771 | 0 | submitSuccessDialog.show(); |
772 | 0 | } |
773 | |
}); |
774 | 0 | return wfDisApproveItem; |
775 | |
} |
776 | |
|
777 | |
private KSMenuItemData getApproveItem() { |
778 | |
KSMenuItemData wfApproveItem; |
779 | |
|
780 | 0 | wfApproveItem= new KSMenuItemData("Approve Proposal", new ClickHandler(){ |
781 | |
public void onClick(ClickEvent event) { |
782 | 0 | setupSubmitSuccessDialog(); |
783 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
784 | |
|
785 | |
|
786 | |
|
787 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
788 | |
|
789 | 0 | approveCancelButtons.addCallback(new Callback<ButtonEnumerations.ButtonEnum>() { |
790 | |
@Override |
791 | |
public void exec(ButtonEnumerations.ButtonEnum result) { |
792 | 0 | if (result != ButtonEnumerations.ApproveCancelEnum.CANCEL) { |
793 | 0 | if (rationaleEditor.getText().trim().equals("")) { |
794 | 0 | required.setText("Please enter the decision rationale"); |
795 | |
} else { |
796 | 0 | if (approveDialogView != null) { |
797 | |
|
798 | 0 | parentController.requestModel(new ModelRequestCallback<DataModel>() { |
799 | |
|
800 | |
@Override |
801 | |
public void onModelReady(DataModel model) { |
802 | 0 | approveDialogView.updateModel(); |
803 | 0 | model.validateNextState(new Callback<List<ValidationResultInfo>>() { |
804 | |
@Override |
805 | |
public void exec(List<ValidationResultInfo> results) { |
806 | |
|
807 | 0 | if (ErrorLevel.OK.equals(approveDialogView.processValidationResults(results))) { |
808 | |
|
809 | 0 | SaveActionEvent saveActionEvent = new SaveActionEvent(); |
810 | 0 | saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback() { |
811 | |
public void onActionComplete(ActionEvent action) { |
812 | 0 | doWorkflowApprove(); |
813 | 0 | } |
814 | |
}); |
815 | 0 | parentController.fireApplicationEvent(saveActionEvent); |
816 | 0 | } else { |
817 | 0 | KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); |
818 | |
} |
819 | 0 | } |
820 | |
}); |
821 | 0 | } |
822 | |
|
823 | |
@Override |
824 | |
public void onRequestFail(Throwable cause) { |
825 | 0 | KSNotifier.add(new KSNotification("Error requesting data model.", false, true, 5000)); |
826 | 0 | } |
827 | |
|
828 | |
}); |
829 | |
|
830 | |
} else { |
831 | 0 | doWorkflowApprove(); |
832 | |
} |
833 | |
|
834 | |
} |
835 | |
|
836 | |
} else { |
837 | 0 | submitSuccessDialog.hide(); |
838 | |
} |
839 | 0 | } |
840 | |
|
841 | |
private void doWorkflowApprove() { |
842 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.APPROVE.getType()); |
843 | |
|
844 | 0 | workflowRpcServiceAsync.approveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
845 | |
@Override |
846 | |
public void handleFailure(Throwable caught) { |
847 | 0 | submitSuccessDialog.hide(); |
848 | 0 | Window.alert("Error approving Proposal"); |
849 | 0 | } |
850 | |
|
851 | |
public void onSuccess(Boolean result) { |
852 | 0 | submitSuccessDialog.hide(); |
853 | 0 | if (result) { |
854 | 0 | updateWorkflow(dataModel); |
855 | 0 | if (submitCallback != null) { |
856 | 0 | submitCallback.exec(result); |
857 | |
} |
858 | |
|
859 | 0 | KSNotifier.add(new KSNotification("Proposal was approved", false)); |
860 | |
} else { |
861 | 0 | Window.alert("Error approving Proposal"); |
862 | |
} |
863 | 0 | } |
864 | |
}); |
865 | |
|
866 | 0 | } |
867 | |
}); |
868 | |
|
869 | 0 | if(approveDialogView.getField("proposal/prevEndTerm") != null){ |
870 | |
|
871 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
872 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
873 | |
|
874 | |
@Override |
875 | |
public void onKeyUp(KeyUpEvent event) { |
876 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(((KSPicker) (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget())).getDisplayValue() == "") ){ |
877 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(true); |
878 | |
} else { |
879 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
880 | |
} |
881 | 0 | } |
882 | |
|
883 | |
}); |
884 | |
|
885 | 0 | if (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget() instanceof KSPicker) { |
886 | 0 | ((KSPicker) (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget())).addSelectionChangeHandler(new SelectionChangeHandler(){ |
887 | |
|
888 | |
@Override |
889 | |
public void onSelectionChange(SelectionChangeEvent event) { |
890 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(((KSPicker) (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget())).getDisplayValue() == "") ){ |
891 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(true); |
892 | |
} else { |
893 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
894 | |
} |
895 | 0 | } |
896 | |
|
897 | |
}); |
898 | |
} |
899 | |
} else { |
900 | |
|
901 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
902 | |
|
903 | |
@Override |
904 | |
public void onKeyUp(KeyUpEvent event) { |
905 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
906 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(true); |
907 | |
} else { |
908 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
909 | |
} |
910 | 0 | } |
911 | |
|
912 | |
}); |
913 | |
|
914 | |
} |
915 | |
|
916 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Approve Proposal"); |
917 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are approving the " + proposalName +" proposal"); |
918 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
919 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
920 | 0 | required.setVisible(true); |
921 | 0 | HorizontalPanel rationalePanel = new HorizontalPanel(); |
922 | 0 | rationalePanel.add(fieldLabel); |
923 | 0 | rationalePanel.add(required); |
924 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
925 | 0 | dialogPanel.clear(); |
926 | 0 | dialogPanel.add(headerTitle); |
927 | 0 | dialogPanel.add(dialogLabel); |
928 | 0 | dialogPanel.add(rationalePanel); |
929 | 0 | dialogPanel.add(rationaleEditor); |
930 | 0 | if(approveDialogView!=null && !approveDialogView.getFields().isEmpty()){ |
931 | 0 | dialogPanel.add(approveDialogView.asWidget()); |
932 | |
} |
933 | 0 | dialogPanel.add(approveCancelButtons); |
934 | 0 | dialogPanel.setSize("580px", "450px"); |
935 | |
|
936 | |
|
937 | 0 | submitSuccessDialog.show(); |
938 | 0 | } |
939 | |
}); |
940 | 0 | return wfApproveItem; |
941 | |
} |
942 | |
|
943 | |
private KSMenuItemData getWithdrawItem() { |
944 | |
KSMenuItemData wfWithdrawItem; |
945 | |
|
946 | 0 | wfWithdrawItem = new KSMenuItemData("Withdraw Proposal", new ClickHandler() { |
947 | |
public void onClick(ClickEvent event) { |
948 | 0 | setupSubmitSuccessDialog(); |
949 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
950 | 0 | final ConfirmCancelGroup withdrawButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() { |
951 | |
|
952 | |
@Override |
953 | |
public void exec(ConfirmCancelEnum result) { |
954 | 0 | if (!result.name().equals("CANCEL")) { |
955 | 0 | if (rationaleEditor.getText().trim().equals("")) { |
956 | 0 | required.setText("Please enter the decision rationale"); |
957 | |
} else { |
958 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.WITHDRAW.getType()); |
959 | |
|
960 | 0 | workflowRpcServiceAsync.withdrawDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
961 | |
@Override |
962 | |
public void handleFailure(Throwable caught) { |
963 | 0 | submitSuccessDialog.hide(); |
964 | 0 | Window.alert("Error withdrawing Proposal"); |
965 | 0 | } |
966 | |
|
967 | |
public void onSuccess(Boolean result) { |
968 | 0 | submitSuccessDialog.hide(); |
969 | 0 | if (result) { |
970 | 0 | updateWorkflow(dataModel); |
971 | 0 | if (submitCallback != null) { |
972 | 0 | submitCallback.exec(result); |
973 | |
} |
974 | |
|
975 | 0 | KSNotifier.add(new KSNotification("Proposal will be withdrawn", false)); |
976 | |
} else { |
977 | 0 | Window.alert("Error withdrawing Proposal"); |
978 | |
} |
979 | 0 | } |
980 | |
}); |
981 | |
} |
982 | |
|
983 | |
} else { |
984 | 0 | submitSuccessDialog.hide(); |
985 | |
} |
986 | 0 | } |
987 | |
}); |
988 | |
|
989 | 0 | withdrawButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
990 | |
|
991 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
992 | |
|
993 | |
@Override |
994 | |
public void onKeyUp(KeyUpEvent event) { |
995 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
996 | 0 | withdrawButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
997 | |
} else { |
998 | 0 | withdrawButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
999 | |
} |
1000 | 0 | } |
1001 | |
|
1002 | |
}); |
1003 | |
|
1004 | |
|
1005 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Withdraw Proposal"); |
1006 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are withdrawing the " + proposalName + " proposal"); |
1007 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
1008 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
1009 | 0 | required.setVisible(true); |
1010 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
1011 | 0 | dialogPanel.clear(); |
1012 | 0 | dialogPanel.add(headerTitle); |
1013 | 0 | dialogPanel.add(dialogLabel); |
1014 | 0 | dialogPanel.add(fieldLabel); |
1015 | 0 | dialogPanel.add(required); |
1016 | 0 | dialogPanel.add(rationaleEditor); |
1017 | 0 | dialogPanel.add(withdrawButton); |
1018 | 0 | dialogPanel.setSize("580px", "400px"); |
1019 | |
|
1020 | 0 | submitSuccessDialog.show(); |
1021 | 0 | } |
1022 | |
}); |
1023 | 0 | return wfWithdrawItem; |
1024 | |
} |
1025 | |
|
1026 | |
private KSMenuItemData getBlanketApproveItem() { |
1027 | |
KSMenuItemData wfBlanketApproveItem; |
1028 | |
|
1029 | 0 | wfBlanketApproveItem = new KSMenuItemData("Blanket Approve Proposal", new ClickHandler() { |
1030 | |
public void onClick(ClickEvent event) { |
1031 | 0 | setupSubmitSuccessDialog(); |
1032 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
1033 | 0 | final ConfirmCancelGroup blanketApprovalButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() { |
1034 | |
|
1035 | |
@Override |
1036 | |
public void exec(ConfirmCancelEnum result) { |
1037 | 0 | if (!result.name().equals("CANCEL")) { |
1038 | 0 | if (rationaleEditor.getText().trim().equals("")) { |
1039 | 0 | required.setText("Please enter the decision rationale"); |
1040 | |
} else { |
1041 | |
|
1042 | 0 | if(blanketApproveDialogView!=null){ |
1043 | |
|
1044 | 0 | parentController.requestModel(new ModelRequestCallback<DataModel>(){ |
1045 | |
|
1046 | |
@Override |
1047 | |
public void onModelReady(final DataModel model) { |
1048 | 0 | blanketApproveDialogView.updateModel(); |
1049 | 0 | if(parentController instanceof WorkflowEnhancedNavController){ |
1050 | 0 | ((WorkflowEnhancedNavController)parentController).getMetadataForFinalState(new KSAsyncCallback<Metadata>(){ |
1051 | |
|
1052 | |
@Override |
1053 | |
public void onSuccess( |
1054 | |
Metadata metadata) { |
1055 | 0 | model.validateForMetadata(metadata, new Callback<List<ValidationResultInfo>>() { |
1056 | |
@Override |
1057 | |
public void exec(List<ValidationResultInfo> results) { |
1058 | |
|
1059 | |
|
1060 | |
|
1061 | |
|
1062 | 0 | if(ErrorLevel.OK.equals(blanketApproveDialogView.processValidationResults(results))){ |
1063 | 0 | List<String> ignoreFields = new ArrayList<String>(ignoredApproveDialogFields); |
1064 | 0 | for(FieldDescriptor fd:blanketApproveDialogView.getFields()){ |
1065 | 0 | ignoreFields.add(fd.getFieldKey()); |
1066 | |
} |
1067 | 0 | if(!ValidationResultInfo.hasValidationErrors(results,ErrorLevel.WARN,ignoreFields)){ |
1068 | |
|
1069 | 0 | SaveActionEvent saveActionEvent = new SaveActionEvent(); |
1070 | 0 | saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){ |
1071 | |
public void onActionComplete(ActionEvent action) { |
1072 | 0 | doBlanketApprove(); |
1073 | 0 | } |
1074 | |
}); |
1075 | 0 | parentController.fireApplicationEvent(saveActionEvent); |
1076 | 0 | }else{ |
1077 | 0 | submitSuccessDialog.hide(); |
1078 | 0 | KSNotifier.add(new KSNotification("Unable to blanket approve, please enter all data required for final approval.", false, true, 5000)); |
1079 | |
} |
1080 | 0 | }else{ |
1081 | 0 | KSNotifier.add(new KSNotification("Unable to blanket approve, please enter all data required for final approval.", false, true, 5000)); |
1082 | |
} |
1083 | 0 | } |
1084 | |
}); |
1085 | 0 | } |
1086 | |
|
1087 | |
}); |
1088 | |
} |
1089 | 0 | } |
1090 | |
|
1091 | |
@Override |
1092 | |
public void onRequestFail( |
1093 | |
Throwable cause) { |
1094 | 0 | KSNotifier.add(new KSNotification("Error requesting data model.", false, true, 5000)); |
1095 | 0 | } |
1096 | |
|
1097 | |
}); |
1098 | |
|
1099 | |
}else{ |
1100 | 0 | doBlanketApprove(); |
1101 | |
} |
1102 | |
|
1103 | |
|
1104 | |
} |
1105 | |
} else { |
1106 | 0 | submitSuccessDialog.hide(); |
1107 | 0 | updateWorkflowActionsWidget(); |
1108 | |
} |
1109 | 0 | } |
1110 | |
|
1111 | |
private void doBlanketApprove() { |
1112 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.BLANKET_APPROVE.getType()); |
1113 | 0 | workflowRpcServiceAsync.blanketApproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
1114 | |
@Override |
1115 | |
public void handleFailure(Throwable caught) { |
1116 | 0 | submitSuccessDialog.hide(); |
1117 | 0 | Window.alert("Error blanket approving Proposal"); |
1118 | 0 | } |
1119 | |
|
1120 | |
public void onSuccess(Boolean result) { |
1121 | 0 | submitSuccessDialog.hide(); |
1122 | 0 | if (result) { |
1123 | |
|
1124 | |
|
1125 | |
|
1126 | 0 | enableWorkflowActionsWidgets(false); |
1127 | |
|
1128 | 0 | updateWorkflow(dataModel); |
1129 | 0 | if (submitCallback != null) { |
1130 | 0 | submitCallback.exec(result); |
1131 | |
} |
1132 | |
|
1133 | 0 | KSNotifier.add(new KSNotification("Proposal will be blanket approved", false)); |
1134 | |
} else { |
1135 | 0 | Window.alert("Error blanket approving Proposal"); |
1136 | |
} |
1137 | 0 | } |
1138 | |
}); |
1139 | 0 | } |
1140 | |
}); |
1141 | |
|
1142 | 0 | blanketApprovalButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1143 | |
|
1144 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
1145 | |
|
1146 | |
@Override |
1147 | |
public void onKeyUp(KeyUpEvent event) { |
1148 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
1149 | 0 | blanketApprovalButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
1150 | |
} else { |
1151 | 0 | blanketApprovalButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1152 | |
} |
1153 | 0 | } |
1154 | |
|
1155 | |
}); |
1156 | |
|
1157 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Blanket Approve Proposal"); |
1158 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are blanket approving the " + proposalName + " proposal"); |
1159 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
1160 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
1161 | 0 | required.setVisible(true); |
1162 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
1163 | 0 | dialogPanel.clear(); |
1164 | 0 | dialogPanel.add(headerTitle); |
1165 | 0 | dialogPanel.add(dialogLabel); |
1166 | 0 | dialogPanel.add(fieldLabel); |
1167 | 0 | dialogPanel.add(required); |
1168 | 0 | dialogPanel.add(rationaleEditor); |
1169 | 0 | if(blanketApproveDialogView!=null && !blanketApproveDialogView.getFields().isEmpty()){ |
1170 | 0 | dialogPanel.add(blanketApproveDialogView.asWidget()); |
1171 | |
} |
1172 | 0 | dialogPanel.add(blanketApprovalButton); |
1173 | 0 | dialogPanel.setSize("580px", "400px"); |
1174 | |
|
1175 | 0 | submitSuccessDialog.show(); |
1176 | 0 | } |
1177 | |
}); |
1178 | 0 | return wfBlanketApproveItem; |
1179 | |
} |
1180 | |
|
1181 | |
|
1182 | |
|
1183 | |
|
1184 | |
|
1185 | |
|
1186 | |
|
1187 | |
public void blanketApprove(final Callback<Boolean> onSuccessCallback){ |
1188 | 0 | updateWorkflowIdFromModel(dataModel); |
1189 | 0 | workflowRpcServiceAsync.blanketApproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
1190 | |
@Override |
1191 | |
public void handleFailure(Throwable caught) { |
1192 | 0 | Window.alert("Error blanket approving Proposal"); |
1193 | 0 | } |
1194 | |
|
1195 | |
public void onSuccess(Boolean result) { |
1196 | 0 | if (result) { |
1197 | 0 | onSuccessCallback.exec(true); |
1198 | |
} else { |
1199 | 0 | Window.alert("Error blanket approving Proposal"); |
1200 | |
} |
1201 | 0 | } |
1202 | |
}); |
1203 | 0 | } |
1204 | |
|
1205 | |
|
1206 | |
|
1207 | |
|
1208 | |
|
1209 | |
|
1210 | |
|
1211 | |
public void cancel(final Callback<Boolean> onSuccessCallback){ |
1212 | 0 | ConfirmationDialog confirmCancelDialog = getConfirmationCancelProposalDialog(onSuccessCallback); |
1213 | 0 | confirmCancelDialog.show(); |
1214 | 0 | } |
1215 | |
|
1216 | |
|
1217 | |
protected KSDropDown setUpReturnToPreviousDropDown(String workflowId) { |
1218 | |
|
1219 | 0 | final KSDropDown nodeNameDropDown = new KSDropDown(); |
1220 | 0 | nodeNameDropDown.setBlankFirstItem(true); |
1221 | 0 | workflowRpcServiceAsync.getPreviousRouteNodeNames(workflowId, new KSAsyncCallback<List<String>>() { |
1222 | |
@Override |
1223 | |
public void handleFailure(Throwable caught) { |
1224 | 0 | Window.alert("Error getting previous node names for Proposal"); |
1225 | 0 | } |
1226 | |
|
1227 | |
public void onSuccess(List<String> result) { |
1228 | 0 | SimpleListItems nodeNameList = new SimpleListItems(); |
1229 | 0 | for (String nodeName : result) { |
1230 | 0 | nodeNameList.addItem(nodeName, nodeName); |
1231 | |
} |
1232 | 0 | nodeNameDropDown.setListItems(nodeNameList); |
1233 | 0 | } |
1234 | |
}); |
1235 | 0 | nodeNameDropDown.setInitialized(true); |
1236 | 0 | return nodeNameDropDown; |
1237 | |
} |
1238 | |
|
1239 | |
private KSMenuItemData getReturnToPreviousItem() { |
1240 | |
KSMenuItemData wfReturnToPreviousItem; |
1241 | |
|
1242 | 0 | wfReturnToPreviousItem = new KSMenuItemData("Return Proposal to Previous Node", new ClickHandler() { |
1243 | |
public void onClick(ClickEvent event) { |
1244 | 0 | setupSubmitSuccessDialog(); |
1245 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
1246 | 0 | final KSDropDown nodeNameDropDown = setUpReturnToPreviousDropDown(workflowId); |
1247 | 0 | final ConfirmCancelGroup returnButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() { |
1248 | |
|
1249 | |
@Override |
1250 | |
public void exec(ConfirmCancelEnum result) { |
1251 | 0 | if (!result.name().equals("CANCEL")) { |
1252 | 0 | if ((rationaleEditor.getText().trim().equals("")) && (nodeNameDropDown.getSelectedItem()==null || nodeNameDropDown.getSelectedItem().trim().equals(""))) { |
1253 | 0 | required.setText("Please enter the decision rationale and select a node name to return to"); |
1254 | 0 | } else if (rationaleEditor.getText().trim().equals("")) { |
1255 | 0 | required.setText("Please enter the decision rationale"); |
1256 | 0 | } else if (nodeNameDropDown.getSelectedItem()==null || nodeNameDropDown.getSelectedItem().trim().equals("")) { |
1257 | 0 | required.setText("Please select a node name to return to"); |
1258 | |
} else { |
1259 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.RETURN_TO_PREVIOUS.getType()); |
1260 | 0 | String nodeName = nodeNameDropDown.getSelectedItem().trim(); |
1261 | 0 | workflowRpcServiceAsync.returnDocumentWithId(workflowId, nodeName, new KSAsyncCallback<Boolean>() { |
1262 | |
@Override |
1263 | |
public void handleFailure(Throwable caught) { |
1264 | 0 | submitSuccessDialog.hide(); |
1265 | 0 | Window.alert("Error returning the Proposal to a previous node"); |
1266 | 0 | } |
1267 | |
|
1268 | |
public void onSuccess(Boolean result) { |
1269 | 0 | submitSuccessDialog.hide(); |
1270 | 0 | if (result) { |
1271 | 0 | updateWorkflow(dataModel); |
1272 | 0 | if (submitCallback != null) { |
1273 | 0 | submitCallback.exec(result); |
1274 | |
} |
1275 | |
|
1276 | 0 | KSNotifier.add(new KSNotification("Proposal was returned", false)); |
1277 | |
} else { |
1278 | 0 | Window.alert("Error returning the Proposal to a previous node"); |
1279 | |
} |
1280 | 0 | } |
1281 | |
}); |
1282 | 0 | } |
1283 | |
|
1284 | |
} else { |
1285 | 0 | submitSuccessDialog.hide(); |
1286 | |
} |
1287 | 0 | } |
1288 | |
}); |
1289 | |
|
1290 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1291 | |
|
1292 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
1293 | |
|
1294 | |
@Override |
1295 | |
public void onKeyUp(KeyUpEvent event) { |
1296 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(nodeNameDropDown.getSelectedItem() == null)){ |
1297 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
1298 | |
} else { |
1299 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1300 | |
} |
1301 | 0 | } |
1302 | |
|
1303 | |
}); |
1304 | |
|
1305 | 0 | nodeNameDropDown.addSelectionChangeHandler(new SelectionChangeHandler(){ |
1306 | |
|
1307 | |
@Override |
1308 | |
public void onSelectionChange(SelectionChangeEvent event) { |
1309 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(nodeNameDropDown.getSelectedItem() == null)){ |
1310 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
1311 | |
} else { |
1312 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1313 | |
} |
1314 | 0 | } |
1315 | |
|
1316 | |
}); |
1317 | |
|
1318 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Return Proposal to Previous Node"); |
1319 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are returning the " + proposalName + " proposal to a previous node"); |
1320 | 0 | SectionTitle nnFieldLabel = SectionTitle.generateH4Title("Workflow Node Name"); |
1321 | 0 | SectionTitle drFieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
1322 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
1323 | 0 | required.setVisible(true); |
1324 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
1325 | 0 | dialogPanel.clear(); |
1326 | 0 | dialogPanel.add(headerTitle); |
1327 | 0 | dialogPanel.add(dialogLabel); |
1328 | 0 | dialogPanel.add(nnFieldLabel); |
1329 | 0 | dialogPanel.add(nodeNameDropDown); |
1330 | 0 | dialogPanel.add(drFieldLabel); |
1331 | 0 | dialogPanel.add(required); |
1332 | 0 | dialogPanel.add(rationaleEditor); |
1333 | 0 | dialogPanel.add(returnButton); |
1334 | 0 | dialogPanel.setSize("580px", "400px"); |
1335 | |
|
1336 | 0 | submitSuccessDialog.show(); |
1337 | 0 | } |
1338 | |
}); |
1339 | 0 | return wfReturnToPreviousItem; |
1340 | |
} |
1341 | |
|
1342 | |
private void addRationale(KSRichEditor rationaleEditor, String rationaleType) { |
1343 | 0 | CommentInfo newDecisionRationale = new CommentInfo(); |
1344 | 0 | RichTextInfo text = new RichTextInfo(); |
1345 | 0 | text.setFormatted(rationaleEditor.getHTML()); |
1346 | 0 | text.setPlain(rationaleEditor.getText()); |
1347 | 0 | newDecisionRationale.setReferenceTypeKey(PROPOSAL_REF_TYPE_KEY); |
1348 | 0 | newDecisionRationale.setReferenceId(proposalId); |
1349 | 0 | newDecisionRationale.setState(DtoState.ACTIVE.toString()); |
1350 | 0 | newDecisionRationale.setCommentText(text); |
1351 | 0 | newDecisionRationale.setType(rationaleType); |
1352 | |
|
1353 | |
try { |
1354 | 0 | commentServiceAsync.addComment(proposalId, PROPOSAL_REF_TYPE_KEY, newDecisionRationale, new KSAsyncCallback<CommentInfo>() { |
1355 | |
|
1356 | |
@Override |
1357 | |
public void handleFailure(Throwable caught) { |
1358 | 0 | GWT.log("Add Comment Failed", caught); |
1359 | 0 | } |
1360 | |
|
1361 | |
@Override |
1362 | |
public void onSuccess(CommentInfo result) { |
1363 | 0 | System.out.println("Rationale Added successfully"); |
1364 | 0 | } |
1365 | |
}); |
1366 | 0 | } catch (Exception e) { |
1367 | 0 | GWT.log("Add Comment Failed", e); |
1368 | 0 | } |
1369 | 0 | } |
1370 | |
|
1371 | |
private KSMenuItemData getStartItem() { |
1372 | |
KSMenuItemData wfStartWorkflowItem; |
1373 | 0 | wfStartWorkflowItem = new KSMenuItemData("Submit Proposal", new ClickHandler(){ |
1374 | |
public void onClick(ClickEvent event) { |
1375 | |
|
1376 | 0 | dataModel.validateNextState(new Callback<List<ValidationResultInfo>>() { |
1377 | |
@Override |
1378 | |
public void exec(List<ValidationResultInfo> result) { |
1379 | |
|
1380 | 0 | boolean isValid = parentController.isValid(result, false); |
1381 | 0 | if(isValid){ |
1382 | 0 | dialog.show(); |
1383 | |
} |
1384 | |
else{ |
1385 | 0 | Window.alert("Unable to submit to workflow. Please check sections for missing fields."); |
1386 | |
} |
1387 | 0 | } |
1388 | |
}); |
1389 | 0 | } |
1390 | |
|
1391 | |
}); |
1392 | 0 | return wfStartWorkflowItem; |
1393 | |
} |
1394 | |
|
1395 | |
private KSMenuItemData getCancelWorkflowItem() { |
1396 | |
KSMenuItemData wfCancelWorkflowItem; |
1397 | 0 | wfCancelWorkflowItem = new KSMenuItemData("Cancel Proposal", new ClickHandler() { |
1398 | |
public void onClick(ClickEvent event) { |
1399 | 0 | ConfirmationDialog confirmationCancelProposal = getConfirmationCancelProposalDialog(null); |
1400 | 0 | confirmationCancelProposal.show(); |
1401 | 0 | } |
1402 | |
}); |
1403 | 0 | return wfCancelWorkflowItem; |
1404 | |
} |
1405 | |
|
1406 | |
protected ConfirmationDialog getConfirmationCancelProposalDialog (final Callback<Boolean> onSuccessCallback){ |
1407 | 0 | final ConfirmationDialog confirmationCancelProposal = new ConfirmationDialog("Cancel Proposal","This action is not reversible and all data will be lost. Do you wish to cancel this proposal?"); |
1408 | |
|
1409 | 0 | confirmationCancelProposal.getConfirmButton().setText("Yes, cancel proposal"); |
1410 | 0 | confirmationCancelProposal.getCancelButton().setStyleName(ButtonStyle.PRIMARY_SMALL.getStyle()); |
1411 | 0 | confirmationCancelProposal.getCancelButton().setText("No, return to proposal"); |
1412 | |
|
1413 | 0 | confirmationCancelProposal.getConfirmButton().addClickHandler(new ClickHandler(){ |
1414 | |
@Override |
1415 | |
public void onClick(ClickEvent event) { |
1416 | 0 | workflowRpcServiceAsync.cancelDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
1417 | |
@Override |
1418 | |
public void handleFailure(Throwable caught) { |
1419 | 0 | confirmationCancelProposal.hide(); |
1420 | 0 | Window.alert("Error Cancelling Proposal"); |
1421 | 0 | } |
1422 | |
public void onSuccess(Boolean result) { |
1423 | 0 | confirmationCancelProposal.hide(); |
1424 | 0 | if (result) { |
1425 | 0 | updateWorkflow(dataModel); |
1426 | 0 | if (submitCallback != null) { |
1427 | 0 | submitCallback.exec(true); |
1428 | |
} |
1429 | 0 | if (onSuccessCallback != null){ |
1430 | 0 | onSuccessCallback.exec(true); |
1431 | |
} |
1432 | |
|
1433 | 0 | KSNotifier.add(new KSNotification("Proposal will be Cancelled", false)); |
1434 | |
} else { |
1435 | 0 | Window.alert("Error Cancelling Proposal"); |
1436 | |
} |
1437 | 0 | } |
1438 | |
}); |
1439 | |
|
1440 | 0 | } |
1441 | |
|
1442 | |
}); |
1443 | |
|
1444 | 0 | return confirmationCancelProposal; |
1445 | |
} |
1446 | |
|
1447 | |
private void setWorkflowStatus(String statusCd){ |
1448 | 0 | String statusTranslation = ""; |
1449 | 0 | if (WorkflowConstants.ROUTE_HEADER_SAVED_CD.equals(statusCd)){ |
1450 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_SAVED_LABEL_KEY); |
1451 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_INITIATED_CD.equals(statusCd)){ |
1452 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_INITIATED_LABEL_KEY); |
1453 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_ENROUTE_CD.equals(statusCd)){ |
1454 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_ENROUTE_LABEL_KEY); |
1455 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_APPROVED_CD.equals(statusCd)){ |
1456 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_APPROVED_LABEL_KEY); |
1457 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_CANCEL_CD.equals(statusCd)){ |
1458 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_CANCEL_LABEL_KEY); |
1459 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusCd)){ |
1460 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_EXCEPTION_LABEL_KEY); |
1461 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_DISAPPROVED_CD.equals(statusCd)){ |
1462 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_DISAPPROVED_LABEL_KEY); |
1463 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_FINAL_CD.equals(statusCd)){ |
1464 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_APPROVED_LABEL_KEY); |
1465 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_DISAPPROVE_CANCEL_CD.equals(statusCd)){ |
1466 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_DISAPPROVE_CANCEL_LABEL_KEY); |
1467 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_PROCESSED_CD.equals(statusCd)){ |
1468 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_APPROVED_LABEL_KEY); |
1469 | |
} else { |
1470 | 0 | statusTranslation = statusCd; |
1471 | |
} |
1472 | |
|
1473 | 0 | workflowStatusLabel.setText("Status: " + statusTranslation); |
1474 | 0 | } |
1475 | |
|
1476 | |
private void setProposalStatus(String statusCode) { |
1477 | 0 | String statusLabel = Application.getApplicationContext() |
1478 | |
.getUILabel("common", null, null, "proposalStatusLabel"); |
1479 | 0 | String status = Application.getApplicationContext().getUILabel("common", null, null, statusCode); |
1480 | |
|
1481 | 0 | proposalStatusLabel.setText(statusLabel + ": " + status); |
1482 | 0 | } |
1483 | |
|
1484 | |
|
1485 | |
|
1486 | |
|
1487 | |
|
1488 | |
|
1489 | |
public void setModelName(String modelName) { |
1490 | 0 | this.modelName = modelName; |
1491 | 0 | } |
1492 | |
|
1493 | |
|
1494 | |
|
1495 | |
|
1496 | |
|
1497 | |
public void setProposalPath(String proposalPath) { |
1498 | 0 | this.proposalPath = proposalPath; |
1499 | 0 | } |
1500 | |
|
1501 | |
public void setWorkflowRpcService(WorkflowRpcServiceAsync workflowRpcServiceAsync){ |
1502 | 0 | this.workflowRpcServiceAsync = workflowRpcServiceAsync; |
1503 | 0 | } |
1504 | |
|
1505 | |
|
1506 | |
public void refresh(){ |
1507 | 0 | updateApproveFields(); |
1508 | 0 | updateWorkflow(dataModel); |
1509 | 0 | } |
1510 | |
|
1511 | |
private String getLabel(String labelKey) { |
1512 | 0 | return Application.getApplicationContext().getUILabel("common", null, null, labelKey); |
1513 | |
} |
1514 | |
|
1515 | |
public void getDataIdFromWorkflowId(String workflowId, AsyncCallback<String> callback){ |
1516 | 0 | workflowRpcServiceAsync.getDataIdFromWorkflowId(workflowId, callback); |
1517 | 0 | } |
1518 | |
|
1519 | |
public void addSubmitCallback(Callback<Boolean> callback) { |
1520 | 0 | this.submitCallback = callback; |
1521 | |
|
1522 | 0 | } |
1523 | |
|
1524 | |
public List<KSMenuItemData> getAdditionalItems() { |
1525 | 0 | return additionalItems; |
1526 | |
} |
1527 | |
|
1528 | |
public void addIgnoreDialogField(String string) { |
1529 | 0 | ignoredApproveDialogFields.add(string); |
1530 | 0 | } |
1531 | |
|
1532 | |
public VerticalSectionView getApproveDialogue() { |
1533 | 0 | return approveDialogView; |
1534 | |
} |
1535 | |
|
1536 | |
public void progressiveEnableFields() { |
1537 | 0 | if (getApproveDialogue() != null) { |
1538 | |
|
1539 | 0 | FieldDescriptor prevEndTerm = approveDialogView.getField("proposal/prevEndTerm"); |
1540 | |
|
1541 | 0 | if (prevEndTerm != null) { |
1542 | 0 | approveDialogView.getWidget(0).setVisible(true); |
1543 | 0 | approveDialogView.getField("proposal/prevEndTerm").getMetadata().getConstraints().get(0).setMinOccurs(1); |
1544 | 0 | approveDialogView.getField("proposal/prevEndTerm").getFieldElement().setRequiredString("requiredMarker", "ks-form-module-elements-required"); |
1545 | 0 | approveDialogView.getField("startTerm").getFieldWidget().setVisible(true); |
1546 | |
} else { |
1547 | 0 | approveDialogView.getWidget(0).setVisible(false); |
1548 | 0 | approveDialogView.getField("startTerm").getFieldWidget().setVisible(false); |
1549 | |
} |
1550 | |
} |
1551 | 0 | } |
1552 | |
|
1553 | |
} |