Coverage Report - org.kuali.student.lum.program.client.widgets.SummaryActionPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
SummaryActionPanel
0%
0/59
0%
0/10
1.316
SummaryActionPanel$1
0%
0/4
N/A
1.316
SummaryActionPanel$2
0%
0/4
N/A
1.316
SummaryActionPanel$3
0%
0/3
N/A
1.316
SummaryActionPanel$4
0%
0/3
N/A
1.316
SummaryActionPanel$5
0%
0/3
N/A
1.316
SummaryActionPanel$6
0%
0/4
N/A
1.316
SummaryActionPanel$6$1
0%
0/6
0%
0/2
1.316
SummaryActionPanel$7
0%
0/3
N/A
1.316
 
 1  
 package org.kuali.student.lum.program.client.widgets;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.kuali.student.common.ui.client.application.Application;
 6  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 7  
 import org.kuali.student.common.ui.client.mvc.Callback;
 8  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 9  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 10  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 11  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 12  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 13  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 14  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 15  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 16  
 import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel;
 17  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 18  
 import org.kuali.student.lum.program.client.ProgramConstants;
 19  
 import org.kuali.student.lum.program.client.ProgramMsgConstants;
 20  
 import org.kuali.student.lum.program.client.ProgramStatus;
 21  
 import org.kuali.student.lum.program.client.events.AfterSaveEvent;
 22  
 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
 23  
 import org.kuali.student.lum.program.client.events.StateChangeEvent;
 24  
 
 25  
 import com.google.gwt.event.dom.client.ClickEvent;
 26  
 import com.google.gwt.event.dom.client.ClickHandler;
 27  
 import com.google.gwt.event.shared.HandlerManager;
 28  
 import com.google.gwt.user.client.ui.Anchor;
 29  
 import com.google.gwt.user.client.ui.Composite;
 30  
 import com.google.gwt.user.client.ui.FlowPanel;
 31  
 import com.google.gwt.user.client.ui.HasVerticalAlignment;
 32  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 33  
 import com.google.gwt.user.client.ui.Widget;
 34  
 
 35  
 /**
 36  
  * @author Igor
 37  
  */
 38  0
 public class SummaryActionPanel extends Composite {
 39  
 
 40  0
     private final HorizontalPanel content = new HorizontalPanel();
 41  
 
 42  0
     private final KSButton approveButton = new KSButton(getLabel(ProgramMsgConstants.BUTTON_APPROVE));
 43  
 
 44  0
     private final KSButton activateButton = new KSButton(getLabel(ProgramMsgConstants.BUTTON_ACTIVATE), ButtonStyle.SECONDARY);
 45  
 
 46  0
     private final Anchor exitAnchor = new Anchor(getLabel(ProgramMsgConstants.LINK_BACKCURRICULUM));
 47  
 
 48  0
     private final KSLightBox activateDialog = new KSLightBox();
 49  
     private Section activateSection;
 50  
 
 51  
     private DataModel dataModel;
 52  
 
 53  
     private HandlerManager eventBus;
 54  
 
 55  0
     public SummaryActionPanel(Section activateSection, HandlerManager eventBus) {
 56  0
         initWidget(content);
 57  0
         this.activateSection = activateSection;
 58  0
         this.eventBus = eventBus;
 59  0
         buildLayout();
 60  0
         setStyles();
 61  0
         bind();
 62  0
     }
 63  
 
 64  
     private void bind() {
 65  0
         eventBus.addHandler(AfterSaveEvent.TYPE, new AfterSaveEvent.Handler() {
 66  
             @Override
 67  
             public void onEvent(AfterSaveEvent event) {
 68  0
                 dataModel = event.getModel();
 69  0
                 processStatus();
 70  0
             }
 71  
         });
 72  0
         eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() {
 73  
             @Override
 74  
             public void onEvent(ModelLoadedEvent event) {
 75  0
                 dataModel = event.getModel();
 76  0
                 processStatus();
 77  0
             }
 78  
         });
 79  0
         approveButton.addClickHandler(new ClickHandler() {
 80  
             @Override
 81  
             public void onClick(ClickEvent event) {
 82  0
                 processButtonClick(ProgramStatus.APPROVED);
 83  0
             }
 84  
         });
 85  0
         activateButton.addClickHandler(new ClickHandler() {
 86  
             @Override
 87  
             public void onClick(ClickEvent event) {
 88  0
                 processActivateClick();
 89  0
             }
 90  
         });
 91  0
         exitAnchor.addClickHandler(new ClickHandler() {
 92  
             @Override
 93  
             public void onClick(ClickEvent event) {
 94  0
                 HistoryManager.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation());
 95  0
             }
 96  
         });
 97  0
     }
 98  
 
 99  
     private void processStatus() {
 100  0
         processStatus(ProgramStatus.of(dataModel));
 101  0
     }
 102  
 
 103  
     private void processButtonClick(ProgramStatus status) {
 104  0
         eventBus.fireEvent(new StateChangeEvent(status));
 105  0
     }
 106  
 
 107  
     private void processActivateClick() {
 108  0
         String versionFromId = dataModel.get(ProgramConstants.VERSION_FROM_ID);
 109  0
         if (versionFromId != null) {
 110  0
             activateSection.updateWidgetData(dataModel);
 111  0
             activateDialog.show();
 112  
         } else {
 113  0
             processButtonClick(ProgramStatus.ACTIVE);
 114  
         }
 115  0
     }
 116  
 
 117  
     private void processStatus(ProgramStatus programStatus) {
 118  0
         if (programStatus == ProgramStatus.DRAFT) {
 119  0
             enableButtons(true, false);
 120  0
         } else if (programStatus == ProgramStatus.APPROVED) {
 121  0
             enableButtons(false, true);
 122  0
         } else if (programStatus == ProgramStatus.ACTIVE) {
 123  0
             enableButtons(false, false);
 124  0
         } else if (programStatus == ProgramStatus.SUPERSEDED) {
 125  0
             content.setVisible(false);
 126  
         }
 127  0
     }
 128  
 
 129  
     private void setStyles() {
 130  0
         content.addStyleName("programActionPanel");
 131  0
         content.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
 132  0
     }
 133  
 
 134  
     private void buildLayout() {
 135  0
         content.add(approveButton);
 136  0
         content.add(activateButton);
 137  0
         content.add(exitAnchor);
 138  
 
 139  0
         buildActivateDialog();
 140  0
     }
 141  
 
 142  
     private void buildActivateDialog() {
 143  0
         FlowPanel panel = new FlowPanel();
 144  
 
 145  0
         panel.add((Widget) activateSection);
 146  
 
 147  0
         KSButton activate = new KSButton(getLabel(ProgramMsgConstants.BUTTON_ACTIVATE), new ClickHandler() {
 148  
             public void onClick(ClickEvent event) {
 149  0
                 activateSection.updateModel(dataModel);
 150  0
                 dataModel.validate(new Callback<List<ValidationResultInfo>>(){
 151  
                                         @Override
 152  
                                         public void exec(List<ValidationResultInfo> results) {
 153  
                                                 // Process the results on the additional fields view
 154  0
                         if (ErrorLevel.OK.equals(activateSection.processValidationResults(results))) {
 155  
                             // Call activate once the data is valid
 156  0
                                                     processButtonClick(ProgramStatus.ACTIVE);
 157  0
                                     activateDialog.hide();
 158  
                         } else {
 159  0
                             KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000));
 160  
                         }
 161  
 
 162  0
                                         }
 163  
                 });
 164  0
             }
 165  
         });
 166  0
         activateDialog.addButton(activate);
 167  
 
 168  0
         KSButton cancel = new KSButton(getLabel(ProgramMsgConstants.COMMON_CANCEL), ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler() {
 169  
             public void onClick(ClickEvent event) {
 170  0
                 activateDialog.hide();
 171  0
             }
 172  
         });
 173  0
         activateDialog.addButton(cancel);
 174  
 
 175  0
         activateDialog.setWidget(panel);
 176  0
     }
 177  
 
 178  
     private void enableButtons(boolean enableApprove, boolean enableActivate) {
 179  0
         approveButton.setEnabled(enableApprove);
 180  0
         activateButton.setEnabled(enableActivate);
 181  0
     }
 182  
     
 183  
     protected String getLabel(String messageKey) {
 184  0
         return Application.getApplicationContext().getUILabel(ProgramMsgConstants.PROGRAM_MSG_GROUP, messageKey);
 185  
     }
 186  
 }