Coverage Report - org.kuali.student.lum.program.client.core.view.CoreViewController
 
Classes in this File Line Coverage Branch Coverage Complexity
CoreViewController
0%
0/22
0%
0/2
1.375
CoreViewController$1
0%
0/12
0%
0/4
1.375
CoreViewController$2
0%
0/3
N/A
1.375
CoreViewController$3
0%
0/3
N/A
1.375
CoreViewController$4
0%
0/3
N/A
1.375
 
 1  
 package org.kuali.student.lum.program.client.core.view;
 2  
 
 3  
 import com.google.gwt.core.client.GWT;
 4  
 import com.google.gwt.event.dom.client.ChangeEvent;
 5  
 import com.google.gwt.event.dom.client.ChangeHandler;
 6  
 import com.google.gwt.event.shared.HandlerManager;
 7  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 8  
 import org.kuali.student.common.ui.client.application.ViewContext;
 9  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 10  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 11  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 12  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 13  
 import org.kuali.student.lum.common.client.widgets.DropdownList;
 14  
 import org.kuali.student.lum.program.client.ProgramConstants;
 15  
 import org.kuali.student.lum.program.client.ProgramRegistry;
 16  
 import org.kuali.student.lum.program.client.ProgramSections;
 17  
 import org.kuali.student.lum.program.client.ProgramStatus;
 18  
 import org.kuali.student.lum.program.client.core.CoreController;
 19  
 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
 20  
 import org.kuali.student.lum.program.client.events.ProgramViewEvent;
 21  
 import org.kuali.student.lum.program.client.major.ActionType;
 22  
 
 23  
 /**
 24  
  * @author Igor
 25  
  */
 26  0
 public class CoreViewController extends CoreController {
 27  
 
 28  
     /**
 29  
      * Initialize the action drop-down with a list of values.  Note that these values
 30  
      * will be changed further down in the code depending on if we are working with the latest 
 31  
      * version of the program.
 32  
      */ 
 33  0
     private final DropdownList actionBox = new DropdownList(ActionType.getValuesForCoreProgram(false));
 34  
 
 35  
     /**
 36  
      * Constructor.
 37  
      *
 38  
      * @param programModel
 39  
      */
 40  
     public CoreViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) {
 41  0
         super(programModel, viewContext, eventBus);
 42  0
         configurer = GWT.create(CoreViewConfigurer.class);
 43  0
         bind();
 44  0
     }
 45  
 
 46  
     private void bind() {
 47  0
         actionBox.addChangeHandler(new ChangeHandler() {
 48  
             @Override
 49  
             public void onChange(ChangeEvent event) {
 50  0
                 ActionType actionType = ActionType.of(actionBox.getSelectedValue());
 51  0
                 ViewContext viewContext = getViewContext();
 52  0
                 if (actionType == ActionType.MODIFY) {
 53  0
                     ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum()));
 54  0
                     HistoryManager.navigate(AppLocations.Locations.EDIT_CORE_PROGRAM.getLocation(), viewContext);
 55  0
                 } else if (actionType == ActionType.MODIFY_VERSION) {
 56  0
                     String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID);
 57  0
                     viewContext.setId(versionIndId);
 58  0
                     viewContext.setIdType(IdType.COPY_OF_OBJECT_ID);
 59  0
                     HistoryManager.navigate(AppLocations.Locations.EDIT_CORE_PROGRAM.getLocation(), viewContext);
 60  
                 }
 61  0
             }
 62  
         });
 63  0
         eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() {
 64  
             @Override
 65  
             public void onEvent(ProgramViewEvent event) {
 66  0
                 actionBox.setSelectedIndex(0);
 67  0
             }
 68  
         });
 69  0
         eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() {
 70  
             @Override
 71  
             public void onEvent(ModelLoadedEvent event) {
 72  0
                 resetActionList();
 73  0
             }
 74  
         });
 75  0
     }
 76  
 
 77  
     @Override
 78  
     protected void configureView() {
 79  0
         super.configureView();
 80  0
         addContentWidget(actionBox);
 81  0
         initialized = true;
 82  0
     }
 83  
 
 84  
     protected void resetActionList() {
 85  
         //Only allow modify with version option for an active course that id also the latest version
 86  0
         ProgramStatus status = ProgramStatus.of(programModel.<String>get(ProgramConstants.STATE));
 87  0
         String versionIndId = programModel.get(ProgramConstants.VERSION_IND_ID);
 88  0
         Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER);
 89  
 
 90  0
         actionBox.clear();
 91  0
         if (status == ProgramStatus.ACTIVE) {
 92  0
             programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>() {
 93  
                 public void onSuccess(Boolean isLatest) {
 94  0
                     actionBox.setList(ActionType.getValuesForCoreProgram(isLatest));
 95  0
                 }
 96  
             });
 97  
         } else {
 98  0
             actionBox.setList(ActionType.getValuesForCoreProgram(false));
 99  
         }
 100  0
     }
 101  
 }