| 1 |  |  package org.kuali.student.lum.program.client.major.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 |  |   | 
  | 24 |  |   | 
  | 25 |  |  public class ManagingBodiesEditConfiguration extends AbstractSectionConfiguration { | 
  | 26 |  |   | 
  | 27 | 0 |      public ManagingBodiesEditConfiguration(Configurer configurer) { | 
  | 28 | 0 |          this.setConfigurer(configurer); | 
  | 29 | 0 |          rootSection = new VerticalSectionView(ProgramSections.MANAGE_BODIES_EDIT, getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_MANAGINGBODIES), ProgramConstants.PROGRAM_MODEL_ID); | 
  | 30 | 0 |      } | 
  | 31 |  |   | 
  | 32 |  |      @Override | 
  | 33 |  |      protected void buildLayout() { | 
  | 34 |  |   | 
  | 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 |          section = new HorizontalSection(); | 
  | 48 | 0 |          FieldDescriptor du = configurer.addField(section, ProgramConstants.DEPLOYMENT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_DEPLOYMENTUNIT)); | 
  | 49 | 0 |          FieldDescriptor dd = configurer.addField(section, ProgramConstants.DEPLOYMENT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_DEPLOYMENTDIVISION)); | 
  | 50 | 0 |          rootSection.addSection(section); | 
  | 51 |  |           | 
  | 52 | 0 |          section = new HorizontalSection(); | 
  | 53 | 0 |          FieldDescriptor fru = configurer.addField(section, ProgramConstants.FINANCIAL_RESOURCES_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALRESOURCESUNIT)); | 
  | 54 | 0 |          FieldDescriptor frd = configurer.addField(section, ProgramConstants.FINANCIAL_RESOURCES_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALRESOURCESDIVISION)); | 
  | 55 | 0 |          rootSection.addSection(section); | 
  | 56 |  |           | 
  | 57 | 0 |          section = new HorizontalSection(); | 
  | 58 | 0 |          FieldDescriptor fcu = configurer.addField(section, ProgramConstants.FINANCIAL_CONTROL_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALCONTROLUNIT)); | 
  | 59 | 0 |          FieldDescriptor fcd = configurer.addField(section, ProgramConstants.FINANCIAL_CONTROL_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALCONTROLDIVISION)); | 
  | 60 | 0 |          rootSection.addSection(section); | 
  | 61 |  |   | 
  | 62 | 0 |          final KSCheckBox unitCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all units below"); | 
  | 63 | 0 |          final KSCheckBox divisionCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all divisions below"); | 
  | 64 | 0 |          unitCheckBox.setValue(true); | 
  | 65 | 0 |          divisionCheckBox.setValue(true); | 
  | 66 | 0 |          final KSSelectedList[] unitSelects = new KSSelectedList[]{(KSSelectedList) sou.getFieldWidget(), | 
  | 67 |  |                          (KSSelectedList) du.getFieldWidget(),(KSSelectedList) fru.getFieldWidget(),(KSSelectedList) fcu.getFieldWidget()}; | 
  | 68 | 0 |          final KSSelectedList[] divisionSelects = new KSSelectedList[]{(KSSelectedList) sod.getFieldWidget(), | 
  | 69 |  |                          (KSSelectedList) dd.getFieldWidget(),(KSSelectedList) frd.getFieldWidget(),(KSSelectedList) fcd.getFieldWidget()}; | 
  | 70 |  |   | 
  | 71 | 0 |          rootSection.addStyleName("KS-Dropdown-Short"); | 
  | 72 |  |           | 
  | 73 |  |           | 
  | 74 | 0 |          if(cou.getFieldWidget() instanceof KSSelectedList){ | 
  | 75 | 0 |                  final KSSelectedList couWidget = (KSSelectedList)cou.getFieldWidget(); | 
  | 76 |  |                   | 
  | 77 | 0 |                  couWidget.getMainPanel().insert(unitCheckBox, 1); | 
  | 78 |  |                   | 
  | 79 |  |                   | 
  | 80 |  |                   | 
  | 81 |  |                   | 
  | 82 |  |                   | 
  | 83 |  |                   | 
  | 84 | 0 |                  if (couWidget.getAddItemButton() != null){ | 
  | 85 | 0 |                  couWidget.getAddItemButton().addClickHandler(new ClickHandler(){ | 
  | 86 |  |                                  public void onClick(ClickEvent event) { | 
  | 87 | 0 |                                          if(unitCheckBox.getValue()){ | 
  | 88 | 0 |                                                  KSItemLabel lastAdded = couWidget.getSelectedItems().get(couWidget.getSelectedItems().size()-1); | 
  | 89 | 0 |                              for(KSSelectedList select:unitSelects){ | 
  | 90 | 0 |                                  select.addItem(lastAdded.getKey(), lastAdded.getDisplayText()); | 
  | 91 |  |                          } | 
  | 92 |  |                          } | 
  | 93 | 0 |                                  } | 
  | 94 |  |                  }); | 
  | 95 |  |                  } | 
  | 96 |  |                   | 
  | 97 | 0 |                  if (couWidget.getPicker() != null){ | 
  | 98 | 0 |                  final Callback<List<SelectedResults>> originalAdvancedSearchCallback = couWidget.getPicker().getAdvancedSearchCallback(); | 
  | 99 |  |                   | 
  | 100 | 0 |                  couWidget.getPicker().setAdvancedSearchCallback(new Callback<List<SelectedResults>>() { | 
  | 101 |  |                  public void exec(List<SelectedResults> results) { | 
  | 102 |  |                           | 
  | 103 | 0 |                          originalAdvancedSearchCallback.exec(results); | 
  | 104 | 0 |                      if (unitCheckBox.getValue() && results.size() > 0) { | 
  | 105 | 0 |                                                  for (SelectedResults res : results) { | 
  | 106 | 0 |                              for(KSSelectedList select:unitSelects){ | 
  | 107 | 0 |                                      select.addItem(res.getReturnKey(), res.getDisplayKey()); | 
  | 108 |  |                              } | 
  | 109 |  |                              } | 
  | 110 |  |                      } | 
  | 111 | 0 |                  } | 
  | 112 |  |              }); | 
  | 113 |  |                   | 
  | 114 |  |          } | 
  | 115 |  |          } | 
  | 116 | 0 |          if(cod.getFieldWidget() instanceof KSSelectedList){ | 
  | 117 | 0 |                  final KSSelectedList codWidget = (KSSelectedList)cod.getFieldWidget(); | 
  | 118 | 0 |                  codWidget.getMainPanel().insert(divisionCheckBox, 1); | 
  | 119 | 0 |                  if (codWidget.getAddItemButton() != null){ | 
  | 120 | 0 |                  codWidget.getAddItemButton().addClickHandler(new ClickHandler(){ | 
  | 121 |  |                                  public void onClick(ClickEvent event) { | 
  | 122 | 0 |                                          if(divisionCheckBox.getValue()){ | 
  | 123 | 0 |                                                  KSItemLabel lastAdded = codWidget.getSelectedItems().get(codWidget.getSelectedItems().size()-1); | 
  | 124 | 0 |                              for(KSSelectedList select:divisionSelects){ | 
  | 125 | 0 |                                  select.addItem(lastAdded.getKey(), lastAdded.getDisplayText()); | 
  | 126 |  |                          } | 
  | 127 |  |                          } | 
  | 128 | 0 |                                  } | 
  | 129 |  |                  }); | 
  | 130 |  |                  } | 
  | 131 |  |          } | 
  | 132 |  |           | 
  | 133 |  |   | 
  | 134 | 0 |      } | 
  | 135 |  |   | 
  | 136 |  |  } |