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
24
25 public class CredentialManagingBodiesEditConfiguration extends AbstractSectionConfiguration {
26
27 public CredentialManagingBodiesEditConfiguration(Configurer configurer) {
28 this.setConfigurer(configurer);
29 rootSection = new VerticalSectionView(ProgramSections.MANAGE_BODIES_EDIT, getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_MANAGINGBODIES),
30 ProgramConstants.PROGRAM_MODEL_ID);
31 }
32
33 @Override
34 protected void buildLayout() {
35 HorizontalSection section;
36
37 section = new HorizontalSection();
38 FieldDescriptor cou = configurer.addField(section, ProgramConstants.CURRICULUM_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTUNIT));
39 FieldDescriptor cod = configurer.addField(section, ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTDIVISION));
40 rootSection.addSection(section);
41
42 section = new HorizontalSection();
43 FieldDescriptor sou = configurer.addField(section, ProgramConstants.STUDENT_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTUNIT));
44 FieldDescriptor sod = configurer.addField(section, ProgramConstants.STUDENT_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTDIVISION));
45 rootSection.addSection(section);
46
47 final KSCheckBox unitCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all units below");
48 final KSCheckBox divisionCheckBox = new KSCheckBox("I want the \"Add to List\" button to populate all divisions below");
49 unitCheckBox.setValue(true);
50 divisionCheckBox.setValue(true);
51 final KSSelectedList[] unitSelects = new KSSelectedList[]{(KSSelectedList) sou.getFieldWidget()};
52 final KSSelectedList[] divisionSelects = new KSSelectedList[]{(KSSelectedList) sod.getFieldWidget()};
53
54 rootSection.addStyleName("KS-Dropdown-Short");
55
56
57 if(cou.getFieldWidget() instanceof KSSelectedList){
58 final KSSelectedList couWidget = (KSSelectedList)cou.getFieldWidget();
59
60 couWidget.getMainPanel().insert(unitCheckBox, 1);
61 couWidget.getAddItemButton().addClickHandler(new ClickHandler(){
62 public void onClick(ClickEvent event) {
63 if(unitCheckBox.getValue()){
64 KSItemLabel lastAdded = couWidget.getSelectedItems().get(couWidget.getSelectedItems().size()-1);
65 for(KSSelectedList select:unitSelects){
66 select.addItem(lastAdded.getKey(), lastAdded.getDisplayText());
67 }
68 }
69 }
70 });
71
72
73 final Callback<List<SelectedResults>> originalAdvancedSearchCallback = couWidget.getPicker().getAdvancedSearchCallback();
74
75 couWidget.getPicker().setAdvancedSearchCallback(new Callback<List<SelectedResults>>() {
76 public void exec(List<SelectedResults> results) {
77
78 originalAdvancedSearchCallback.exec(results);
79 if (unitCheckBox.getValue() && results.size() > 0) {
80 for (SelectedResults res : results) {
81 for(KSSelectedList select:unitSelects){
82 select.addItem(res.getReturnKey(), res.getDisplayKey());
83 }
84 }
85 }
86 }
87 });
88
89 }
90
91 if(cod.getFieldWidget() instanceof KSSelectedList){
92 final KSSelectedList codWidget = (KSSelectedList)cod.getFieldWidget();
93 codWidget.getMainPanel().insert(divisionCheckBox, 1);
94 codWidget.getAddItemButton().addClickHandler(new ClickHandler(){
95 public void onClick(ClickEvent event) {
96 if(divisionCheckBox.getValue()){
97 KSItemLabel lastAdded = codWidget.getSelectedItems().get(codWidget.getSelectedItems().size()-1);
98 for(KSSelectedList select:divisionSelects){
99 select.addItem(lastAdded.getKey(), lastAdded.getDisplayText());
100 }
101 }
102 }
103 });
104 }
105 }
106 }