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 | |
|
445 | |
public void doValidationCheck(Callback<List<ValidationResultInfo>> callback){ |
446 | 0 | dataModel.validateNextState(callback); |
447 | 0 | } |
448 | |
|
449 | |
public KSLabel getWorkflowStatusLabel(){ |
450 | 0 | return workflowStatusLabel; |
451 | |
} |
452 | |
|
453 | |
public KSLabel getProposalStatusLabel() { |
454 | 0 | return proposalStatusLabel; |
455 | |
} |
456 | |
|
457 | |
private void updateWorkflowIdFromModel(final DataModel model) { |
458 | 0 | if(model!=null){ |
459 | 0 | String modelProposalId = model.get(QueryPath.parse(proposalPath + "/id")); |
460 | |
|
461 | |
|
462 | 0 | if (modelProposalId != null && !modelProposalId.isEmpty() && !modelProposalId.equals(proposalId)){ |
463 | 0 | proposalId = modelProposalId; |
464 | 0 | workflowId = model.get(QueryPath.parse(proposalPath + "/workflowId")); |
465 | 0 | proposalName = model.get(QueryPath.parse(proposalPath + "/name")); |
466 | |
} |
467 | |
} |
468 | 0 | } |
469 | |
|
470 | |
private void updateWorkflow(DataModel model){ |
471 | 0 | updateWorkflowIdFromModel(model); |
472 | |
|
473 | 0 | if (workflowId != null && !workflowId.isEmpty()){ |
474 | |
|
475 | 0 | workflowRpcServiceAsync.getActionsRequested(workflowId, new KSAsyncCallback<String>(){ |
476 | |
|
477 | |
public void onSuccess(String result) { |
478 | 0 | workflowActions = result; |
479 | 0 | updateWorkflowActionsWidget(); |
480 | 0 | } |
481 | |
}); |
482 | |
|
483 | 0 | workflowRpcServiceAsync.getDocumentStatus(workflowId, new KSAsyncCallback<String>(){ |
484 | |
@Override |
485 | |
public void handleFailure(Throwable caught) { |
486 | 0 | setWorkflowStatus("Unknown"); |
487 | 0 | } |
488 | |
|
489 | |
@Override |
490 | |
public void onSuccess(String result) { |
491 | 0 | setWorkflowStatus(result); |
492 | 0 | } |
493 | |
}); |
494 | 0 | proposalServiceAsync.getProposalByWorkflowId(workflowId, new KSAsyncCallback<ProposalInfo>() { |
495 | |
@Override |
496 | |
public void handleFailure(Throwable caught) { |
497 | 0 | setProposalStatus("Unknown"); |
498 | 0 | } |
499 | |
|
500 | |
@Override |
501 | |
public void onSuccess(ProposalInfo result) { |
502 | 0 | setProposalStatus(result.getState()); |
503 | 0 | } |
504 | |
}); |
505 | |
} else { |
506 | 0 | setWorkflowStatus("Draft"); |
507 | 0 | setProposalStatus("Draft"); |
508 | |
} |
509 | 0 | } |
510 | |
|
511 | |
private void updateWorkflowActionsWidget(){ |
512 | 0 | items.clear(); |
513 | |
|
514 | |
|
515 | |
|
516 | 0 | if (workflowWidgetsEnabled){ |
517 | |
|
518 | 0 | String workflowNode = null; |
519 | 0 | if(dataModel!=null){ |
520 | 0 | workflowNode = dataModel.get("proposal/workflowNode"); |
521 | |
} |
522 | |
|
523 | 0 | if(workflowActions.contains("S")){ |
524 | 0 | items.add(wfStartWorkflowItem); |
525 | |
} |
526 | 0 | if(workflowActions.contains("C")){ |
527 | 0 | items.add(wfCancelWorkflowItem); |
528 | |
} |
529 | 0 | if(workflowActions.contains("A")){ |
530 | 0 | items.add(wfApproveItem); |
531 | |
|
532 | 0 | if("PreRoute".equals(workflowNode)){ |
533 | 0 | wfApproveItem.setLabel("Resubmit Proposal"); |
534 | |
}else{ |
535 | 0 | wfApproveItem.setLabel("Approve Proposal"); |
536 | |
|
537 | 0 | items.add(wfDisApproveItem); |
538 | |
} |
539 | |
} |
540 | 0 | if(workflowActions.contains("K")){ |
541 | 0 | items.add(wfAcknowledgeItem); |
542 | |
} |
543 | 0 | if(workflowActions.contains("F")){ |
544 | 0 | items.add(wfFYIWorkflowItem); |
545 | |
} |
546 | 0 | if(workflowActions.contains("R")){ |
547 | |
|
548 | |
|
549 | 0 | if(!"PreRoute".equals(workflowNode)){ |
550 | 0 | items.add(wfReturnToPreviousItem); |
551 | |
} |
552 | |
} |
553 | 0 | if(workflowActions.contains("B")){ |
554 | 0 | items.add(wfBlanketApproveItem); |
555 | |
} |
556 | 0 | if(workflowActions.contains("W")){ |
557 | 0 | items.add(wfWithdrawItem); |
558 | |
} |
559 | 0 | } else { |
560 | 0 | if(workflowActions.contains("C")){ |
561 | 0 | items.add(wfCancelWorkflowItem); |
562 | |
} |
563 | 0 | if(workflowActions.contains("K")){ |
564 | 0 | items.add(wfAcknowledgeItem); |
565 | |
} |
566 | 0 | if(workflowActions.contains("F")){ |
567 | 0 | items.add(wfFYIWorkflowItem); |
568 | |
} |
569 | 0 | if(workflowActions.contains("W")){ |
570 | 0 | items.add(wfWithdrawItem); |
571 | |
} |
572 | 0 | if(workflowActions.contains("A")){ |
573 | 0 | items.add(wfDisApproveItem); |
574 | |
} |
575 | |
} |
576 | |
|
577 | |
|
578 | 0 | items.addAll(additionalItems); |
579 | |
|
580 | 0 | for(StylishDropDown widget: workflowWidgets){ |
581 | |
|
582 | 0 | widget.setItems(items); |
583 | 0 | widget.setEnabled(true); |
584 | 0 | if(items.isEmpty()){ |
585 | 0 | widget.setVisible(false); |
586 | |
} |
587 | |
else{ |
588 | 0 | widget.setVisible(true); |
589 | |
} |
590 | |
} |
591 | 0 | } |
592 | |
|
593 | |
private KSMenuItemData getFYIWorkflowItem() { |
594 | |
KSMenuItemData wfFYIWorkflowItem; |
595 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
596 | 0 | wfFYIWorkflowItem = new KSMenuItemData("FYI Proposal", new ClickHandler(){ |
597 | |
public void onClick(ClickEvent event) { |
598 | 0 | addRationale(rationaleEditor,DecisionRationaleDetail.FYI.getType()); |
599 | 0 | workflowRpcServiceAsync.fyiDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){ |
600 | |
@Override |
601 | |
public void handleFailure(Throwable caught) { |
602 | 0 | Window.alert("Error FYIing Proposal"); |
603 | 0 | } |
604 | |
public void onSuccess( |
605 | |
Boolean result) { |
606 | 0 | if(result){ |
607 | 0 | updateWorkflow(dataModel); |
608 | 0 | if(submitCallback != null){ |
609 | 0 | submitCallback.exec(true); |
610 | |
} |
611 | |
|
612 | 0 | KSNotifier.add(new KSNotification("Proposal was FYIed", false)); |
613 | |
}else{ |
614 | 0 | Window.alert("Error FYIing Proposal"); |
615 | |
} |
616 | 0 | } |
617 | |
|
618 | |
}); |
619 | 0 | } |
620 | |
}); |
621 | 0 | return wfFYIWorkflowItem; |
622 | |
} |
623 | |
|
624 | |
private KSMenuItemData getAcknowledgeItem() { |
625 | |
KSMenuItemData wfAcknowledgeItem; |
626 | 0 | wfAcknowledgeItem = new KSMenuItemData("Acknowledge Proposal", new ClickHandler(){ |
627 | |
public void onClick(ClickEvent event) { |
628 | 0 | setupSubmitSuccessDialog(); |
629 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
630 | 0 | final AcknowledgeCancelGroup approvalButton = new AcknowledgeCancelGroup(new Callback<AcknowledgeCancelEnum>(){ |
631 | |
|
632 | |
@Override |
633 | |
public void exec(AcknowledgeCancelEnum result) { |
634 | 0 | if(!result.name().equals("CANCEL")){ |
635 | 0 | addRationale(rationaleEditor,DecisionRationaleDetail.ACKNOWLEDGE.getType()); |
636 | 0 | workflowRpcServiceAsync.acknowledgeDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){ |
637 | |
@Override |
638 | |
public void handleFailure(Throwable caught) { |
639 | 0 | submitSuccessDialog.hide(); |
640 | 0 | Window.alert("Error acknowledging Proposal"); |
641 | 0 | } |
642 | |
public void onSuccess(Boolean result) { |
643 | 0 | submitSuccessDialog.hide(); |
644 | 0 | if(result){ |
645 | 0 | updateWorkflow(dataModel); |
646 | 0 | if(submitCallback != null){ |
647 | 0 | submitCallback.exec(true); |
648 | |
} |
649 | |
|
650 | 0 | KSNotifier.add(new KSNotification("Proposal was acknowledged", false)); |
651 | |
}else{ |
652 | 0 | Window.alert("Error acknowledging Proposal"); |
653 | |
} |
654 | 0 | } |
655 | |
}); |
656 | |
} |
657 | |
else{ |
658 | 0 | submitSuccessDialog.hide(); |
659 | |
} |
660 | 0 | } |
661 | |
}); |
662 | |
|
663 | 0 | approvalButton.getButton(ButtonEnumerations.AcknowledgeCancelEnum.ACKNOWLEDGE).setEnabled(false); |
664 | |
|
665 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
666 | |
|
667 | |
@Override |
668 | |
public void onKeyUp(KeyUpEvent event) { |
669 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
670 | 0 | approvalButton.getButton(ButtonEnumerations.AcknowledgeCancelEnum.ACKNOWLEDGE).setEnabled(true); |
671 | |
} else { |
672 | 0 | approvalButton.getButton(ButtonEnumerations.AcknowledgeCancelEnum.ACKNOWLEDGE).setEnabled(false); |
673 | |
} |
674 | 0 | } |
675 | |
|
676 | |
}); |
677 | |
|
678 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Acknowledge Proposal"); |
679 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are acknowledging the " + proposalName +" proposal"); |
680 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
681 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
682 | 0 | dialogPanel.clear(); |
683 | 0 | submitSuccessDialog.clearButtons(); |
684 | 0 | submitSuccessDialog.setNonCaptionHeader(headerTitle); |
685 | 0 | dialogPanel.add(dialogLabel); |
686 | 0 | dialogPanel.add(fieldLabel); |
687 | 0 | dialogPanel.add(rationaleEditor); |
688 | 0 | submitSuccessDialog.addButtonGroup(approvalButton); |
689 | 0 | submitSuccessDialog.show(); |
690 | 0 | } |
691 | |
}); |
692 | 0 | return wfAcknowledgeItem; |
693 | |
} |
694 | |
|
695 | |
private KSMenuItemData getDisApproveItem() { |
696 | |
KSMenuItemData wfDisApproveItem; |
697 | 0 | wfDisApproveItem = new KSMenuItemData("Reject Proposal", new ClickHandler(){ |
698 | |
public void onClick(ClickEvent event) { |
699 | 0 | setupSubmitSuccessDialog(); |
700 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
701 | |
|
702 | 0 | final RejectCancelGroup disapprovalButton = new RejectCancelGroup(new Callback<RejectCancelEnum>(){ |
703 | |
|
704 | |
@Override |
705 | |
public void exec(RejectCancelEnum result) { |
706 | 0 | if(!result.name().equals("CANCEL")){ |
707 | 0 | if(rationaleEditor.getText().trim().equals("")){ |
708 | 0 | required.setText("Please enter the decision rationale"); |
709 | |
} |
710 | |
else{ |
711 | 0 | addRationale(rationaleEditor,DecisionRationaleDetail.REJECT.getType()); |
712 | 0 | workflowRpcServiceAsync.disapproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>(){ |
713 | |
@Override |
714 | |
public void handleFailure(Throwable caught) { |
715 | 0 | submitSuccessDialog.hide(); |
716 | 0 | Window.alert("Error rejecting Proposal"); |
717 | 0 | } |
718 | |
public void onSuccess(Boolean result) { |
719 | 0 | submitSuccessDialog.hide(); |
720 | 0 | if(submitCallback != null){ |
721 | 0 | submitCallback.exec(result); |
722 | |
} |
723 | 0 | if(result){ |
724 | 0 | KSNotifier.add(new KSNotification("Proposal was rejected", false)); |
725 | 0 | updateWorkflow(dataModel); |
726 | |
}else{ |
727 | 0 | Window.alert("Error rejecting Proposal"); |
728 | |
} |
729 | 0 | } |
730 | |
|
731 | |
}); |
732 | |
} |
733 | |
|
734 | |
} |
735 | |
else{ |
736 | 0 | submitSuccessDialog.hide(); |
737 | |
} |
738 | 0 | } |
739 | |
}); |
740 | |
|
741 | 0 | disapprovalButton.getButton(ButtonEnumerations.RejectCancelEnum.REJECT).setEnabled(false); |
742 | |
|
743 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
744 | |
|
745 | |
@Override |
746 | |
public void onKeyUp(KeyUpEvent event) { |
747 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
748 | 0 | disapprovalButton.getButton(ButtonEnumerations.RejectCancelEnum.REJECT).setEnabled(true); |
749 | |
} else { |
750 | 0 | disapprovalButton.getButton(ButtonEnumerations.RejectCancelEnum.REJECT).setEnabled(false); |
751 | |
} |
752 | 0 | } |
753 | |
|
754 | |
}); |
755 | |
|
756 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Reject Proposal"); |
757 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are rejecting the " + proposalName +" proposal"); |
758 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
759 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
760 | 0 | required.setVisible(true); |
761 | |
|
762 | |
|
763 | |
|
764 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
765 | 0 | dialogPanel.clear(); |
766 | 0 | submitSuccessDialog.clearButtons(); |
767 | 0 | submitSuccessDialog.setNonCaptionHeader(headerTitle); |
768 | 0 | dialogPanel.add(dialogLabel); |
769 | 0 | dialogPanel.add(fieldLabel); |
770 | 0 | dialogPanel.add(required); |
771 | 0 | dialogPanel.add(rationaleEditor); |
772 | 0 | submitSuccessDialog.addButtonGroup(disapprovalButton); |
773 | 0 | submitSuccessDialog.setWidget(dialogPanel); |
774 | 0 | submitSuccessDialog.show(); |
775 | 0 | } |
776 | |
}); |
777 | 0 | return wfDisApproveItem; |
778 | |
} |
779 | |
|
780 | |
private KSMenuItemData getApproveItem() { |
781 | |
KSMenuItemData wfApproveItem; |
782 | |
|
783 | 0 | wfApproveItem= new KSMenuItemData("Approve Proposal", new ClickHandler(){ |
784 | |
public void onClick(ClickEvent event) { |
785 | 0 | setupSubmitSuccessDialog(); |
786 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
787 | |
|
788 | |
|
789 | |
|
790 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
791 | |
|
792 | 0 | approveCancelButtons.addCallback(new Callback<ButtonEnumerations.ButtonEnum>() { |
793 | |
@Override |
794 | |
public void exec(ButtonEnumerations.ButtonEnum result) { |
795 | 0 | if (result != ButtonEnumerations.ApproveCancelEnum.CANCEL) { |
796 | 0 | if (rationaleEditor.getText().trim().equals("")) { |
797 | 0 | required.setText("Please enter the decision rationale"); |
798 | |
} else { |
799 | 0 | if (approveDialogView != null) { |
800 | |
|
801 | 0 | parentController.requestModel(new ModelRequestCallback<DataModel>() { |
802 | |
|
803 | |
@Override |
804 | |
public void onModelReady(DataModel model) { |
805 | 0 | approveDialogView.updateModel(); |
806 | 0 | model.validateNextState(new Callback<List<ValidationResultInfo>>() { |
807 | |
@Override |
808 | |
public void exec(List<ValidationResultInfo> results) { |
809 | |
|
810 | 0 | if (ErrorLevel.OK.equals(approveDialogView.processValidationResults(results))) { |
811 | |
|
812 | 0 | SaveActionEvent saveActionEvent = new SaveActionEvent(); |
813 | 0 | saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback() { |
814 | |
public void onActionComplete(ActionEvent action) { |
815 | 0 | doWorkflowApprove(); |
816 | 0 | } |
817 | |
}); |
818 | 0 | parentController.fireApplicationEvent(saveActionEvent); |
819 | 0 | } else { |
820 | 0 | KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); |
821 | |
} |
822 | 0 | } |
823 | |
}); |
824 | 0 | } |
825 | |
|
826 | |
@Override |
827 | |
public void onRequestFail(Throwable cause) { |
828 | 0 | KSNotifier.add(new KSNotification("Error requesting data model.", false, true, 5000)); |
829 | 0 | } |
830 | |
|
831 | |
}); |
832 | |
|
833 | |
} else { |
834 | 0 | doWorkflowApprove(); |
835 | |
} |
836 | |
|
837 | |
} |
838 | |
|
839 | |
} else { |
840 | 0 | submitSuccessDialog.hide(); |
841 | |
} |
842 | 0 | } |
843 | |
|
844 | |
private void doWorkflowApprove() { |
845 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.APPROVE.getType()); |
846 | |
|
847 | 0 | workflowRpcServiceAsync.approveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
848 | |
@Override |
849 | |
public void handleFailure(Throwable caught) { |
850 | 0 | submitSuccessDialog.hide(); |
851 | 0 | Window.alert("Error approving Proposal"); |
852 | 0 | } |
853 | |
|
854 | |
public void onSuccess(Boolean result) { |
855 | 0 | submitSuccessDialog.hide(); |
856 | 0 | if (result) { |
857 | 0 | updateWorkflow(dataModel); |
858 | 0 | if (submitCallback != null) { |
859 | 0 | submitCallback.exec(result); |
860 | |
} |
861 | |
|
862 | 0 | KSNotifier.add(new KSNotification("Proposal was approved", false)); |
863 | |
} else { |
864 | 0 | Window.alert("Error approving Proposal"); |
865 | |
} |
866 | 0 | } |
867 | |
}); |
868 | |
|
869 | 0 | } |
870 | |
}); |
871 | |
|
872 | 0 | if(approveDialogView.getField("proposal/prevEndTerm") != null){ |
873 | |
|
874 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
875 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
876 | |
|
877 | |
@Override |
878 | |
public void onKeyUp(KeyUpEvent event) { |
879 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(((KSPicker) (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget())).getDisplayValue() == "") ){ |
880 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(true); |
881 | |
} else { |
882 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
883 | |
} |
884 | 0 | } |
885 | |
|
886 | |
}); |
887 | |
|
888 | 0 | if (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget() instanceof KSPicker) { |
889 | 0 | ((KSPicker) (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget())).addSelectionChangeHandler(new SelectionChangeHandler(){ |
890 | |
|
891 | |
@Override |
892 | |
public void onSelectionChange(SelectionChangeEvent event) { |
893 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(((KSPicker) (approveDialogView.getField("proposal/prevEndTerm").getFieldWidget())).getDisplayValue() == "") ){ |
894 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(true); |
895 | |
} else { |
896 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
897 | |
} |
898 | 0 | } |
899 | |
|
900 | |
}); |
901 | |
} |
902 | |
} else { |
903 | |
|
904 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
905 | |
|
906 | |
@Override |
907 | |
public void onKeyUp(KeyUpEvent event) { |
908 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
909 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(true); |
910 | |
} else { |
911 | 0 | approveCancelButtons.getButton(ButtonEnumerations.ApproveCancelEnum.APPROVE).setEnabled(false); |
912 | |
} |
913 | 0 | } |
914 | |
|
915 | |
}); |
916 | |
|
917 | |
} |
918 | |
|
919 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Approve Proposal"); |
920 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are approving the " + proposalName +" proposal"); |
921 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
922 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
923 | 0 | required.setVisible(true); |
924 | 0 | HorizontalPanel rationalePanel = new HorizontalPanel(); |
925 | 0 | rationalePanel.add(fieldLabel); |
926 | 0 | rationalePanel.add(required); |
927 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
928 | 0 | dialogPanel.clear(); |
929 | 0 | submitSuccessDialog.clearButtons(); |
930 | 0 | submitSuccessDialog.setNonCaptionHeader(headerTitle); |
931 | 0 | dialogPanel.add(dialogLabel); |
932 | 0 | dialogPanel.add(rationalePanel); |
933 | 0 | dialogPanel.add(rationaleEditor); |
934 | 0 | if(approveDialogView!=null && !approveDialogView.getFields().isEmpty()){ |
935 | 0 | dialogPanel.add(approveDialogView.asWidget()); |
936 | |
} |
937 | 0 | submitSuccessDialog.addButtonGroup(approveCancelButtons); |
938 | |
|
939 | 0 | dialogPanel.setHeight("380px"); |
940 | 0 | submitSuccessDialog.show(); |
941 | 0 | } |
942 | |
}); |
943 | 0 | return wfApproveItem; |
944 | |
} |
945 | |
|
946 | |
private KSMenuItemData getWithdrawItem() { |
947 | |
KSMenuItemData wfWithdrawItem; |
948 | |
|
949 | 0 | wfWithdrawItem = new KSMenuItemData("Withdraw Proposal", new ClickHandler() { |
950 | |
public void onClick(ClickEvent event) { |
951 | 0 | setupSubmitSuccessDialog(); |
952 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
953 | 0 | final ConfirmCancelGroup withdrawButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() { |
954 | |
|
955 | |
@Override |
956 | |
public void exec(ConfirmCancelEnum result) { |
957 | 0 | if (!result.name().equals("CANCEL")) { |
958 | 0 | if (rationaleEditor.getText().trim().equals("")) { |
959 | 0 | required.setText("Please enter the decision rationale"); |
960 | |
} else { |
961 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.WITHDRAW.getType()); |
962 | |
|
963 | 0 | workflowRpcServiceAsync.withdrawDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
964 | |
@Override |
965 | |
public void handleFailure(Throwable caught) { |
966 | 0 | submitSuccessDialog.hide(); |
967 | 0 | Window.alert("Error withdrawing Proposal"); |
968 | 0 | } |
969 | |
|
970 | |
public void onSuccess(Boolean result) { |
971 | 0 | submitSuccessDialog.hide(); |
972 | 0 | if (result) { |
973 | 0 | updateWorkflow(dataModel); |
974 | 0 | if (submitCallback != null) { |
975 | 0 | submitCallback.exec(result); |
976 | |
} |
977 | |
|
978 | 0 | KSNotifier.add(new KSNotification("Proposal will be withdrawn", false)); |
979 | |
} else { |
980 | 0 | Window.alert("Error withdrawing Proposal"); |
981 | |
} |
982 | 0 | } |
983 | |
}); |
984 | |
} |
985 | |
|
986 | |
} else { |
987 | 0 | submitSuccessDialog.hide(); |
988 | |
} |
989 | 0 | } |
990 | |
}); |
991 | |
|
992 | 0 | withdrawButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
993 | |
|
994 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
995 | |
|
996 | |
@Override |
997 | |
public void onKeyUp(KeyUpEvent event) { |
998 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
999 | 0 | withdrawButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
1000 | |
} else { |
1001 | 0 | withdrawButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1002 | |
} |
1003 | 0 | } |
1004 | |
|
1005 | |
}); |
1006 | |
|
1007 | |
|
1008 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Withdraw Proposal"); |
1009 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are withdrawing the " + proposalName + " proposal"); |
1010 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
1011 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
1012 | 0 | required.setVisible(true); |
1013 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
1014 | 0 | dialogPanel.clear(); |
1015 | 0 | submitSuccessDialog.clearButtons(); |
1016 | 0 | submitSuccessDialog.setNonCaptionHeader(headerTitle); |
1017 | 0 | dialogPanel.add(dialogLabel); |
1018 | 0 | dialogPanel.add(fieldLabel); |
1019 | 0 | dialogPanel.add(required); |
1020 | 0 | dialogPanel.add(rationaleEditor); |
1021 | 0 | submitSuccessDialog.addButtonGroup(withdrawButton); |
1022 | |
|
1023 | 0 | dialogPanel.setHeight("380px"); |
1024 | |
|
1025 | 0 | submitSuccessDialog.show(); |
1026 | 0 | } |
1027 | |
}); |
1028 | 0 | return wfWithdrawItem; |
1029 | |
} |
1030 | |
|
1031 | |
private KSMenuItemData getBlanketApproveItem() { |
1032 | |
KSMenuItemData wfBlanketApproveItem; |
1033 | |
|
1034 | 0 | wfBlanketApproveItem = new KSMenuItemData("Blanket Approve Proposal", new ClickHandler() { |
1035 | |
public void onClick(ClickEvent event) { |
1036 | 0 | setupSubmitSuccessDialog(); |
1037 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
1038 | 0 | final ConfirmCancelGroup blanketApprovalButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() { |
1039 | |
|
1040 | |
@Override |
1041 | |
public void exec(ConfirmCancelEnum result) { |
1042 | 0 | if (!result.name().equals("CANCEL")) { |
1043 | 0 | if (rationaleEditor.getText().trim().equals("")) { |
1044 | 0 | required.setText("Please enter the decision rationale"); |
1045 | |
} else { |
1046 | |
|
1047 | 0 | if(blanketApproveDialogView!=null){ |
1048 | |
|
1049 | 0 | parentController.requestModel(new ModelRequestCallback<DataModel>(){ |
1050 | |
|
1051 | |
@Override |
1052 | |
public void onModelReady(final DataModel model) { |
1053 | 0 | blanketApproveDialogView.updateModel(); |
1054 | 0 | if(parentController instanceof WorkflowEnhancedNavController){ |
1055 | 0 | ((WorkflowEnhancedNavController)parentController).getMetadataForFinalState(new KSAsyncCallback<Metadata>(){ |
1056 | |
|
1057 | |
@Override |
1058 | |
public void onSuccess( |
1059 | |
Metadata metadata) { |
1060 | 0 | model.validateForMetadata(metadata, new Callback<List<ValidationResultInfo>>() { |
1061 | |
@Override |
1062 | |
public void exec(List<ValidationResultInfo> results) { |
1063 | |
|
1064 | |
|
1065 | |
|
1066 | |
|
1067 | 0 | if(ErrorLevel.OK.equals(blanketApproveDialogView.processValidationResults(results))){ |
1068 | 0 | List<String> ignoreFields = new ArrayList<String>(ignoredApproveDialogFields); |
1069 | 0 | for(FieldDescriptor fd:blanketApproveDialogView.getFields()){ |
1070 | 0 | ignoreFields.add(fd.getFieldKey()); |
1071 | |
} |
1072 | 0 | if(!ValidationResultInfo.hasValidationErrors(results,ErrorLevel.WARN,ignoreFields)){ |
1073 | |
|
1074 | 0 | SaveActionEvent saveActionEvent = new SaveActionEvent(); |
1075 | 0 | saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){ |
1076 | |
public void onActionComplete(ActionEvent action) { |
1077 | 0 | doBlanketApprove(); |
1078 | 0 | } |
1079 | |
}); |
1080 | 0 | parentController.fireApplicationEvent(saveActionEvent); |
1081 | 0 | }else{ |
1082 | 0 | submitSuccessDialog.hide(); |
1083 | 0 | KSNotifier.add(new KSNotification("Unable to blanket approve, please enter all data required for final approval.", false, true, 5000)); |
1084 | |
} |
1085 | 0 | }else{ |
1086 | 0 | KSNotifier.add(new KSNotification("Unable to blanket approve, please enter all data required for final approval.", false, true, 5000)); |
1087 | |
} |
1088 | 0 | } |
1089 | |
}); |
1090 | 0 | } |
1091 | |
|
1092 | |
}); |
1093 | |
} |
1094 | 0 | } |
1095 | |
|
1096 | |
@Override |
1097 | |
public void onRequestFail( |
1098 | |
Throwable cause) { |
1099 | 0 | KSNotifier.add(new KSNotification("Error requesting data model.", false, true, 5000)); |
1100 | 0 | } |
1101 | |
|
1102 | |
}); |
1103 | |
|
1104 | |
}else{ |
1105 | 0 | doBlanketApprove(); |
1106 | |
} |
1107 | |
|
1108 | |
|
1109 | |
} |
1110 | |
} else { |
1111 | 0 | submitSuccessDialog.hide(); |
1112 | 0 | updateWorkflowActionsWidget(); |
1113 | |
} |
1114 | 0 | } |
1115 | |
|
1116 | |
private void doBlanketApprove() { |
1117 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.BLANKET_APPROVE.getType()); |
1118 | 0 | workflowRpcServiceAsync.blanketApproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
1119 | |
@Override |
1120 | |
public void handleFailure(Throwable caught) { |
1121 | 0 | submitSuccessDialog.hide(); |
1122 | 0 | Window.alert("Error blanket approving Proposal"); |
1123 | 0 | } |
1124 | |
|
1125 | |
public void onSuccess(Boolean result) { |
1126 | 0 | submitSuccessDialog.hide(); |
1127 | 0 | if (result) { |
1128 | |
|
1129 | |
|
1130 | |
|
1131 | 0 | enableWorkflowActionsWidgets(false); |
1132 | |
|
1133 | 0 | updateWorkflow(dataModel); |
1134 | 0 | if (submitCallback != null) { |
1135 | 0 | submitCallback.exec(result); |
1136 | |
} |
1137 | |
|
1138 | 0 | KSNotifier.add(new KSNotification("Proposal will be blanket approved", false)); |
1139 | |
} else { |
1140 | 0 | Window.alert("Error blanket approving Proposal"); |
1141 | |
} |
1142 | 0 | } |
1143 | |
}); |
1144 | 0 | } |
1145 | |
}); |
1146 | |
|
1147 | 0 | blanketApprovalButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1148 | |
|
1149 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
1150 | |
|
1151 | |
@Override |
1152 | |
public void onKeyUp(KeyUpEvent event) { |
1153 | 0 | if(!rationaleEditor.getText().trim().isEmpty()){ |
1154 | 0 | blanketApprovalButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
1155 | |
} else { |
1156 | 0 | blanketApprovalButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1157 | |
} |
1158 | 0 | } |
1159 | |
|
1160 | |
}); |
1161 | |
|
1162 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Blanket Approve Proposal"); |
1163 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are blanket approving the " + proposalName + " proposal"); |
1164 | 0 | SectionTitle fieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
1165 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
1166 | 0 | required.setVisible(true); |
1167 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
1168 | 0 | dialogPanel.clear(); |
1169 | 0 | submitSuccessDialog.clearButtons(); |
1170 | 0 | submitSuccessDialog.setNonCaptionHeader(headerTitle); |
1171 | 0 | dialogPanel.add(dialogLabel); |
1172 | 0 | dialogPanel.add(fieldLabel); |
1173 | 0 | dialogPanel.add(required); |
1174 | 0 | dialogPanel.add(rationaleEditor); |
1175 | 0 | if(blanketApproveDialogView!=null && !blanketApproveDialogView.getFields().isEmpty()){ |
1176 | 0 | dialogPanel.add(blanketApproveDialogView.asWidget()); |
1177 | |
} |
1178 | 0 | submitSuccessDialog.addButtonGroup(blanketApprovalButton); |
1179 | |
|
1180 | 0 | dialogPanel.setHeight("380px"); |
1181 | |
|
1182 | 0 | submitSuccessDialog.show(); |
1183 | 0 | } |
1184 | |
}); |
1185 | 0 | return wfBlanketApproveItem; |
1186 | |
} |
1187 | |
|
1188 | |
|
1189 | |
|
1190 | |
|
1191 | |
|
1192 | |
|
1193 | |
|
1194 | |
public void blanketApprove(final Callback<Boolean> onSuccessCallback){ |
1195 | 0 | updateWorkflowIdFromModel(dataModel); |
1196 | 0 | workflowRpcServiceAsync.blanketApproveDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
1197 | |
@Override |
1198 | |
public void handleFailure(Throwable caught) { |
1199 | 0 | Window.alert("Error blanket approving Proposal"); |
1200 | 0 | } |
1201 | |
|
1202 | |
public void onSuccess(Boolean result) { |
1203 | 0 | if (result) { |
1204 | 0 | onSuccessCallback.exec(true); |
1205 | |
} else { |
1206 | 0 | Window.alert("Error blanket approving Proposal"); |
1207 | |
} |
1208 | 0 | } |
1209 | |
}); |
1210 | 0 | } |
1211 | |
|
1212 | |
|
1213 | |
|
1214 | |
|
1215 | |
|
1216 | |
|
1217 | |
|
1218 | |
public void cancel(final Callback<Boolean> onSuccessCallback){ |
1219 | 0 | ConfirmationDialog confirmCancelDialog = getConfirmationCancelProposalDialog(onSuccessCallback); |
1220 | 0 | confirmCancelDialog.show(); |
1221 | 0 | } |
1222 | |
|
1223 | |
|
1224 | |
protected KSDropDown setUpReturnToPreviousDropDown(String workflowId) { |
1225 | |
|
1226 | 0 | final KSDropDown nodeNameDropDown = new KSDropDown(); |
1227 | 0 | nodeNameDropDown.setBlankFirstItem(true); |
1228 | 0 | workflowRpcServiceAsync.getPreviousRouteNodeNames(workflowId, new KSAsyncCallback<List<String>>() { |
1229 | |
@Override |
1230 | |
public void handleFailure(Throwable caught) { |
1231 | 0 | Window.alert("Error getting previous node names for Proposal"); |
1232 | 0 | } |
1233 | |
|
1234 | |
public void onSuccess(List<String> result) { |
1235 | 0 | SimpleListItems nodeNameList = new SimpleListItems(); |
1236 | 0 | for (String nodeName : result) { |
1237 | 0 | nodeNameList.addItem(nodeName, nodeName); |
1238 | |
} |
1239 | 0 | nodeNameDropDown.setListItems(nodeNameList); |
1240 | 0 | } |
1241 | |
}); |
1242 | 0 | nodeNameDropDown.setInitialized(true); |
1243 | 0 | return nodeNameDropDown; |
1244 | |
} |
1245 | |
|
1246 | |
private KSMenuItemData getReturnToPreviousItem() { |
1247 | |
KSMenuItemData wfReturnToPreviousItem; |
1248 | |
|
1249 | 0 | wfReturnToPreviousItem = new KSMenuItemData("Return Proposal to Previous Node", new ClickHandler() { |
1250 | |
public void onClick(ClickEvent event) { |
1251 | 0 | setupSubmitSuccessDialog(); |
1252 | 0 | final KSRichEditor rationaleEditor = new KSRichEditor(); |
1253 | 0 | final KSDropDown nodeNameDropDown = setUpReturnToPreviousDropDown(workflowId); |
1254 | 0 | final ConfirmCancelGroup returnButton = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>() { |
1255 | |
|
1256 | |
@Override |
1257 | |
public void exec(ConfirmCancelEnum result) { |
1258 | 0 | if (!result.name().equals("CANCEL")) { |
1259 | 0 | if ((rationaleEditor.getText().trim().equals("")) && (nodeNameDropDown.getSelectedItem()==null || nodeNameDropDown.getSelectedItem().trim().equals(""))) { |
1260 | 0 | required.setText("Please enter the decision rationale and select a node name to return to"); |
1261 | 0 | } else if (rationaleEditor.getText().trim().equals("")) { |
1262 | 0 | required.setText("Please enter the decision rationale"); |
1263 | 0 | } else if (nodeNameDropDown.getSelectedItem()==null || nodeNameDropDown.getSelectedItem().trim().equals("")) { |
1264 | 0 | required.setText("Please select a node name to return to"); |
1265 | |
} else { |
1266 | 0 | addRationale(rationaleEditor, DecisionRationaleDetail.RETURN_TO_PREVIOUS.getType()); |
1267 | 0 | String nodeName = nodeNameDropDown.getSelectedItem().trim(); |
1268 | 0 | workflowRpcServiceAsync.returnDocumentWithId(workflowId, nodeName, new KSAsyncCallback<Boolean>() { |
1269 | |
@Override |
1270 | |
public void handleFailure(Throwable caught) { |
1271 | 0 | submitSuccessDialog.hide(); |
1272 | 0 | Window.alert("Error returning the Proposal to a previous node"); |
1273 | 0 | } |
1274 | |
|
1275 | |
public void onSuccess(Boolean result) { |
1276 | 0 | submitSuccessDialog.hide(); |
1277 | 0 | if (result) { |
1278 | 0 | updateWorkflow(dataModel); |
1279 | 0 | if (submitCallback != null) { |
1280 | 0 | submitCallback.exec(result); |
1281 | |
} |
1282 | |
|
1283 | 0 | KSNotifier.add(new KSNotification("Proposal was returned", false)); |
1284 | |
} else { |
1285 | 0 | Window.alert("Error returning the Proposal to a previous node"); |
1286 | |
} |
1287 | 0 | } |
1288 | |
}); |
1289 | 0 | } |
1290 | |
|
1291 | |
} else { |
1292 | 0 | submitSuccessDialog.hide(); |
1293 | |
} |
1294 | 0 | } |
1295 | |
}); |
1296 | |
|
1297 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1298 | |
|
1299 | 0 | rationaleEditor.getRichTextArea().addKeyUpHandler(new KeyUpHandler(){ |
1300 | |
|
1301 | |
@Override |
1302 | |
public void onKeyUp(KeyUpEvent event) { |
1303 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(nodeNameDropDown.getSelectedItem() == null)){ |
1304 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
1305 | |
} else { |
1306 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1307 | |
} |
1308 | 0 | } |
1309 | |
|
1310 | |
}); |
1311 | |
|
1312 | 0 | nodeNameDropDown.addSelectionChangeHandler(new SelectionChangeHandler(){ |
1313 | |
|
1314 | |
@Override |
1315 | |
public void onSelectionChange(SelectionChangeEvent event) { |
1316 | 0 | if(!rationaleEditor.getText().trim().isEmpty() && !(nodeNameDropDown.getSelectedItem() == null)){ |
1317 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(true); |
1318 | |
} else { |
1319 | 0 | returnButton.getButton(ButtonEnumerations.ConfirmCancelEnum.CONFIRM).setEnabled(false); |
1320 | |
} |
1321 | 0 | } |
1322 | |
|
1323 | |
}); |
1324 | |
|
1325 | 0 | SectionTitle headerTitle = SectionTitle.generateH3Title("Return Proposal to Previous Node"); |
1326 | 0 | SectionTitle dialogLabel = SectionTitle.generateH4Title("You are returning the " + proposalName + " proposal to a previous node"); |
1327 | 0 | SectionTitle nnFieldLabel = SectionTitle.generateH4Title("Workflow Node Name"); |
1328 | 0 | SectionTitle drFieldLabel = SectionTitle.generateH4Title("Decision Rationale"); |
1329 | 0 | required = new AbbrPanel("Required", "ks-form-module-elements-required", " * "); |
1330 | 0 | required.setVisible(true); |
1331 | 0 | rationaleEditor.addStyleName("KS-Comment-Create-Editor"); |
1332 | 0 | dialogPanel.clear(); |
1333 | 0 | submitSuccessDialog.clearButtons(); |
1334 | 0 | submitSuccessDialog.setNonCaptionHeader(headerTitle); |
1335 | 0 | dialogPanel.add(dialogLabel); |
1336 | 0 | dialogPanel.add(nnFieldLabel); |
1337 | 0 | dialogPanel.add(nodeNameDropDown); |
1338 | 0 | dialogPanel.add(drFieldLabel); |
1339 | 0 | dialogPanel.add(required); |
1340 | 0 | dialogPanel.add(rationaleEditor); |
1341 | 0 | submitSuccessDialog.addButtonGroup(returnButton); |
1342 | |
|
1343 | 0 | dialogPanel.setHeight("380px"); |
1344 | |
|
1345 | 0 | submitSuccessDialog.show(); |
1346 | 0 | } |
1347 | |
}); |
1348 | 0 | return wfReturnToPreviousItem; |
1349 | |
} |
1350 | |
|
1351 | |
private void addRationale(KSRichEditor rationaleEditor, String rationaleType) { |
1352 | 0 | CommentInfo newDecisionRationale = new CommentInfo(); |
1353 | 0 | RichTextInfo text = new RichTextInfo(); |
1354 | 0 | text.setFormatted(rationaleEditor.getHTML()); |
1355 | 0 | text.setPlain(rationaleEditor.getText()); |
1356 | 0 | newDecisionRationale.setReferenceTypeKey(PROPOSAL_REF_TYPE_KEY); |
1357 | 0 | newDecisionRationale.setReferenceId(proposalId); |
1358 | 0 | newDecisionRationale.setState(DtoState.ACTIVE.toString()); |
1359 | 0 | newDecisionRationale.setCommentText(text); |
1360 | 0 | newDecisionRationale.setType(rationaleType); |
1361 | |
|
1362 | |
try { |
1363 | 0 | commentServiceAsync.addComment(proposalId, PROPOSAL_REF_TYPE_KEY, newDecisionRationale, new KSAsyncCallback<CommentInfo>() { |
1364 | |
|
1365 | |
@Override |
1366 | |
public void handleFailure(Throwable caught) { |
1367 | 0 | GWT.log("Add Comment Failed", caught); |
1368 | 0 | } |
1369 | |
|
1370 | |
@Override |
1371 | |
public void onSuccess(CommentInfo result) { |
1372 | 0 | System.out.println("Rationale Added successfully"); |
1373 | 0 | } |
1374 | |
}); |
1375 | 0 | } catch (Exception e) { |
1376 | 0 | GWT.log("Add Comment Failed", e); |
1377 | 0 | } |
1378 | 0 | } |
1379 | |
|
1380 | |
private KSMenuItemData getStartItem() { |
1381 | |
KSMenuItemData wfStartWorkflowItem; |
1382 | 0 | wfStartWorkflowItem = new KSMenuItemData("Submit Proposal", new ClickHandler(){ |
1383 | |
public void onClick(ClickEvent event) { |
1384 | |
|
1385 | 0 | dataModel.validateNextState(new Callback<List<ValidationResultInfo>>() { |
1386 | |
@Override |
1387 | |
public void exec(List<ValidationResultInfo> result) { |
1388 | |
|
1389 | 0 | boolean isValid = parentController.isValid(result, false); |
1390 | 0 | if(isValid){ |
1391 | 0 | dialog.show(); |
1392 | |
} |
1393 | |
else{ |
1394 | 0 | Window.alert("Unable to submit to workflow. Please check sections for missing fields."); |
1395 | |
} |
1396 | 0 | } |
1397 | |
}); |
1398 | 0 | } |
1399 | |
|
1400 | |
}); |
1401 | 0 | return wfStartWorkflowItem; |
1402 | |
} |
1403 | |
|
1404 | |
private KSMenuItemData getCancelWorkflowItem() { |
1405 | |
KSMenuItemData wfCancelWorkflowItem; |
1406 | 0 | wfCancelWorkflowItem = new KSMenuItemData("Cancel Proposal", new ClickHandler() { |
1407 | |
public void onClick(ClickEvent event) { |
1408 | 0 | ConfirmationDialog confirmationCancelProposal = getConfirmationCancelProposalDialog(null); |
1409 | 0 | confirmationCancelProposal.show(); |
1410 | 0 | } |
1411 | |
}); |
1412 | 0 | return wfCancelWorkflowItem; |
1413 | |
} |
1414 | |
|
1415 | |
protected ConfirmationDialog getConfirmationCancelProposalDialog (final Callback<Boolean> onSuccessCallback){ |
1416 | 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?"); |
1417 | |
|
1418 | 0 | confirmationCancelProposal.getConfirmButton().setText("Yes, cancel proposal"); |
1419 | 0 | confirmationCancelProposal.getCancelButton().setStyleName(ButtonStyle.PRIMARY_SMALL.getStyle()); |
1420 | 0 | confirmationCancelProposal.getCancelButton().setText("No, return to proposal"); |
1421 | |
|
1422 | 0 | confirmationCancelProposal.getConfirmButton().addClickHandler(new ClickHandler(){ |
1423 | |
@Override |
1424 | |
public void onClick(ClickEvent event) { |
1425 | 0 | workflowRpcServiceAsync.cancelDocumentWithId(workflowId, new KSAsyncCallback<Boolean>() { |
1426 | |
@Override |
1427 | |
public void handleFailure(Throwable caught) { |
1428 | 0 | confirmationCancelProposal.hide(); |
1429 | 0 | Window.alert("Error Cancelling Proposal"); |
1430 | 0 | } |
1431 | |
public void onSuccess(Boolean result) { |
1432 | 0 | confirmationCancelProposal.hide(); |
1433 | 0 | if (result) { |
1434 | 0 | updateWorkflow(dataModel); |
1435 | 0 | if (submitCallback != null) { |
1436 | 0 | submitCallback.exec(true); |
1437 | |
} |
1438 | 0 | if (onSuccessCallback != null){ |
1439 | 0 | onSuccessCallback.exec(true); |
1440 | |
} |
1441 | |
|
1442 | 0 | KSNotifier.add(new KSNotification("Proposal will be Cancelled", false)); |
1443 | |
} else { |
1444 | 0 | Window.alert("Error Cancelling Proposal"); |
1445 | |
} |
1446 | 0 | } |
1447 | |
}); |
1448 | |
|
1449 | 0 | } |
1450 | |
|
1451 | |
}); |
1452 | |
|
1453 | 0 | return confirmationCancelProposal; |
1454 | |
} |
1455 | |
|
1456 | |
private void setWorkflowStatus(String statusCd){ |
1457 | 0 | String statusTranslation = ""; |
1458 | 0 | if (WorkflowConstants.ROUTE_HEADER_SAVED_CD.equals(statusCd)){ |
1459 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_SAVED_LABEL_KEY); |
1460 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_INITIATED_CD.equals(statusCd)){ |
1461 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_INITIATED_LABEL_KEY); |
1462 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_ENROUTE_CD.equals(statusCd)){ |
1463 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_ENROUTE_LABEL_KEY); |
1464 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_APPROVED_CD.equals(statusCd)){ |
1465 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_APPROVED_LABEL_KEY); |
1466 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_CANCEL_CD.equals(statusCd)){ |
1467 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_CANCEL_LABEL_KEY); |
1468 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_EXCEPTION_CD.equals(statusCd)){ |
1469 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_EXCEPTION_LABEL_KEY); |
1470 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_DISAPPROVED_CD.equals(statusCd)){ |
1471 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_DISAPPROVED_LABEL_KEY); |
1472 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_FINAL_CD.equals(statusCd)){ |
1473 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_APPROVED_LABEL_KEY); |
1474 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_DISAPPROVE_CANCEL_CD.equals(statusCd)){ |
1475 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_DISAPPROVE_CANCEL_LABEL_KEY); |
1476 | 0 | } else if (WorkflowConstants.ROUTE_HEADER_PROCESSED_CD.equals(statusCd)){ |
1477 | 0 | statusTranslation = getLabel(WorkflowConstants.ROUTE_HEADER_APPROVED_LABEL_KEY); |
1478 | |
} else { |
1479 | 0 | statusTranslation = statusCd; |
1480 | |
} |
1481 | |
|
1482 | 0 | workflowStatusLabel.setText("Status: " + statusTranslation); |
1483 | 0 | } |
1484 | |
|
1485 | |
private void setProposalStatus(String statusCode) { |
1486 | 0 | String statusLabel = Application.getApplicationContext() |
1487 | |
.getUILabel("common", null, null, "proposalStatusLabel"); |
1488 | 0 | String status = Application.getApplicationContext().getUILabel("common", null, null, statusCode); |
1489 | |
|
1490 | 0 | proposalStatusLabel.setText(statusLabel + ": " + status); |
1491 | 0 | } |
1492 | |
|
1493 | |
|
1494 | |
|
1495 | |
|
1496 | |
|
1497 | |
|
1498 | |
public void setModelName(String modelName) { |
1499 | 0 | this.modelName = modelName; |
1500 | 0 | } |
1501 | |
|
1502 | |
|
1503 | |
|
1504 | |
|
1505 | |
|
1506 | |
public void setProposalPath(String proposalPath) { |
1507 | 0 | this.proposalPath = proposalPath; |
1508 | 0 | } |
1509 | |
|
1510 | |
public void setWorkflowRpcService(WorkflowRpcServiceAsync workflowRpcServiceAsync){ |
1511 | 0 | this.workflowRpcServiceAsync = workflowRpcServiceAsync; |
1512 | 0 | } |
1513 | |
|
1514 | |
|
1515 | |
public void refresh(){ |
1516 | 0 | updateApproveFields(); |
1517 | 0 | updateWorkflow(dataModel); |
1518 | 0 | } |
1519 | |
|
1520 | |
private String getLabel(String labelKey) { |
1521 | 0 | return Application.getApplicationContext().getUILabel("common", null, null, labelKey); |
1522 | |
} |
1523 | |
|
1524 | |
public void getDataIdFromWorkflowId(String workflowId, AsyncCallback<String> callback){ |
1525 | 0 | workflowRpcServiceAsync.getDataIdFromWorkflowId(workflowId, callback); |
1526 | 0 | } |
1527 | |
|
1528 | |
public void addSubmitCallback(Callback<Boolean> callback) { |
1529 | 0 | this.submitCallback = callback; |
1530 | |
|
1531 | 0 | } |
1532 | |
|
1533 | |
public List<KSMenuItemData> getAdditionalItems() { |
1534 | 0 | return additionalItems; |
1535 | |
} |
1536 | |
|
1537 | |
public void addIgnoreDialogField(String string) { |
1538 | 0 | ignoredApproveDialogFields.add(string); |
1539 | 0 | } |
1540 | |
|
1541 | |
public VerticalSectionView getApproveDialogue() { |
1542 | 0 | return approveDialogView; |
1543 | |
} |
1544 | |
|
1545 | |
public void progressiveEnableFields() { |
1546 | 0 | if (getApproveDialogue() != null) { |
1547 | |
|
1548 | 0 | FieldDescriptor prevEndTerm = approveDialogView.getField("proposal/prevEndTerm"); |
1549 | |
|
1550 | 0 | if (prevEndTerm != null) { |
1551 | 0 | approveDialogView.getWidget(0).setVisible(true); |
1552 | 0 | approveDialogView.getField("proposal/prevEndTerm").getMetadata().getConstraints().get(0).setMinOccurs(1); |
1553 | 0 | approveDialogView.getField("proposal/prevEndTerm").getFieldElement().setRequiredString("requiredMarker", "ks-form-module-elements-required"); |
1554 | 0 | approveDialogView.getField("startTerm").getFieldWidget().setVisible(true); |
1555 | |
} else { |
1556 | 0 | approveDialogView.getWidget(0).setVisible(false); |
1557 | 0 | approveDialogView.getField("startTerm").getFieldWidget().setVisible(false); |
1558 | |
} |
1559 | |
} |
1560 | 0 | } |
1561 | |
|
1562 | |
} |