Coverage Report - org.kuali.student.lum.lu.ui.course.client.controllers.CourseAdminController
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseAdminController
0%
0/52
0%
0/14
1.684
CourseAdminController$1
0%
0/3
N/A
1.684
CourseAdminController$2
0%
0/3
N/A
1.684
CourseAdminController$3
0%
0/3
N/A
1.684
CourseAdminController$4
0%
0/3
N/A
1.684
CourseAdminController$4$1
0%
0/4
0%
0/2
1.684
CourseAdminController$5
0%
0/4
0%
0/2
1.684
CourseAdminController$5$1
0%
0/10
0%
0/4
1.684
CourseAdminController$5$1$1
0%
0/6
0%
0/2
1.684
CourseAdminController$6
0%
0/4
0%
0/2
1.684
CourseAdminController$7
0%
0/3
N/A
1.684
 
 1  
 package org.kuali.student.lum.lu.ui.course.client.controllers;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 
 6  
 import org.kuali.student.common.assembly.data.QueryPath;
 7  
 import org.kuali.student.common.dto.DtoConstants;
 8  
 import org.kuali.student.common.ui.client.application.Application;
 9  
 import org.kuali.student.common.ui.client.application.ViewContext;
 10  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection;
 11  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 12  
 import org.kuali.student.common.ui.client.event.ActionEvent;
 13  
 import org.kuali.student.common.ui.client.event.SaveActionEvent;
 14  
 import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback;
 15  
 import org.kuali.student.common.ui.client.mvc.Callback;
 16  
 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
 17  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 18  
 import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData;
 19  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 20  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 21  
 import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities;
 22  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 23  
 import org.kuali.student.lum.lu.LUConstants;
 24  
 import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants;
 25  
 import org.kuali.student.lum.lu.ui.course.client.configuration.CourseAdminConfigurer;
 26  
 import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList;
 27  
 
 28  
 import com.google.gwt.core.client.GWT;
 29  
 import com.google.gwt.event.dom.client.ClickEvent;
 30  
 import com.google.gwt.event.dom.client.ClickHandler;
 31  
 import com.google.gwt.user.client.DOM;
 32  
 
 33  
 /**
 34  
  * Controller for create/modify course with proposal wrapper admin screens. This controller uses a different
 35  
  * configurer for admin screens and attempts to reuse as much of the validation, save & retreive logic coded
 36  
  * in the CourseProposalController.  Also it reuses the menu from CourseProposalController and adds click
 37  
  * handlers to button menu to navigate user b/w sections of the same view.
 38  
  * 
 39  
  * @author Will
 40  
  *
 41  
  */
 42  0
 public class CourseAdminController extends CourseProposalController{
 43  
         
 44  0
         List<KSButton> cancelButtons = new ArrayList<KSButton>();
 45  
         
 46  
         /**
 47  
          * Override the intitailzeController method to use CourseAdminConfigurer 
 48  
          */
 49  
         @Override
 50  
         protected void initializeController() {
 51  
                    
 52  0
                 super.cfg = GWT.create(CourseAdminConfigurer.class);
 53  0
                 super.proposalPath = cfg.getProposalPath();
 54  0
                    super.workflowUtil = new WorkflowUtilities(CourseAdminController.this ,proposalPath);
 55  
                 
 56  0
                    cfg.setState(DtoConstants.STATE_DRAFT.toUpperCase());
 57  0
                    cfg.setNextState(DtoConstants.STATE_APPROVED.toUpperCase());
 58  0
                    super.setDefaultModelId(cfg.getModelId());
 59  0
                    super.registerModelsAndHandlers();
 60  0
                    super.addStyleName("ks-course-admin");
 61  0
                    currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_CREATE_ADMIN;
 62  
                    //this.removeMenu();                                                
 63  0
     }
 64  
     
 65  
         /**
 66  
          * Override the getSaveButton to provide a new set of buttons for the admin screens
 67  
          */
 68  
         @Override
 69  
         public KSButton getSaveButton(){
 70  0
                 return new KSButton("Save", new ClickHandler(){
 71  
             public void onClick(ClickEvent event) {
 72  0
                     handleButtonClick(DtoConstants.STATE_DRAFT);                    
 73  0
             }
 74  
         });                
 75  
         }
 76  
                 
 77  
         public KSButton getApproveButton(){
 78  0
                 return new KSButton("Approve", new ClickHandler(){
 79  
             public void onClick(ClickEvent event) {       
 80  0
                     handleButtonClick(DtoConstants.STATE_APPROVED);
 81  0
             }
 82  
         });
 83  
     }
 84  
                 
 85  
         public KSButton getApproveAndActivateButton(){
 86  0
                 return new KSButton("Approve and Activate", new ClickHandler(){
 87  
             public void onClick(ClickEvent event) {
 88  0
                     handleButtonClick(DtoConstants.STATE_ACTIVE);
 89  0
             }
 90  
         });                
 91  
         }
 92  
 
 93  
         public KSButton getCancelButton(){
 94  0
                 KSButton cancelButton = new KSButton("Cancel Proposal", new ClickHandler(){
 95  
             public void onClick(ClickEvent event) {
 96  
                     //Cancel the proposal and navigate the user back to curriculum home if cancel was successful.
 97  0
                     workflowUtil.cancel(new Callback<Boolean>(){
 98  
                                         @Override
 99  
                                         public void exec(Boolean result) {
 100  0
                                                 if (result){
 101  0
                                                         Application.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation());                                                        
 102  
                                                 }                                                
 103  0
                                         }
 104  
                             
 105  
                     });
 106  0
             }
 107  
         });
 108  
         
 109  0
                 if (LUConstants.PROPOSAL_TYPE_COURSE_CREATE_ADMIN.equals(currentDocType)){
 110  
                         //For new admin proposal, disable the cancel button intially since proposal doesn't exist
 111  
                         //until they click save.
 112  0
                         cancelButton.setEnabled(false);
 113  
                 }
 114  
         
 115  0
                 cancelButtons.add(cancelButton);
 116  0
                 return cancelButton;
 117  
     }
 118  
         
 119  
         /**
 120  
          * This processes the save, approve, or approve and activate button clicks. The action is determined
 121  
          * by the value of the state parameter.
 122  
          * 
 123  
          * @param state The state to set on the course when saving course data. DRAFT=Save, APPROVED=Approve, and
 124  
          * ACTIVE=Approve & Activate
 125  
          */
 126  
         protected void handleButtonClick(final String state){
 127  0
             cluProposalModel.set(QueryPath.parse(CreditCourseConstants.STATE), state);
 128  0
             final SaveActionEvent saveActionEvent = new SaveActionEvent(false);
 129  
             
 130  0
             if (DtoConstants.STATE_APPROVED.equalsIgnoreCase(state) || DtoConstants.STATE_ACTIVE.equalsIgnoreCase(state)){
 131  
                 // For "Approve" and "Approve & Activate" actions, automatically blanket approve the admin proposal so it 
 132  
                 // enters final state. This is accomplished by first saving the course (via saveActionEvent) and then by 
 133  
                 // executing the the blanket approve call upon a successful save. When user clicks either of these buttons 
 134  
                 // and blanket approve is successful, they are navigated to the view course screen.
 135  
 
 136  0
                     saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){
 137  
                                 @Override
 138  
                                 public void onActionComplete(ActionEvent actionEvent) {
 139  0
                                         if (saveActionEvent.isSaveSuccessful()){
 140  0
                                                 workflowUtil.blanketApprove(new Callback<Boolean>(){
 141  
                                                         @Override
 142  
                                                         public void exec(Boolean result) {
 143  
                                                             // FIXME:  Even though workflow rpc call to blanket approve is successful, the
 144  
                                                                 // asynchronous nature of workflow is causing timing issues here. Need to investigate
 145  
                                                             // making blanket approve workflow more synchronous to avoid the timing issues.
 146  
                                                                 // NOTE: One solution is to not allow an activate here, and force user to activate from view
 147  
                                                                 // screen, the down side being user now requires two clicks.
 148  
                                                                 
 149  0
                                                                 final ViewContext viewContext = new ViewContext();
 150  0
                                                 viewContext.setId((String)cluProposalModel.get(CreditCourseConstants.ID));
 151  0
                                                 viewContext.setIdType(IdType.OBJECT_ID);                                                                                                                        
 152  0
                                                                 if (DtoConstants.STATE_APPROVED.equalsIgnoreCase(state)){
 153  0
                                                                         KSNotifier.show("Course approved. It may take a minute or two for course status to be updated. Refresh to see latest status.");
 154  0
                                                                         Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext);
 155  0
                                                                 } else if (DtoConstants.STATE_ACTIVE.equalsIgnoreCase(state)){
 156  
                                                                         //For "Approve and Activate", call change state rpc method to properly activate the course
 157  0
                                                                         CourseWorkflowActionList.setCourseState(viewContext.getId(), DtoConstants.STATE_ACTIVE, new Callback<String>(){
 158  
                                                                                 @Override
 159  
                                                                                 public void exec(String result) {
 160  0
                                                                                         if (result == null){
 161  0
                                                                                                 KSNotifier.show("Course approved, but activation failed.");
 162  
                                                                                         } else {
 163  0
                                                                                                 KSNotifier.show("Course approved and activated. It may take a minute or two for course status to be updated. Refresh to see latest status.");                                                                        
 164  
                                                                                         }
 165  0
                                                                                         Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext);
 166  0
                                                                                 }
 167  
                                                                         });                                                        
 168  
                                                                 }
 169  
                                                                 
 170  0
                                                         }
 171  
                                                 });
 172  
                                         }      
 173  0
                                 }
 174  
                     });
 175  
             } else {
 176  
                     //For a save event all this does is enable the cancel button to allow user to cancel the proposal.
 177  0
                     saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){
 178  
                                 @Override
 179  
                                 public void onActionComplete(ActionEvent action) {
 180  0
                                         for (KSButton cancelButton:cancelButtons){
 181  0
                                                 cancelButton.setEnabled(true);
 182  
                                         }                                        
 183  0
                                 }                            
 184  
                     });
 185  
             }
 186  
             
 187  0
         CourseAdminController.this.fireApplicationEvent(saveActionEvent);                
 188  0
         }
 189  
         
 190  
         /**
 191  
      * Override the setHeaderTitle to display proper header title for admin screens
 192  
      */
 193  
         @Override
 194  
         protected void setHeaderTitle(){
 195  
             String title;
 196  0
             if (cluProposalModel.get(cfg.getProposalTitlePath()) != null){
 197  0
                     title = getProposalTitle();
 198  
             }
 199  
             else{
 200  0
                     title = "New Course (Admin Proposal)";
 201  
             }
 202  0
             this.setContentTitle(title);
 203  0
             this.setName(title);
 204  0
             WindowTitleUtils.setContextTitle(title);
 205  0
                 currentTitle = title;
 206  0
     }
 207  
     
 208  
         private String getProposalTitle(){
 209  0
                 StringBuffer sb = new StringBuffer();
 210  0
                 sb.append(cluProposalModel.get(cfg.getProposalTitlePath()));
 211  0
                 sb.append(" (Admin Proposal)");
 212  0
                 return sb.toString();
 213  
         }
 214  
         
 215  
         /**
 216  
          * This is a special method for CourseAdminController, which adds a menu item to the navigation menu and navigates
 217  
          * a user to a section within the view rather than a different view.
 218  
          * 
 219  
          * @param parentMenu
 220  
          * @param sectionName
 221  
          * @param sectionId
 222  
          * @param section
 223  
          */
 224  
     public void addMenuItemSection(String parentMenu, final String sectionName, final String sectionId, final Section section) {            
 225  0
         KSMenuItemData parentItem = null;
 226  0
         for (int i = 0; i < topLevelMenuItems.size(); i++) {
 227  0
             if (topLevelMenuItems.get(i).getLabel().equals(parentMenu)) {
 228  0
                 parentItem = topLevelMenuItems.get(i);
 229  0
                 break;
 230  
             }
 231  
         }
 232  
 
 233  0
         KSMenuItemData item = new KSMenuItemData(sectionName);
 234  0
             ((BaseSection)section).setSectionId(sectionId);
 235  0
             item.setClickHandler(new ClickHandler(){
 236  
                         public void onClick(ClickEvent event) {                
 237  
                                 //FIXME: This doesn't scroll to exactly the position stuff
 238  0
                                 DOM.getElementById(sectionId).scrollIntoView();
 239  0
                         }                    
 240  
             });
 241  
 
 242  0
         if (parentItem != null) {
 243  0
             parentItem.addSubItem(item);
 244  
         } else {
 245  0
             topLevelMenuItems.add(item);
 246  
         }
 247  
 
 248  0
         menu.refresh();
 249  0
     }
 250  
     
 251  
 }