Coverage Report - org.kuali.student.lum.program.client.credential.edit.CredentialManagingBodiesEditConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
CredentialManagingBodiesEditConfiguration
0%
0/29
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.FieldDescriptor;
 6  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection;
 7  
 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
 8  
 import org.kuali.student.common.ui.client.mvc.Callback;
 9  
 import org.kuali.student.common.ui.client.widgets.KSCheckBox;
 10  
 import org.kuali.student.common.ui.client.widgets.KSItemLabel;
 11  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
 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.ProgramSections;
 17  
 import org.kuali.student.lum.program.client.properties.ProgramProperties;
 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() {
 28  0
         rootSection = new VerticalSectionView(ProgramSections.MANAGE_BODIES_EDIT, ProgramProperties.get().program_menu_sections_managingBodies(), ProgramConstants.PROGRAM_MODEL_ID);
 29  0
     }
 30  
 
 31  
     @Override
 32  
     protected void buildLayout() {
 33  
             HorizontalSection section;
 34  
         
 35  0
         section = new HorizontalSection();
 36  0
         FieldDescriptor cou = configurer.addField(section, ProgramConstants.CURRICULUM_OVERSIGHT_UNIT, new MessageKeyInfo(ProgramProperties.get().managingBodies_curriculumOversightUnit()));
 37  0
         FieldDescriptor cod = configurer.addField(section, ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION, new MessageKeyInfo(ProgramProperties.get().managingBodies_curriculumOversightDivision()));
 38  0
         rootSection.addSection(section);
 39  
         
 40  0
         section = new HorizontalSection();
 41  0
         FieldDescriptor sou = configurer.addField(section, ProgramConstants.STUDENT_OVERSIGHT_UNIT, new MessageKeyInfo(ProgramProperties.get().managingBodies_studentOversightUnit()));
 42  0
         FieldDescriptor sod = configurer.addField(section, ProgramConstants.STUDENT_OVERSIGHT_DIVISION, new MessageKeyInfo(ProgramProperties.get().managingBodies_studentOversightDivision()));
 43  0
         rootSection.addSection(section);
 44  
         
 45  0
         final KSCheckBox unitCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all units below");//Make a message
 46  0
         final KSCheckBox divisionCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all divisions below");//Make a message
 47  0
         unitCheckBox.setValue(true);
 48  0
         divisionCheckBox.setValue(true);
 49  0
         final KSSelectedList[] unitSelects = new KSSelectedList[]{(KSSelectedList) sou.getFieldWidget()};
 50  0
         final KSSelectedList[] divisionSelects = new KSSelectedList[]{(KSSelectedList) sod.getFieldWidget()};
 51  
 
 52  0
         rootSection.addStyleName("KS-Dropdown-Short");
 53  
         
 54  
         //get a handle to the add to list button, chain in adding to all fds 
 55  0
         if(cou.getFieldWidget() instanceof KSSelectedList){
 56  0
                 final KSSelectedList couWidget = (KSSelectedList)cou.getFieldWidget();
 57  
                 
 58  0
                 couWidget.getMainPanel().insert(unitCheckBox, 1);
 59  0
                 couWidget.getAddItemButton().addClickHandler(new ClickHandler(){
 60  
                                 public void onClick(ClickEvent event) {
 61  0
                                         if(unitCheckBox.getValue()){
 62  0
                                                 KSItemLabel lastAdded = couWidget.getSelectedItems().get(couWidget.getSelectedItems().size()-1);
 63  0
                             for(KSSelectedList select:unitSelects){
 64  0
                                 select.addItem(lastAdded.getKey(), lastAdded.getDisplayText());
 65  
                         }
 66  
                         }
 67  0
                                 }
 68  
                 });
 69  
                 
 70  
                 //Also add a hook into the advanced search
 71  0
                 final Callback<List<SelectedResults>> originalAdvancedSearchCallback = couWidget.getPicker().getAdvancedSearchCallback();
 72  
                 
 73  0
                 couWidget.getPicker().setAdvancedSearchCallback(new Callback<List<SelectedResults>>() {
 74  
                 public void exec(List<SelectedResults> results) {
 75  
                         //Chain the original call and add the new item(s) to the rest of the selects
 76  0
                         originalAdvancedSearchCallback.exec(results);
 77  0
                     if (unitCheckBox.getValue() && results.size() > 0) {
 78  0
                                                 for (SelectedResults res : results) {
 79  0
                             for(KSSelectedList select:unitSelects){
 80  0
                                     select.addItem(res.getReturnKey(), res.getDisplayKey());
 81  
                             }
 82  
                             }
 83  
                     }
 84  0
                 }
 85  
             });
 86  
                 
 87  
         }
 88  
         
 89  0
         if(cod.getFieldWidget() instanceof KSSelectedList){
 90  0
                 final KSSelectedList codWidget = (KSSelectedList)cod.getFieldWidget();
 91  0
                 codWidget.getMainPanel().insert(divisionCheckBox, 1);
 92  0
                 codWidget.getAddItemButton().addClickHandler(new ClickHandler(){
 93  
                                 public void onClick(ClickEvent event) {
 94  0
                                         if(divisionCheckBox.getValue()){
 95  0
                                                 KSItemLabel lastAdded = codWidget.getSelectedItems().get(codWidget.getSelectedItems().size()-1);
 96  0
                             for(KSSelectedList select:divisionSelects){
 97  0
                                 select.addItem(lastAdded.getKey(), lastAdded.getDisplayText());
 98  
                         }
 99  
                         }
 100  0
                                 }
 101  
                 });
 102  
         }
 103  0
     }
 104  
 }