1 package org.kuali.student.lum.program.client.variation.edit;
2
3 import org.kuali.student.common.assembly.data.Metadata;
4 import org.kuali.student.common.assembly.data.QueryPath;
5 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
6 import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport;
7 import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection;
8 import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
9 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
10 import org.kuali.student.common.ui.client.mvc.DataModel;
11 import org.kuali.student.common.ui.client.widgets.KSTextBox;
12 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
13 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
14 import org.kuali.student.common.ui.client.widgets.search.SearchPanel;
15 import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
16 import org.kuali.student.lum.program.client.ProgramConstants;
17 import org.kuali.student.lum.program.client.ProgramSections;
18 import org.kuali.student.lum.program.client.properties.ProgramProperties;
19
20 import com.google.gwt.user.client.ui.Widget;
21
22
23
24
25 public class VariationInformationEditConfiguration extends AbstractSectionConfiguration {
26
27 public VariationInformationEditConfiguration() {
28 rootSection = new VerticalSectionView(ProgramSections.PROGRAM_DETAILS_EDIT, ProgramProperties.get().program_menu_sections_programInformation(), ProgramConstants.PROGRAM_MODEL_ID);
29 }
30
31 @Override
32 protected void buildLayout() {
33 HorizontalSection horizontalSection = new HorizontalSection();
34 horizontalSection.addSection(createLeftSection());
35 horizontalSection.addSection(createRightSection());
36 rootSection.addSection(horizontalSection);
37 }
38
39 private VerticalSection createLeftSection() {
40 VerticalSection section = new VerticalSection();
41 section.addSection(createKeyProgramInformationSection());
42 section.addSection(createProgramTitleSection());
43 section.addSection(createDatesSection());
44 section.addSection(createOtherInformationSection());
45 return section;
46 }
47
48 private VerticalSection createRightSection() {
49 VerticalSection section = new VerticalSection();
50 section.addStyleName("readOnlySection");
51 section.addSection(createReadOnlySection());
52 return section;
53 }
54
55 private VerticalSection createKeyProgramInformationSection() {
56 VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_identifyingDetails()));
57 configurer.addField(section, ProgramConstants.CODE, new MessageKeyInfo(ProgramProperties.get().programInformation_code()));
58 configurer.addField(section, ProgramConstants.PROGRAM_CLASSIFICATION, new MessageKeyInfo(ProgramProperties.get().programInformation_classification()));
59 configurer.addField(section, ProgramConstants.DEGREE_TYPE, new MessageKeyInfo(ProgramProperties.get().programInformation_degreeType()));
60 return section;
61 }
62
63 private VerticalSection createProgramTitleSection() {
64 VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_programTitle()));
65 configurer.addField(section, ProgramConstants.LONG_TITLE, new MessageKeyInfo(ProgramProperties.get().programInformation_titleFull()));
66 configurer.addField(section, ProgramConstants.SHORT_TITLE, new MessageKeyInfo(ProgramProperties.get().programInformation_titleShort()));
67 configurer.addField(section, ProgramConstants.TRANSCRIPT, new MessageKeyInfo(ProgramProperties.get().programInformation_titleTranscript()));
68 configurer.addField(section, ProgramConstants.DIPLOMA, new MessageKeyInfo(ProgramProperties.get().programInformation_titleDiploma())).setWidgetBinding(new DiplomaBinding());
69 return section;
70 }
71
72 private VerticalSection createDatesSection() {
73 VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_dates()));
74 configurer.addField(section, ProgramConstants.START_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_startTerm()));
75 configurer.addField(section, ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_admitTerm()));
76 configurer.addField(section, ProgramConstants.END_PROGRAM_ENTRY_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_entryTerm()));
77 configurer.addField(section, ProgramConstants.END_PROGRAM_ENROLL_TERM, new MessageKeyInfo(ProgramProperties.get().programInformation_enrollTerm()));
78 return section;
79 }
80
81 private VerticalSection createOtherInformationSection() {
82 VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(ProgramProperties.get().programInformation_otherInformation()));
83 configurer.addField(section, ProgramConstants.LOCATION, new MessageKeyInfo(ProgramProperties.get().programInformation_location()));
84 Widget cip2000Picker = configureSearch(ProgramConstants.CIP_2000);
85 configurer.addField(section, ProgramConstants.CIP_2000, new MessageKeyInfo(ProgramProperties.get().programInformation_cip2000()), cip2000Picker);
86 Widget cip2010Picker = configureSearch(ProgramConstants.CIP_2010);
87 configurer.addField(section, ProgramConstants.CIP_2010, new MessageKeyInfo(ProgramProperties.get().programInformation_cip2010()), cip2010Picker);
88 configurer.addField(section, ProgramConstants.HEGIS_CODE, new MessageKeyInfo(ProgramProperties.get().programInformation_hegis()));
89 return section;
90 }
91
92 private VerticalSection createReadOnlySection() {
93 VerticalSection section = new VerticalSection();
94 configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_INSTITUTION_ID, new MessageKeyInfo(ProgramProperties.get().programInformation_institution()));
95 configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_TYPE_NAME, new MessageKeyInfo(ProgramProperties.get().programInformation_credentialProgram()));
96 configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_LEVEL, new MessageKeyInfo(ProgramProperties.get().programInformation_level()));
97 return section;
98 }
99
100 private Widget configureSearch(String fieldKey) {
101 Widget searchWidget;
102 QueryPath path = QueryPath.concat(null, fieldKey);
103 Metadata meta = configurer.getModelDefinition().getMetadata(path);
104
105 searchWidget = new KSPicker(meta.getInitialLookup(), meta.getAdditionalLookups());
106 SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
107 if (panel != null) {
108 panel.setMutipleSelect(false);
109 }
110
111 return searchWidget;
112 }
113
114 public class DiplomaBinding extends ModelWidgetBindingSupport<KSTextBox> {
115 private boolean isEmpty(String value){
116 return value == null || (value != null && "".equals(value));
117 }
118
119 @Override
120 public void setModelValue(KSTextBox widget, DataModel model, String path) {
121 String diplomaTitle = widget.getText();
122 if(diplomaTitle != null)
123 model.set(QueryPath.concat(null, "/" + ProgramConstants.DIPLOMA), diplomaTitle);
124 }
125
126 @Override
127 public void setWidgetValue(KSTextBox widget, DataModel model, String path) {
128 String diplomaTitle = model.get("/" + ProgramConstants.DIPLOMA);
129 if(isEmpty(diplomaTitle)){
130 String programTitle = model.get("/" + ProgramConstants.LONG_TITLE);
131 if (!isEmpty(programTitle))
132 widget.setText(programTitle);
133 }
134 else
135 widget.setText(diplomaTitle);
136 }
137 }
138 }