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