Coverage Report - org.kuali.student.lum.program.client.credential.edit.CredentialManagingBodiesEditConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
CredentialManagingBodiesEditConfiguration
0%
0/30
0%
0/4
3
CredentialManagingBodiesEditConfiguration$1
0%
0/6
0%
0/4
3
CredentialManagingBodiesEditConfiguration$2
0%
0/7
0%
0/8
3
CredentialManagingBodiesEditConfiguration$3
0%
0/6
0%
0/4
3
 
 1  
 package org.kuali.student.lum.program.client.credential.edit;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.kuali.student.common.ui.client.configurable.mvc.Configurer;
 6  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 7  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection;
 8  
 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
 9  
 import org.kuali.student.common.ui.client.mvc.Callback;
 10  
 import org.kuali.student.common.ui.client.widgets.KSCheckBox;
 11  
 import org.kuali.student.common.ui.client.widgets.KSItemLabel;
 12  
 import org.kuali.student.common.ui.client.widgets.list.KSSelectedList;
 13  
 import org.kuali.student.common.ui.client.widgets.search.SelectedResults;
 14  
 import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
 15  
 import org.kuali.student.lum.program.client.ProgramConstants;
 16  
 import org.kuali.student.lum.program.client.ProgramMsgConstants;
 17  
 import org.kuali.student.lum.program.client.ProgramSections;
 18  
 
 19  
 import com.google.gwt.event.dom.client.ClickEvent;
 20  
 import com.google.gwt.event.dom.client.ClickHandler;
 21  
 
 22  
 /**
 23  
  * @author Igor
 24  
  */
 25  
 public class CredentialManagingBodiesEditConfiguration extends AbstractSectionConfiguration {
 26  
 
 27  0
     public CredentialManagingBodiesEditConfiguration(Configurer configurer) {
 28  0
         this.setConfigurer(configurer);
 29  0
         rootSection = new VerticalSectionView(ProgramSections.MANAGE_BODIES_EDIT, getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_MANAGINGBODIES), 
 30  
                 ProgramConstants.PROGRAM_MODEL_ID);
 31  0
     }
 32  
 
 33  
     @Override
 34  
     protected void buildLayout() {
 35  
             HorizontalSection section;
 36  
         
 37  0
         section = new HorizontalSection();
 38  0
         FieldDescriptor cou = configurer.addField(section, ProgramConstants.CURRICULUM_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTUNIT));
 39  0
         FieldDescriptor cod = configurer.addField(section, ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTDIVISION));
 40  0
         rootSection.addSection(section);
 41  
         
 42  0
         section = new HorizontalSection();
 43  0
         FieldDescriptor sou = configurer.addField(section, ProgramConstants.STUDENT_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTUNIT));
 44  0
         FieldDescriptor sod = configurer.addField(section, ProgramConstants.STUDENT_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTDIVISION));
 45  0
         rootSection.addSection(section);
 46  
         
 47  0
         final KSCheckBox unitCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all units below");//Make a message
 48  0
         final KSCheckBox divisionCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all divisions below");//Make a message
 49  0
         unitCheckBox.setValue(true);
 50  0
         divisionCheckBox.setValue(true);
 51  0
         final KSSelectedList[] unitSelects = new KSSelectedList[]{(KSSelectedList) sou.getFieldWidget()};
 52  0
         final KSSelectedList[] divisionSelects = new KSSelectedList[]{(KSSelectedList) sod.getFieldWidget()};
 53  
 
 54  0
         rootSection.addStyleName("KS-Dropdown-Short");
 55  
         
 56  
         //get a handle to the add to list button, chain in adding to all fds 
 57  0
         if(cou.getFieldWidget() instanceof KSSelectedList){
 58  0
                 final KSSelectedList couWidget = (KSSelectedList)cou.getFieldWidget();
 59  
                 
 60  0
                 couWidget.getMainPanel().insert(unitCheckBox, 1);
 61  0
                 couWidget.getAddItemButton().addClickHandler(new ClickHandler(){
 62  
                                 public void onClick(ClickEvent event) {
 63  0
                                         if(unitCheckBox.getValue()){
 64  0
                                                 KSItemLabel lastAdded = couWidget.getSelectedItems().get(couWidget.getSelectedItems().size()-1);
 65  0
                             for(KSSelectedList select:unitSelects){
 66  0
                                 select.addItem(lastAdded.getKey(), lastAdded.getDisplayText());
 67  
                         }
 68  
                         }
 69  0
                                 }
 70  
                 });
 71  
                 
 72  
                 //Also add a hook into the advanced search
 73  0
                 final Callback<List<SelectedResults>> originalAdvancedSearchCallback = couWidget.getPicker().getAdvancedSearchCallback();
 74  
                 
 75  0
                 couWidget.getPicker().setAdvancedSearchCallback(new Callback<List<SelectedResults>>() {
 76  
                 public void exec(List<SelectedResults> results) {
 77  
                         //Chain the original call and add the new item(s) to the rest of the selects
 78  0
                         originalAdvancedSearchCallback.exec(results);
 79  0
                     if (unitCheckBox.getValue() && results.size() > 0) {
 80  0
                                                 for (SelectedResults res : results) {
 81  0
                             for(KSSelectedList select:unitSelects){
 82  0
                                     select.addItem(res.getReturnKey(), res.getDisplayKey());
 83  
                             }
 84  
                             }
 85  
                     }
 86  0
                 }
 87  
             });
 88  
                 
 89  
         }
 90  
         
 91  0
         if(cod.getFieldWidget() instanceof KSSelectedList){
 92  0
                 final KSSelectedList codWidget = (KSSelectedList)cod.getFieldWidget();
 93  0
                 codWidget.getMainPanel().insert(divisionCheckBox, 1);
 94  0
                 codWidget.getAddItemButton().addClickHandler(new ClickHandler(){
 95  
                                 public void onClick(ClickEvent event) {
 96  0
                                         if(divisionCheckBox.getValue()){
 97  0
                                                 KSItemLabel lastAdded = codWidget.getSelectedItems().get(codWidget.getSelectedItems().size()-1);
 98  0
                             for(KSSelectedList select:divisionSelects){
 99  0
                                 select.addItem(lastAdded.getKey(), lastAdded.getDisplayText());
 100  
                         }
 101  
                         }
 102  0
                                 }
 103  
                 });
 104  
         }
 105  0
     }
 106  
 }