Coverage Report - org.kuali.student.lum.lu.ui.course.client.widgets.ViewCourseActionList
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewCourseActionList
0%
0/42
0%
0/4
1.154
ViewCourseActionList$1
0%
0/6
N/A
1.154
ViewCourseActionList$2
0%
0/3
N/A
1.154
ViewCourseActionList$3
0%
0/3
N/A
1.154
ViewCourseActionList$4
0%
0/3
N/A
1.154
 
 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  
 
 16  
 package org.kuali.student.lum.lu.ui.course.client.widgets;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.student.common.assembly.data.QueryPath;
 22  
 import org.kuali.student.common.ui.client.mvc.Controller;
 23  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 24  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 25  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 26  
 import org.kuali.student.common.ui.client.widgets.StylishDropDown;
 27  
 import org.kuali.student.common.ui.client.widgets.layout.HorizontalBlockFlowPanel;
 28  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
 29  
 
 30  
 import com.google.gwt.core.client.GWT;
 31  
 import com.google.gwt.event.dom.client.ClickEvent;
 32  
 import com.google.gwt.event.dom.client.ClickHandler;
 33  
 import com.google.gwt.event.logical.shared.CloseHandler;
 34  
 import com.google.gwt.user.client.Window;
 35  
 import com.google.gwt.user.client.ui.Composite;
 36  
 
 37  
 
 38  
 // Skeleton for an action list for View Course.  Actions don't go anywhere yet as most functionality
 39  
 // hasn't been coded yet.
 40  
 @Deprecated
 41  0
 public class ViewCourseActionList extends Composite {
 42  0
         DataModel dataModel=null;
 43  
         
 44  
         private KSMenuItemData retireCourseAction;
 45  
         private KSMenuItemData copyCourseAction;
 46  
         private KSMenuItemData modifyCourseAction;
 47  
         
 48  0
         List<KSMenuItemData> items = new ArrayList<KSMenuItemData>();
 49  
     
 50  
     private String modelName;
 51  
     private String courseCodePath;
 52  
        
 53  0
         private HorizontalBlockFlowPanel rootPanel = new HorizontalBlockFlowPanel();
 54  0
         private StylishDropDown courseActionsDropDown = GWT.create(StylishDropDown.class);
 55  
         
 56  
     Controller myController;
 57  
     
 58  
         public ViewCourseActionList(CloseHandler<KSLightBox> onSubmitSuccessHandler) {
 59  0
                 super();
 60  0
                 super.initWidget(rootPanel);
 61  
                 
 62  0
                 courseActionsDropDown.initialise("Course Actions");
 63  
                 
 64  0
                 setupButtons();
 65  
 
 66  0
                 rootPanel.add(courseActionsDropDown);
 67  
                 
 68  0
                 courseActionsDropDown.addStyleName("KS-Workflow-DropDown");
 69  0
         }
 70  
         
 71  
         /* (non-Javadoc)
 72  
          * @see com.google.gwt.user.client.ui.Widget#onLoad()
 73  
          */
 74  
         @Override
 75  
         protected void onLoad() {
 76  0
                 super.onLoad();
 77  0
                 myController = Controller.findController(this);
 78  
                 
 79  0
                 if(null==dataModel){
 80  
                         //Get the Model from the controller and register a model change handler when the workflow model is updated
 81  0
                         myController.requestModel(modelName, new ModelRequestCallback<DataModel>(){
 82  
                         
 83  
                                 @Override
 84  
                                 public void onRequestFail(Throwable cause) {
 85  0
                                         Window.alert("Model Request Failed. "+cause.getMessage());
 86  0
                                 }
 87  
 
 88  
                                 @Override
 89  
                                 public void onModelReady(DataModel model) {
 90  
                                         //After we get the model update immediately
 91  0
                                         dataModel = model;
 92  0
                                         updateActions(dataModel);
 93  
                                          
 94  
                                         /*
 95  
                                         model.addModelChangeHandler(new ModelChangeHandler(){
 96  
                                                 public void onModelChange(ModelChangeEvent event) {
 97  
                                                         updateWorkflow(dataModel);                                                        
 98  
                                                 }                                                
 99  
                                         });
 100  
                                         */
 101  0
                                 }
 102  
                         });
 103  
                 }else{
 104  
                         
 105  
                         //If the model has been set don't waste time finding it again and don't register 
 106  
                         //another change listener, just update
 107  0
                         updateActions(dataModel);
 108  
                 }
 109  0
         }
 110  
         
 111  
         private String getCourseCodeFromModel(DataModel model){
 112  0
                 String courseCode = "";
 113  0
                 if(model!=null){
 114  0
                         courseCode = model.get(QueryPath.parse(courseCodePath));
 115  
                 }
 116  0
                 return courseCode;
 117  
         }
 118  
         
 119  
         private void setupButtons() {
 120  
 //                final ConfirmationDialog dialog = new ConfirmationDialog("Submit Proposal", "Are you sure you want to submit the proposal to workflow?", "Submit");
 121  
 //                dialog.getConfirmButton().addClickHandler(new ClickHandler(){
 122  
 //
 123  
 //                        @Override
 124  
 //                        public void onClick(ClickEvent event) {
 125  
 //                                dialog.getConfirmButton().setEnabled(false);
 126  
 //                                rpcService.submitDocumentWithData(dataModel.getRoot(), new KSAsyncCallback<DataSaveResult>(){
 127  
 //                                        public void handleFailure(
 128  
 //                                                        Throwable caught) {
 129  
 //                                                Window.alert("Error starting Proposal workflow");
 130  
 //                                                dialog.getConfirmButton().setEnabled(true);
 131  
 //                                        }
 132  
 //                                        public void onSuccess(
 133  
 //                                                        DataSaveResult result) {
 134  
 //                                                //Update the model with the saved data
 135  
 //                                                dataModel.setRoot(result.getValue());
 136  
 //                                                
 137  
 //                                                items.remove(wfStartWorkflowItem);
 138  
 //                                                courseActionsDropDown.setItems(items);
 139  
 //                                                dialog.hide();
 140  
 //                                                dialog.getConfirmButton().setEnabled(true);
 141  
 //                                                //Notify the user that the document was submitted
 142  
 //                                                showSuccessDialog();
 143  
 //                                        }
 144  
 //                                });
 145  
 //                                
 146  
 //                        }
 147  
 //                });
 148  
  
 149  0
                 copyCourseAction = new KSMenuItemData("Copy Course", new ClickHandler(){
 150  
                 public void onClick(ClickEvent event) {
 151  0
                                 Window.alert("Function not yet implemented");
 152  
                         
 153  
 //                                rpcService.acknowledgeDocumentWithId(proposalId, new KSAsyncCallback<Boolean>(){
 154  
 //                                        public void handleFailure(
 155  
 //                                                        Throwable caught) {
 156  
 //                                                Window.alert("Error acknowledging Proposal");
 157  
 //                                        }
 158  
 //                                        public void onSuccess(
 159  
 //                                                        Boolean result) {
 160  
 //                                                if(result){
 161  
 //                                                        Window.alert("Proposal was acknowledged");
 162  
 //                                                        items.remove(wfAcknowledgeItem);
 163  
 //                                                        courseActionsDropDown.setItems(items);
 164  
 //                                                }else{
 165  
 //                                                        Window.alert("Error acknowledging Proposal");
 166  
 //                                                }
 167  
 //                                        }
 168  
 //                                        
 169  
 //                                });
 170  0
                 }        
 171  
             });
 172  
 
 173  0
                 retireCourseAction = new KSMenuItemData("Retire Course", new ClickHandler(){
 174  
                 public void onClick(ClickEvent event) {
 175  0
                                 Window.alert("Function not yet implemented");
 176  0
                         }        
 177  
             });
 178  0
                 modifyCourseAction = new KSMenuItemData("Modify Course", new ClickHandler(){
 179  
                 public void onClick(ClickEvent event) {
 180  0
                                 Window.alert("Function not yet implemented");
 181  0
                         }        
 182  
             });
 183  0
         }
 184  
 
 185  
         private void updateActions(DataModel model){
 186  0
                 String courseCode = getCourseCodeFromModel(model);
 187  0
                 items.clear();
 188  
                 
 189  0
                 copyCourseAction.setLabel("Copy " + courseCode );
 190  0
                 modifyCourseAction.setLabel("Modify " + courseCode );
 191  0
                 retireCourseAction.setLabel("Retire " + courseCode );
 192  
                 
 193  0
                 items.add(copyCourseAction);
 194  0
                 items.add(modifyCourseAction);
 195  0
                 items.add(retireCourseAction);
 196  0
                 courseActionsDropDown.setItems(items);
 197  
 
 198  0
         }
 199  
 
 200  
         /**
 201  
          * Use to set the modelName to use when this widget requests the data model.
 202  
          * 
 203  
          * @param modelName
 204  
          */
 205  
         public void setModelName(String modelName) {
 206  0
                 this.modelName = modelName;
 207  0
         }
 208  
         
 209  
         /**
 210  
          * Use to set the data model path to retrieve the id to use for this workflow. 
 211  
          * @param courseCodePath
 212  
          */
 213  
         public void setCourseCodePath(String courseCodePath) {
 214  0
                 this.courseCodePath = courseCodePath;
 215  0
         }
 216  
         
 217  
         public void refresh(){
 218  0
                 updateActions(dataModel);
 219  0
         }
 220  
 }