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