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