Coverage Report - org.kuali.student.lum.program.client.major.view.MajorViewController
 
Classes in this File Line Coverage Branch Coverage Complexity
MajorViewController
0%
0/74
0%
0/22
2.375
MajorViewController$1
0%
0/7
0%
0/4
2.375
MajorViewController$2
0%
0/3
N/A
2.375
MajorViewController$3
0%
0/12
0%
0/4
2.375
MajorViewController$4
0%
0/3
N/A
2.375
MajorViewController$5
0%
0/5
0%
0/2
2.375
MajorViewController$6
0%
0/4
0%
0/2
2.375
MajorViewController$7
0%
0/17
0%
0/8
2.375
MajorViewController$8
0%
0/4
N/A
2.375
MajorViewController$9
0%
0/4
0%
0/2
2.375
 
 1  
 package org.kuali.student.lum.program.client.major.view;
 2  
 
 3  
 
 4  
 
 5  
 import org.kuali.student.common.assembly.data.Data;
 6  
 import org.kuali.student.common.assembly.data.Data.Property;
 7  
 import org.kuali.student.common.ui.client.application.Application;
 8  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 9  
 import org.kuali.student.common.ui.client.application.ViewContext;
 10  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 11  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 12  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 13  
 import org.kuali.student.common.ui.client.widgets.KSCheckBox;
 14  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 15  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 16  
 import org.kuali.student.common.ui.client.widgets.KSRadioButton;
 17  
 import org.kuali.student.common.ui.shared.IdAttributes;
 18  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 19  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 20  
 import org.kuali.student.lum.common.client.widgets.DropdownList; 
 21  
 import org.kuali.student.lum.program.client.ProgramConstants;
 22  
 import org.kuali.student.lum.program.client.ProgramRegistry;
 23  
 import org.kuali.student.lum.program.client.ProgramSections;
 24  
 import org.kuali.student.lum.program.client.ProgramStatus;
 25  
 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
 26  
 import org.kuali.student.lum.program.client.events.ProgramViewEvent;
 27  
 import org.kuali.student.lum.program.client.major.ActionType;
 28  
 import org.kuali.student.lum.program.client.major.MajorController;
 29  
 
 30  
 import com.google.gwt.core.client.GWT;
 31  
 import com.google.gwt.event.dom.client.ChangeEvent;
 32  
 import com.google.gwt.event.dom.client.ChangeHandler;
 33  
 import com.google.gwt.event.dom.client.ClickEvent;
 34  
 import com.google.gwt.event.dom.client.ClickHandler;
 35  
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 36  
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 37  
 import com.google.gwt.event.shared.HandlerManager;
 38  
 import com.google.gwt.user.client.ui.Anchor;
 39  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 40  
 import com.google.gwt.user.client.ui.VerticalPanel;
 41  
 
 42  
 
 43  0
 public class MajorViewController extends MajorController {
 44  
 
 45  
     // TODO: Change to program and copy msgs
 46  
     private static final String MSG_GROUP = "program";
 47  
     
 48  
     /**
 49  
      * Initialize the action drop-down with a list of values.  Note that these values
 50  
      * will be changed further down in the code depending on if we are working with the latest 
 51  
      * version of the program.
 52  
      */
 53  0
     private final DropdownList actionBox = new DropdownList(ActionType.getValuesForMajorDiscipline(false));
 54  
  
 55  
     // Used to pass flag if this is the latest version of the program from
 56  
     // an async call to the light box so we can conditionally decided
 57  
     // to display the use curriculum review process checkbox
 58  
     private boolean isCurrentVersion;
 59  
     
 60  
     /**
 61  
      * Constructor.
 62  
      *
 63  
      * @param programModel
 64  
      */
 65  
     public MajorViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) {
 66  0
         super(programModel, viewContext, eventBus);
 67  0
         configurer = GWT.create(MajorViewConfigurer.class);
 68  
   
 69  
         // Initialize handlers and action drop-down
 70  0
         initHandlers();
 71  0
      }
 72  
  
 73  
     private void initHandlers() {
 74  
         
 75  
         /*
 76  
          * Action drop-down box on-change
 77  
          */
 78  0
         actionBox.addChangeHandler(new ChangeHandler() {
 79  
             @Override
 80  
             public void onChange(ChangeEvent event) {
 81  
                 
 82  
                 // Get the action selected in the drop-down
 83  0
                 ActionType actionType = ActionType.of(actionBox.getSelectedValue());
 84  0
                 ViewContext viewContext = getViewContext();
 85  
                 
 86  
                 // If modify is selected
 87  0
                 if (actionType == ActionType.MODIFY) {
 88  
                     
 89  
                     // Show the modify program light box.  This is triggered when you choose the 
 90  
                     // modify program option in the action drop-down box
 91  0
                     buildModifyDialog(viewContext,"/HOME/CURRICULUM_HOME/COURSE_PROPOSAL",programModel);                   
 92  
                 } 
 93  
                 // If retire is selected
 94  0
                 else if (actionType == ActionType.RETIRE) {
 95  
                     // TODO: retire is not implemented yet for program
 96  
                 }
 97  0
             }
 98  
         });
 99  
         /*
 100  
          * Initial value selected in action drop-down
 101  
          */
 102  0
         eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() {
 103  
             @Override
 104  
             public void onEvent(ProgramViewEvent event) {
 105  0
                 actionBox.setSelectedIndex(0);
 106  0
             }
 107  
         });
 108  
         
 109  
         /* 
 110  
          * Code executed right after model is loaded from service
 111  
          */
 112  0
         eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() {
 113  
             @Override
 114  
             public void onEvent(ModelLoadedEvent event) {
 115  
                 
 116  
                 /*
 117  
                  * Reload values in the drop-down if the data model changes
 118  
                  * since we may have loaded a different version
 119  
                  */
 120  0
                 resetActionList();
 121  
                  
 122  0
                 String type = context.getAttributes().get(ProgramConstants.TYPE);
 123  0
                 if (type != null) {
 124  0
                     context.getAttributes().remove(ProgramConstants.TYPE);
 125  0
                     if (type.equals(ProgramConstants.VARIATION_TYPE_KEY)) {
 126  0
                         showVariationView();
 127  
                     } else {
 128  
                             //Take out the vairationId if it exists for cleaner navigation
 129  0
                             context.getAttributes().remove(ProgramConstants.VARIATION_ID);
 130  0
                         showView(ProgramSections.VIEW_ALL);
 131  
                     }
 132  
                 } else {
 133  0
                         context.getAttributes().remove(ProgramConstants.VARIATION_ID);
 134  0
                     showView(ProgramSections.VIEW_ALL);
 135  
                 }
 136  0
             }
 137  
         });
 138  0
     }
 139  
     /**
 140  
      * 
 141  
      * This method builds the light box that appears when you choose to modify a program.
 142  
      * 
 143  
      * @param viewContext
 144  
      * @param modifyPath
 145  
      * @param model
 146  
      */
 147  
     private void buildModifyDialog(final ViewContext viewContext, final String modifyPath, final DataModel model){
 148  0
         final KSLightBox modifyDialog = new KSLightBox();
 149  
         
 150  
         //Create a dialog for course selection
 151  0
         modifyDialog.setTitle((getMessage("modifyProgramSubTitle")));
 152  
 
 153  0
         final VerticalPanel layout = new VerticalPanel();
 154  0
         layout.addStyleName("ks-form-module-fields");
 155  
                 
 156  0
         final KSButton continueButton = new KSButton(getMessage("continue"));
 157  
         
 158  0
         modifyDialog.addButton(continueButton);
 159  0
         Anchor cancelLink = new Anchor("Cancel");
 160  
        
 161  
         // Cancel should just close the dialog
 162  0
         cancelLink.addClickHandler(new ClickHandler(){
 163  
             public void onClick(ClickEvent event) {
 164  0
                 modifyDialog.hide();
 165  0
             }
 166  
         });
 167  0
         modifyDialog.addButton(cancelLink);
 168  
         
 169  0
         HorizontalPanel titlePanel = new HorizontalPanel();
 170  0
         KSLabel titleLabel = new KSLabel(getMessage("modifyProgramSubTitle"));
 171  0
         titleLabel.addStyleName("bold");
 172  0
         titlePanel.add(titleLabel);
 173  
         
 174  0
         layout.add(titlePanel);
 175  
         
 176  0
         final KSRadioButton radioOptionModifyNoVersion = new KSRadioButton("modifyCreditProgramButtonGroup", getMessage("modifyProgramNoVersion"));
 177  0
         final KSRadioButton radioOptionModifyWithVersion = new KSRadioButton("modifyCreditProgramButtonGroup", getMessage("modifyProgramWithVersion"));
 178  0
         final KSCheckBox curriculumReviewOption = new KSCheckBox(getMessage("useCurriculumReview"));
 179  
         
 180  
         
 181  0
         radioOptionModifyNoVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){
 182  
             public void onValueChange(ValueChangeEvent<Boolean> event) {
 183  0
                 if(event.getValue()){
 184  0
                     curriculumReviewOption.setEnabled(false);
 185  0
                     curriculumReviewOption.setValue(false);
 186  
                 }
 187  0
             }
 188  
         });
 189  0
         radioOptionModifyNoVersion.setValue(true);
 190  
         
 191  
 
 192  0
         curriculumReviewOption.setEnabled(false);
 193  
         
 194  0
         radioOptionModifyWithVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){
 195  
             public void onValueChange(ValueChangeEvent<Boolean> event) {
 196  0
                 if(event.getValue()){
 197  0
                     curriculumReviewOption.setEnabled(true);
 198  
                 }
 199  0
             }
 200  
         });
 201  
         
 202  
         /*
 203  
          * Continue button clicked.
 204  
          */
 205  0
         continueButton.addClickHandler(new ClickHandler(){
 206  
             @Override
 207  
             public void onClick(ClickEvent event) {
 208  0
                  if (radioOptionModifyNoVersion.getValue()){
 209  
                     // If modify w/out version radio button is chosen 
 210  
                     // we just edit the program.  We do not create a copy.
 211  
                     // We navigate to the edit program controller
 212  0
                      ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum()));
 213  0
                      HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext);
 214  0
                  } else if (radioOptionModifyWithVersion.getValue() && curriculumReviewOption.getValue()){
 215  
                     // If the curriculum review option IS checked and the modify with version radio button IS selected
 216  
                     // We need to create a copy of the program (by passing in COPY_OF_OBJECT_ID)
 217  
                     // and then transfer control to the proposal controller (the proposal controller has
 218  
                     // extra section for entering proposal related data
 219  0
                     String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID);
 220  
  
 221  
                     // Pass the ID and the type to the proposal controller
 222  
                     // using the view context.  We then read it in the
 223  
                     // setViewContext method and use it to initialize the
 224  
                     // work flow utilities
 225  0
                     final ViewContext viewContext = new ViewContext();
 226  0
                     viewContext.setId(versionIndId);
 227  0
                     viewContext.setIdType(IdAttributes.IdType.COPY_OF_OBJECT_ID); 
 228  0
                     Application.navigate(AppLocations.Locations.PROGRAM_PROPOSAL.getLocation(), viewContext);
 229  
 
 230  0
                  } else if (radioOptionModifyWithVersion.getValue()){
 231  
                     // If we are just choosing to modify a program but want to create a new version
 232  
                     // AND we are not using the proposal process
 233  
                     // We make a copy of the data model and transfer control
 234  
                     // to the edit program screen
 235  
                      
 236  
                      // Pass the ID and the type to the proposal controller
 237  
                      // using the view context.  We then read it in the
 238  
                      // setViewContext method and use it to initialize the
 239  
                      // work flow utilities
 240  
     
 241  0
                      String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID);
 242  0
                      viewContext.setId(versionIndId);
 243  0
                      viewContext.setIdType(IdType.COPY_OF_OBJECT_ID);
 244  
           
 245  
                      //ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum()));
 246  0
                      HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext);
 247  
                 }   
 248  
                 
 249  
                 // Hide dialog after clicking
 250  0
                 modifyDialog.hide();
 251  0
             }           
 252  
         });
 253  
         
 254  
         //Check that this is the latest version with an async call and only show modify with version options if it is the latest
 255  
        
 256  0
         layout.add(radioOptionModifyNoVersion);
 257  
  
 258  
         // the curriculum review check box implements "modify by proposal"
 259  
         // a user can only check the box when the program state is active, retired, or approved (it must be the latest version when in these states)
 260  
         // See https://wiki.kuali.org/display/KULSTG/Course%2C+Proposal%2C+and+Program+Action+Dropdown+Items
 261  0
         ProgramStatus status = ProgramStatus.of(programModel);
 262  0
         if(isCurrentVersion && (status == ProgramStatus.ACTIVE || status == ProgramStatus.APPROVED || status == ProgramStatus.ACTIVE)){
 263  0
             layout.add(radioOptionModifyWithVersion);
 264  0
             layout.add(curriculumReviewOption);
 265  
         }
 266  
         
 267  0
         modifyDialog.setWidget(layout);
 268  0
         modifyDialog.show();
 269  0
     } 
 270  
  
 271  
     
 272  
     /**
 273  
      * 
 274  
      * This method will grab a message based on a key.
 275  
      * 
 276  
      * @param courseMessageKey
 277  
      * @return
 278  
      */
 279  
     public String getMessage(String programMessageKey) {
 280  0
         String msg = Application.getApplicationContext().getMessage(MSG_GROUP, programMessageKey);
 281  0
         if (msg == null) {
 282  0
             msg = programMessageKey;
 283  
         }
 284  0
         return msg;
 285  
     }   
 286  
     
 287  
     /**
 288  
      * 
 289  
      * This method will set the values in the action list drop-down.
 290  
      *
 291  
      */
 292  
     protected void resetActionList() {
 293  
             
 294  
         // Get the current state of the program (SUPERSEDED, ACTIVE, APPROVED, DRAFT)
 295  0
             ProgramStatus status = ProgramStatus.of(programModel);
 296  
             
 297  
             // Get the version independent indicator
 298  0
         String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID);
 299  
         
 300  
         // The the version sequence number
 301  0
         Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER);
 302  
                
 303  
         // Clear the drop-down list and prepare to populate it with values
 304  0
         actionBox.clear();
 305  
   
 306  
         // Call the server to see if this is the latest version of the program
 307  
         // and update the drop-down accordingly
 308  0
             programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>(){
 309  
                         public void onSuccess(Boolean isLatest) {
 310  
                          
 311  
                             // TODO PLEASE REVIEW.  Should we be passing values from async calls to light boxes
 312  
                             // using instance variables like this? (we are doing this in course as well)
 313  0
                             isCurrentVersion = isLatest;
 314  
                             
 315  
                             // Populate the action box drop-down with different values depending 
 316  
                             // on if we are working with the latest version of the program 
 317  
                             // or a historical version
 318  0
                         actionBox.setList(ActionType.getValuesForMajorDiscipline(isLatest));        
 319  0
                          }                
 320  
         });
 321  
             
 322  
            
 323  
             // Get the reference ID of the proposal from the XML model
 324  
             // Note: the filter puts in in the model, see ProposalWorkflowFilter.applyOutboundDataFilter
 325  0
             String referenceId = programModel.getRoot().get("id");
 326  
             
 327  
             // When the program being viewed is in DRAFT state, check to see if it exists as part of program proposal instead of admin modify. 
 328  
             // If its part of a program proposal then we don't want to display the program actions drop down since user is not allowed to take
 329  
             // any actions on a DRAFT program proposal outside of proposal process.
 330  
             // TODO PLEASE REVIEW.  If this async call runs slow, will the box remain visible? Is this an issue?
 331  
             //      Answer: Yes, it might be an issue, possible solution might to block user action w/progress bar until finished.            
 332  0
         if (status == ProgramStatus.DRAFT){
 333  0
                     programRemoteService.isProposal( "kuali.proposal.referenceType.clu", referenceId,  new KSAsyncCallback<Boolean>(){
 334  
                     public void onSuccess(Boolean isProposal) {
 335  
                      
 336  
                         // If this is a proposal then we cannot take any actions on it
 337  
                         // So hide the action box
 338  0
                         if (isProposal){
 339  0
                             actionBox.setVisible(false);
 340  
                         }
 341  
                       
 342  0
                     }           
 343  
                 });
 344  
         }
 345  0
     } 
 346  
   
 347  
     private void showVariationView() {
 348  0
         String variationId = context.getAttributes().get(ProgramConstants.VARIATION_ID);
 349  0
         if (variationId != null) {
 350  0
             final Data variationMap = getDataProperty(ProgramConstants.VARIATIONS);
 351  0
             if (variationMap != null) {
 352  0
                 int row = 0;
 353  0
                 for (Property p : variationMap) {
 354  0
                     final Data variationData = p.getValue();
 355  0
                     if (variationData != null) {
 356  0
                         if (variationData.get(ProgramConstants.ID).equals(variationId)) {
 357  
                             //FIXME: Find a better way to do this.
 358  
                             // We shouldn't be maintaining two separate datamodels for progs and variations
 359  0
                             Data credData = getDataProperty(ProgramConstants.CREDENTIAL_PROGRAM);
 360  0
                             variationData.set(ProgramConstants.CREDENTIAL_PROGRAM, credData);
 361  0
                             ProgramRegistry.setData(variationData);
 362  0
                             ProgramRegistry.setRow(row);
 363  
                         }
 364  0
                         row++;
 365  
                     }
 366  0
                 }
 367  0
                 HistoryManager.navigate(AppLocations.Locations.VIEW_VARIATION.getLocation(), context);
 368  
             }
 369  
         }
 370  0
     }
 371  
 
 372  
     @Override
 373  
     protected void configureView() {
 374  0
         super.configureView();
 375  0
         addContentWidget(actionBox);
 376  0
         initialized = true;
 377  0
     }
 378  
 }