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