1 | |
package org.kuali.student.lum.program.client.major.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.Configurer; |
6 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
7 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
8 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport; |
9 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration; |
10 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection; |
11 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.MultiplicitySection; |
12 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
13 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; |
14 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
15 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
16 | |
import org.kuali.student.common.ui.client.widgets.KSCharCount; |
17 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
18 | |
import org.kuali.student.common.ui.client.widgets.search.SearchPanel; |
19 | |
import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration; |
20 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
21 | |
import org.kuali.student.lum.program.client.ProgramMsgConstants; |
22 | |
import org.kuali.student.lum.program.client.ProgramSections; |
23 | |
|
24 | |
import com.google.gwt.user.client.ui.HasText; |
25 | |
import com.google.gwt.user.client.ui.Widget; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class MajorKeyProgramInfoEditConfiguration extends AbstractSectionConfiguration { |
31 | |
|
32 | 0 | public MajorKeyProgramInfoEditConfiguration(Configurer configurer) { |
33 | 0 | this.setConfigurer(configurer); |
34 | 0 | rootSection = new VerticalSectionView(ProgramSections.PROGRAM_DETAILS_EDIT, getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_PROGRAMINFORMATION), ProgramConstants.PROGRAM_MODEL_ID); |
35 | 0 | } |
36 | |
|
37 | |
@Override |
38 | |
protected void buildLayout() { |
39 | 0 | HorizontalSection horizontalSection = new HorizontalSection(); |
40 | 0 | horizontalSection.addSection(createLeftSection()); |
41 | 0 | rootSection.addSection(horizontalSection); |
42 | 0 | } |
43 | |
|
44 | |
private VerticalSection createLeftSection() { |
45 | 0 | VerticalSection section = new VerticalSection(); |
46 | 0 | section.addSection(createKeyProgramInformationSection()); |
47 | 0 | section.addSection(createProgramTitleSection()); |
48 | 0 | section.addSection(createDatesSection()); |
49 | 0 | section.addSection(createOtherInformationSection()); |
50 | 0 | return section; |
51 | |
} |
52 | |
|
53 | |
protected VerticalSection createKeyProgramInformationSection() { |
54 | 0 | VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_IDENTIFYINGDETAILS))); |
55 | |
|
56 | 0 | VerticalSection s1 = new VerticalSection(); |
57 | 0 | HorizontalSection s2 = new HorizontalSection(); |
58 | |
|
59 | 0 | configurer.addField(s1, ProgramConstants.CODE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CODE)); |
60 | 0 | configurer.addField(s1, ProgramConstants.CREDENTIAL_PROGRAM_ID, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CREDENTIALPROGRAM)); |
61 | 0 | configurer.addField(s1, ProgramConstants.PROGRAM_CLASSIFICATION, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CLASSIFICATION)); |
62 | 0 | configurer.addField(s1, ProgramConstants.DEGREE_TYPE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_DEGREETYPE)); |
63 | 0 | s2.addSection(s1); |
64 | 0 | s2.addSection(createReadOnlySection()); |
65 | 0 | section.addSection(s2); |
66 | 0 | return section; |
67 | |
} |
68 | |
|
69 | |
protected VerticalSection createReadOnlySection() { |
70 | 0 | VerticalSection section = new VerticalSection(); |
71 | 0 | section.addStyleName("readOnlySection"); |
72 | 0 | section.addStyleName("readOnlyNeedsToBeOnTheRight"); |
73 | 0 | configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_INSTITUTION_ID, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_INSTITUTION)); |
74 | 0 | configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_LEVEL, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_LEVEL)); |
75 | 0 | return section; |
76 | |
} |
77 | |
|
78 | |
private VerticalSection createProgramTitleSection() { |
79 | 0 | VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_PROGRAMTITLE))); |
80 | |
|
81 | |
|
82 | 0 | configurer.addField(section, ProgramConstants.LONG_TITLE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLEFULL)); |
83 | 0 | configurer.addField(section, ProgramConstants.SHORT_TITLE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLESHORT), new KSCharCount(configurer.getModelDefinition().getMetadata(QueryPath.parse(ProgramConstants.SHORT_TITLE)))); |
84 | 0 | configurer.addField(section, ProgramConstants.TRANSCRIPT, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLETRANSCRIPT), new KSCharCount(configurer.getModelDefinition().getMetadata(QueryPath.parse(ProgramConstants.TRANSCRIPT)))); |
85 | 0 | configurer.addField(section, ProgramConstants.DIPLOMA, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLEDIPLOMA)).setWidgetBinding(new DiplomaBinding()); |
86 | |
|
87 | 0 | return section; |
88 | |
} |
89 | |
|
90 | |
private VerticalSection createDatesSection() { |
91 | 0 | VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_DATES))); |
92 | |
|
93 | 0 | FieldDescriptor fd = configurer.addField(section,ProgramConstants.PROPOSAL_PREV_START_TERM_PATH, generateMessageInfo(ProgramMsgConstants.MAJORDISCIPLINE_PREVSTARTTERM)); |
94 | 0 | fd.getFieldWidget().setVisible(false); |
95 | 0 | fd.hideLabel(); |
96 | |
|
97 | 0 | configurer.addField(section, ProgramConstants.START_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_STARTTERM)); |
98 | 0 | configurer.addField(section, ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ADMITTERM)); |
99 | 0 | configurer.addField(section, ProgramConstants.END_PROGRAM_ENTRY_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ENTRYTERM)); |
100 | 0 | configurer.addField(section, ProgramConstants.END_PROGRAM_ENROLL_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ENROLLTERM)); |
101 | 0 | return section; |
102 | |
} |
103 | |
|
104 | |
private VerticalSection createOtherInformationSection() { |
105 | 0 | VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_OTHERINFORMATION))); |
106 | 0 | configurer.addField(section, ProgramConstants.LOCATION, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_LOCATION)); |
107 | 0 | Widget cip2000Picker = configureSearch(ProgramConstants.CIP_2000); |
108 | 0 | configurer.addField(section, ProgramConstants.CIP_2000, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CIP2000), cip2000Picker); |
109 | 0 | Widget cip2010Picker = configureSearch(ProgramConstants.CIP_2010); |
110 | 0 | configurer.addField(section, ProgramConstants.CIP_2010, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CIP2010), cip2010Picker); |
111 | 0 | configurer.addField(section, ProgramConstants.HEGIS_CODE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_HEGIS)); |
112 | 0 | section.addSection(createAccreditingAgenciesSection()); |
113 | 0 | return section; |
114 | |
} |
115 | |
|
116 | |
private Section createAccreditingAgenciesSection() { |
117 | |
|
118 | 0 | Metadata metadata = configurer.getModelDefinition().getMetadata(QueryPath.concat(ProgramConstants.ACCREDITING_AGENCY)); |
119 | 0 | MultiplicityConfiguration config = new MultiplicityConfiguration(MultiplicityConfiguration.MultiplicityType.GROUP, MultiplicityConfiguration.StyleType.TOP_LEVEL_GROUP, metadata); |
120 | 0 | config.setAddItemLabel(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_ADDACCREDITATION)); |
121 | 0 | config.setUpdateable(true); |
122 | 0 | config.setItemLabel(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_ACCREDITATION)); |
123 | |
|
124 | 0 | config.setParent(ProgramConstants.ACCREDITING_AGENCY, getLabel(ProgramMsgConstants.PROGRAMINFORMATION_ACCREDITATIONS), null, metadata); |
125 | |
|
126 | 0 | Metadata orgMetadata = configurer.getModelDefinition().getMetadata(QueryPath.concat(ProgramConstants.ACCREDITING_AGENCY, QueryPath.getWildCard(), ProgramConstants.ORG_ID)); |
127 | 0 | config.addField(ProgramConstants.ORG_ID, null, ProgramConstants.ACCREDITING_AGENCY, orgMetadata); |
128 | |
|
129 | 0 | MultiplicitySection section = new MultiplicitySection(config); |
130 | |
|
131 | 0 | return section; |
132 | |
} |
133 | |
|
134 | |
private Widget configureSearch(String fieldKey) { |
135 | |
Widget searchWidget; |
136 | 0 | QueryPath path = QueryPath.concat(null, fieldKey); |
137 | 0 | Metadata meta = configurer.getModelDefinition().getMetadata(path); |
138 | |
|
139 | 0 | searchWidget = new KSPicker(meta.getInitialLookup(), meta.getAdditionalLookups()); |
140 | 0 | SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel(); |
141 | 0 | if (panel != null) { |
142 | 0 | panel.setMutipleSelect(false); |
143 | |
} |
144 | |
|
145 | 0 | return searchWidget; |
146 | |
} |
147 | |
|
148 | 0 | public class DiplomaBinding extends ModelWidgetBindingSupport<HasText> { |
149 | |
private boolean isEmpty(String value) { |
150 | 0 | return value == null || value.isEmpty(); |
151 | |
} |
152 | |
|
153 | |
@Override |
154 | |
public void setModelValue(HasText widget, DataModel model, String path) { |
155 | 0 | String diplomaTitle = widget.getText(); |
156 | 0 | if (diplomaTitle != null) |
157 | 0 | model.set(QueryPath.concat(null, "/" + ProgramConstants.DIPLOMA), diplomaTitle); |
158 | 0 | } |
159 | |
|
160 | |
@Override |
161 | |
public void setWidgetValue(HasText widget, DataModel model, String path) { |
162 | 0 | String diplomaTitle = model.get("/" + ProgramConstants.DIPLOMA); |
163 | 0 | if (isEmpty(diplomaTitle)) { |
164 | 0 | String programTitle = model.get("/" + ProgramConstants.LONG_TITLE); |
165 | 0 | if (!isEmpty(programTitle)){ |
166 | 0 | widget.setText(programTitle); |
167 | |
}else{ |
168 | 0 | widget.setText(""); |
169 | |
} |
170 | 0 | } else |
171 | 0 | widget.setText(diplomaTitle); |
172 | 0 | } |
173 | |
} |
174 | |
} |