Coverage Report - org.kuali.student.lum.program.client.requirements.ProgramRequirementsViewController
 
Classes in this File Line Coverage Branch Coverage Complexity
ProgramRequirementsViewController
0%
0/31
0%
0/10
2.545
ProgramRequirementsViewController$1
0%
0/3
N/A
2.545
ProgramRequirementsViewController$2
0%
0/18
0%
0/8
2.545
ProgramRequirementsViewController$2$1
0%
0/3
N/A
2.545
ProgramRequirementsViewController$2$2
0%
0/11
0%
0/4
2.545
ProgramRequirementsViewController$2$2$1
0%
0/3
N/A
2.545
ProgramRequirementsViewController$3
0%
0/1
N/A
2.545
ProgramRequirementsViewController$ProgramRequirementsViews
0%
0/3
N/A
2.545
 
 1  
 package org.kuali.student.lum.program.client.requirements;
 2  
 
 3  
 import org.kuali.student.common.ui.client.configurable.mvc.layouts.BasicLayout;
 4  
 import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
 5  
 import org.kuali.student.common.ui.client.mvc.*;
 6  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations;
 7  
 import org.kuali.student.common.ui.client.widgets.dialog.ButtonMessageDialog;
 8  
 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup;
 9  
 import org.kuali.student.common.ui.client.widgets.field.layout.button.YesNoCancelGroup;
 10  
 import org.kuali.student.lum.program.client.ProgramConstants;
 11  
 import org.kuali.student.lum.program.client.properties.ProgramProperties;
 12  
 import org.kuali.student.lum.program.client.widgets.EditableHeader;
 13  
 
 14  
 import com.google.gwt.event.shared.HandlerManager;
 15  
 
 16  0
 public class ProgramRequirementsViewController extends BasicLayout {
 17  
 
 18  0
     public enum ProgramRequirementsViews {
 19  0
         PREVIEW,
 20  0
         MANAGE
 21  
     }
 22  
 
 23  
     public static final String PROGRAM_RULES_MODEL_ID = "programRulesModelId";
 24  
     private ProgramRequirementsSummaryView preview;
 25  
     boolean reloadFlag;
 26  
 
 27  
     public ProgramRequirementsViewController(Controller controller, HandlerManager eventBus, String name, Enum<?> viewType, boolean isReadOnly, EditableHeader header, boolean reloadFlag){
 28  0
         this(controller, eventBus, name, viewType, isReadOnly, header);
 29  0
         this.reloadFlag = reloadFlag;
 30  0
     }
 31  
 
 32  
     public ProgramRequirementsViewController(Controller controller, HandlerManager eventBus, String name, Enum<?> viewType, boolean isReadOnly, EditableHeader header) {
 33  0
         super(ProgramRequirementsViewController.class.getName());
 34  0
         super.setController(controller);
 35  0
         super.setName(name);
 36  0
         super.setViewEnum(viewType);
 37  0
         super.setDefaultModelId(PROGRAM_RULES_MODEL_ID);
 38  0
         super.setParentController(controller);
 39  
 
 40  0
         this.setDefaultView(ProgramRequirementsViews.PREVIEW);
 41  
 
 42  
         //not used
 43  0
         super.registerModel(PROGRAM_RULES_MODEL_ID, new ModelProvider<DataModel>() {
 44  
             @Override
 45  
             public void requestModel(final ModelRequestCallback<DataModel> callback) {
 46  0
                 callback.onModelReady(new DataModel());
 47  0
             }
 48  
         });
 49  
 
 50  
         //no name for the view so that breadcrumbs do not extra link
 51  0
         String previewTitle = ProgramProperties.get().program_menu_sections_requirements();
 52  0
         if (isReadOnly && (header != null)) {
 53  0
             preview = new ProgramRequirementsSummaryView(this, eventBus, ProgramRequirementsViews.PREVIEW, "", ProgramConstants.PROGRAM_MODEL_ID, isReadOnly, header);                                                            
 54  
         } else {
 55  0
             preview = new ProgramRequirementsSummaryView(this, eventBus, ProgramRequirementsViews.PREVIEW, (isReadOnly ? previewTitle : ""), ProgramConstants.PROGRAM_MODEL_ID, isReadOnly);
 56  
         }
 57  0
         super.addView(preview);
 58  
 
 59  0
         if (!isReadOnly) {
 60  0
             ProgramRequirementsManageView manageView = new ProgramRequirementsManageView(this, ProgramRequirementsViews.MANAGE, "Add and Combine Rules", PROGRAM_RULES_MODEL_ID);
 61  0
             super.addView(manageView);
 62  
         }
 63  0
     }
 64  
 
 65  
     @Override
 66  
     public void updateModel() {
 67  0
         preview.updateModel();
 68  0
     }
 69  
 
 70  
     @Override
 71  
     public void beforeViewChange(final Enum<?> viewChangingTo, final Callback<Boolean> okToChange) {
 72  
 
 73  0
         if (getCurrentView() == null) {
 74  0
             okToChange.exec(true);
 75  0
             return;
 76  
         }
 77  
 
 78  0
         super.beforeViewChange(viewChangingTo, new Callback<Boolean>() {
 79  
 
 80  
             @Override
 81  
             public void exec(Boolean result) {
 82  
 
 83  
                 //moving from PREVIEW to MANAGE page
 84  
                 //no dialog if user is going to the Manage Rule page
 85  0
                 if (viewChangingTo.name().equals(ProgramRequirementsViews.MANAGE.name()))
 86  
                 {
 87  0
                     okToChange.exec(true);
 88  0
                     return;
 89  
                 }
 90  
 
 91  
                 //moving from MANAGE to PREVIEW page
 92  
                 //no dialog if user clicks on the 'Save' or cancel button on the Manage Rule page
 93  0
                 if (getCurrentView() instanceof ProgramRequirementsManageView) {
 94  0
                     okToChange.exec(true);
 95  0
                     return;
 96  
                 }
 97  
 
 98  
                 //moving from MANAGE to other page
 99  
                 //TODO show dialog if user clicks on a menu from Manage Rules page                
 100  
 
 101  
                 //moving from other page to PREVIEW page
 102  0
                 if (viewChangingTo.name().equals(ProgramRequirementsViews.PREVIEW.name())) {
 103  0
                     preview.getRules().setupRules(ProgramRequirementsViewController.this, ProgramConstants.PROGRAM_MODEL_ID, new Callback<Boolean>() {
 104  
                         @Override
 105  
                         public void exec(Boolean result) {
 106  0
                             okToChange.exec(result);
 107  0
                             return;
 108  
                         }
 109  
                     });
 110  0
                     return;
 111  
                 }
 112  
 
 113  
                 //moving from PREVIEW to other page (rules have NOT changed)
 114  
                 //user is moving to another program section and no changes were made to the rules so allow it to happen
 115  0
                 if (!((SectionView) getCurrentView()).isDirty()) {
 116  0
                     okToChange.exec(true);
 117  0
                     return;
 118  
                 }
 119  
 
 120  
                 //moving from PREVIEW to other page (rules have changed)
 121  
                 //user is moving to another program section and rules have been changed, user needs to either save rules or abandon changes before proceeding
 122  0
                 ButtonGroup<ButtonEnumerations.YesNoCancelEnum> buttonGroup = new YesNoCancelGroup();
 123  0
                 final ButtonMessageDialog<ButtonEnumerations.YesNoCancelEnum> dialog =
 124  
                         new ButtonMessageDialog<ButtonEnumerations.YesNoCancelEnum>("Warning", "You may have unsaved changes.  Save changes?", buttonGroup);
 125  0
                 buttonGroup.addCallback(new Callback<ButtonEnumerations.YesNoCancelEnum>() {
 126  
 
 127  
                     @Override
 128  
                     public void exec(ButtonEnumerations.YesNoCancelEnum result) {
 129  0
                         switch (result) {
 130  
                             case YES:
 131  0
                                 dialog.hide();
 132  0
                                 preview.storeRules(new Callback<Boolean>() {
 133  
                                     @Override
 134  
                                     public void exec(Boolean result) {
 135  0
                                         okToChange.exec(true);
 136  0
                                     }
 137  
                                 });
 138  0
                                 break;
 139  
                             case NO:
 140  0
                                 dialog.hide();
 141  
                                 //preview.revertRuleChanges();     //TODO put back if we will NOT reset rules every time user comes to PREVIEW page above...
 142  0
                                 okToChange.exec(true);
 143  0
                                 break;
 144  
                             case CANCEL:
 145  0
                                 okToChange.exec(false);
 146  0
                                 dialog.hide();
 147  
                                 break;
 148  
                         }
 149  0
                     }
 150  
                 });
 151  0
                 dialog.show();
 152  0
             }
 153  
         });
 154  0
     }
 155  
 
 156  
     @Override
 157  
     public void beforeShow(final Callback<Boolean> onReadyCallback) {
 158  0
         showDefaultView(onReadyCallback);
 159  0
     }
 160  
 
 161  
     public ProgramRequirementsSummaryView getProgramRequirementsView() {
 162  0
         return preview;
 163  
     }
 164  
 }