1 | |
package org.kuali.student.lum.lu.ui.course.client.configuration; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Iterator; |
5 | |
import java.util.List; |
6 | |
import java.util.TreeSet; |
7 | |
|
8 | |
import org.kuali.student.common.assembly.data.Data; |
9 | |
import org.kuali.student.common.assembly.data.QueryPath; |
10 | |
import org.kuali.student.common.assembly.data.Data.Property; |
11 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
12 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptorReadOnly; |
13 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
14 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
15 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.MenuSectionController; |
16 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection; |
17 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
18 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; |
19 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.WarnContainer; |
20 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
21 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
22 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
23 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
24 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
25 | |
import org.kuali.student.common.ui.client.widgets.KSCharCount; |
26 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
27 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; |
28 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldBlock; |
29 | |
import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection; |
30 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
31 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel; |
32 | |
import org.kuali.student.core.document.ui.client.widgets.documenttool.DocumentList; |
33 | |
import org.kuali.student.core.document.ui.client.widgets.documenttool.DocumentListBinding; |
34 | |
import org.kuali.student.core.statement.dto.StatementTypeInfo; |
35 | |
import org.kuali.student.core.workflow.ui.client.views.CollaboratorSectionView; |
36 | |
import org.kuali.student.core.workflow.ui.client.widgets.WorkflowEnhancedNavController; |
37 | |
import org.kuali.student.lum.common.client.lu.LUUIConstants; |
38 | |
import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants; |
39 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseProposalConfigurer.CourseSections; |
40 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseSummaryConfigurer.EditHandler; |
41 | |
|
42 | |
import com.google.gwt.core.client.GWT; |
43 | |
import com.google.gwt.event.dom.client.ClickEvent; |
44 | |
import com.google.gwt.event.dom.client.ClickHandler; |
45 | |
import com.google.gwt.user.client.ui.Anchor; |
46 | |
import com.google.gwt.user.client.ui.Widget; |
47 | |
|
48 | 0 | public class CourseRetireSummaryConfigurer extends CourseSummaryConfigurer { |
49 | |
|
50 | 0 | private boolean showingValidation = false; |
51 | 0 | private List<ValidationResultInfo> validationInfos = new ArrayList<ValidationResultInfo>(); |
52 | 0 | private List<Anchor> validateLinks = new ArrayList<Anchor>(); |
53 | |
|
54 | 0 | public CourseRetireSummaryConfigurer(){ |
55 | |
|
56 | 0 | } |
57 | |
|
58 | |
public CourseRetireSummaryConfigurer(String type, String state, String groupName, |
59 | |
DataModelDefinition modelDefinition, |
60 | |
List<StatementTypeInfo> stmtTypes, Controller controller, |
61 | 0 | String modelId) { |
62 | 0 | this.type = type; |
63 | 0 | this.state = state; |
64 | 0 | this.groupName = groupName; |
65 | 0 | this.modelDefinition = modelDefinition; |
66 | 0 | this.stmtTypes = stmtTypes; |
67 | 0 | this.controller = controller; |
68 | 0 | this.modelId = modelId; |
69 | 0 | tableSection = new SummaryTableSection((Controller) controller); |
70 | 0 | } |
71 | |
|
72 | |
public void init(String type, String state, String groupName, |
73 | |
DataModelDefinition modelDefinition, |
74 | |
List<StatementTypeInfo> stmtTypes, Controller controller, |
75 | |
String modelId) { |
76 | 0 | this.type = type; |
77 | 0 | this.state = state; |
78 | 0 | this.groupName = groupName; |
79 | 0 | this.modelDefinition = modelDefinition; |
80 | 0 | this.stmtTypes = stmtTypes; |
81 | 0 | this.controller = controller; |
82 | 0 | this.modelId = modelId; |
83 | 0 | tableSection = new SummaryTableSection((Controller) controller); |
84 | 0 | } |
85 | |
|
86 | |
public VerticalSectionView generateProposalSummarySection(boolean canEditSections) { |
87 | 0 | tableSection.setEditable(canEditSections); |
88 | 0 | tableSection.addSummaryTableFieldBlock(generateRetirementInfoSection()); |
89 | |
|
90 | |
|
91 | |
|
92 | 0 | tableSection.addSummaryTableFieldBlock(generateProposalDocumentsSection()); |
93 | |
|
94 | 0 | if ( controller instanceof WorkflowEnhancedNavController |
95 | |
&& ((WorkflowEnhancedNavController) controller).getWfUtilities() != null) { |
96 | |
final WarnContainer infoContainer1; |
97 | |
final WarnContainer infoContainer2; |
98 | |
|
99 | 0 | Widget topWorkflowActionWidget= ((WorkflowEnhancedNavController) controller).getWfUtilities().getWorkflowActionsWidget(); |
100 | 0 | Widget bottomWorkflowActionWidget = ((WorkflowEnhancedNavController) controller).getWfUtilities().getWorkflowActionsWidget(); |
101 | |
|
102 | 0 | topWorkflowActionWidget.ensureDebugId("Top-Workflow-Actions"); |
103 | 0 | bottomWorkflowActionWidget.ensureDebugId("Bottom-Workflow-Actions"); |
104 | |
|
105 | 0 | infoContainer1= generateWorkflowWidgetContainer(topWorkflowActionWidget); |
106 | 0 | infoContainer2= generateWorkflowWidgetContainer(bottomWorkflowActionWidget); |
107 | |
|
108 | 0 | ((WorkflowEnhancedNavController) controller).getWfUtilities() |
109 | 0 | .addSubmitCallback(new Callback<Boolean>() { |
110 | |
|
111 | |
@Override |
112 | |
public void exec(Boolean result) { |
113 | 0 | if (result) { |
114 | 0 | tableSection.setEditable(false); |
115 | 0 | if (controller instanceof MenuSectionController) { |
116 | 0 | ((MenuSectionController) controller).removeMenuNavigation(); |
117 | |
} |
118 | |
} |
119 | |
|
120 | 0 | } |
121 | |
}); |
122 | |
|
123 | |
|
124 | 0 | VerticalSectionView verticalSection = new VerticalSectionView(CourseSections.SUMMARY, getLabel(LUUIConstants.SUMMARY_LABEL_KEY), modelId) { |
125 | |
|
126 | |
@Override |
127 | |
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
128 | |
|
129 | 0 | super.beforeShow(new Callback<Boolean>() { |
130 | |
|
131 | |
@Override |
132 | |
public void exec(final Boolean result) { |
133 | |
|
134 | 0 | if (result) { |
135 | |
|
136 | 0 | ((WorkflowEnhancedNavController) controller).getWfUtilities().refresh(); |
137 | |
|
138 | |
|
139 | 0 | ((WorkflowEnhancedNavController) controller).getWfUtilities().doValidationCheck(new Callback<List<ValidationResultInfo>>() { |
140 | |
|
141 | |
@Override |
142 | |
public void exec(List<ValidationResultInfo> validationResults) { |
143 | |
|
144 | 0 | tableSection.enableValidation(showingValidation); |
145 | |
|
146 | 0 | initializeHeaders(validationResults); |
147 | 0 | resolveMissingFieldsWarnings(); |
148 | |
|
149 | |
|
150 | 0 | onReadyCallback.exec(result); |
151 | 0 | } |
152 | |
}); |
153 | |
} else { |
154 | 0 | onReadyCallback.exec(result); |
155 | |
} |
156 | 0 | } |
157 | |
}); |
158 | 0 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
void initializeHeaders(List<ValidationResultInfo> validationResults){ |
164 | 0 | ErrorLevel isValid = tableSection.processValidationResults(validationResults, true); |
165 | 0 | validationInfos = validationResults; |
166 | |
|
167 | 0 | if (isValid == ErrorLevel.OK) { |
168 | |
|
169 | 0 | infoContainer1.showWarningLayout(false); |
170 | 0 | infoContainer2.showWarningLayout(false); |
171 | |
|
172 | 0 | ((WorkflowEnhancedNavController) controller).getWfUtilities().enableWorkflowActionsWidgets(true); |
173 | |
} else { |
174 | |
|
175 | 0 | infoContainer1.clearWarnLayout(); |
176 | 0 | infoContainer2.clearWarnLayout(); |
177 | |
|
178 | 0 | infoContainer1.showWarningLayout(true); |
179 | 0 | infoContainer2.showWarningLayout(true); |
180 | 0 | ((WorkflowEnhancedNavController) controller).getWfUtilities().enableWorkflowActionsWidgets(false); |
181 | |
} |
182 | 0 | } |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
public void resolveMissingFieldsWarnings(){ |
188 | |
|
189 | 0 | if (tableSection.getIsMissingFields()) { |
190 | 0 | final Anchor link1 = new Anchor("Show what's missing."); |
191 | 0 | final Anchor link2 = new Anchor("Show what's missing."); |
192 | 0 | ClickHandler showHideMsgClickHandler = new ClickHandler() { |
193 | |
|
194 | |
@Override |
195 | |
public void onClick(ClickEvent event) { |
196 | |
|
197 | 0 | if (!showingValidation) { |
198 | |
|
199 | 0 | for (int i = 0; i < validateLinks.size(); i++) { |
200 | |
|
201 | 0 | validateLinks.get(i).setText("Hide error highlighting."); |
202 | |
} |
203 | |
|
204 | 0 | showingValidation = true; |
205 | |
|
206 | 0 | tableSection.enableValidation(showingValidation); |
207 | 0 | tableSection.processValidationResults(validationInfos, true); |
208 | |
} else { |
209 | |
|
210 | 0 | for (int i = 0; i < validateLinks.size(); i++) { |
211 | |
|
212 | 0 | validateLinks.get(i).setText("Show what's missing."); |
213 | |
} |
214 | |
|
215 | 0 | showingValidation = false; |
216 | |
|
217 | 0 | tableSection.enableValidation(showingValidation); |
218 | 0 | tableSection.removeValidationHighlighting(); |
219 | |
} |
220 | 0 | } |
221 | |
}; |
222 | |
|
223 | 0 | validateLinks.add(link1); |
224 | 0 | validateLinks.add(link2); |
225 | |
|
226 | 0 | link1.addClickHandler(showHideMsgClickHandler); |
227 | 0 | link2.addClickHandler(showHideMsgClickHandler); |
228 | |
|
229 | 0 | infoContainer1.addWarnWidget(new KSLabel("This proposal has missing fields. ")); |
230 | 0 | infoContainer1.addWarnWidget(link1); |
231 | 0 | infoContainer2.addWarnWidget(new KSLabel("This proposal has missing fields. ")); |
232 | 0 | infoContainer2.addWarnWidget(link2); |
233 | |
} |
234 | 0 | } |
235 | |
|
236 | |
@Override |
237 | |
public ErrorLevel processValidationResults(List<ValidationResultInfo> validationResults) { |
238 | |
|
239 | 0 | tableSection.processValidationResults(validationResults, false); |
240 | 0 | resolveProposalSubmissionWarnings(); |
241 | |
|
242 | 0 | return super.processValidationResults(validationResults); |
243 | |
} |
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
public void resolveProposalSubmissionWarnings(){ |
250 | |
|
251 | 0 | if (tableSection.getHasWarnings()) { |
252 | |
|
253 | 0 | infoContainer1.addWarnWidgetBlock(new KSLabel("This proposal contains warnings that prevent it from being submitted.")); |
254 | 0 | infoContainer2.addWarnWidgetBlock(new KSLabel("This proposal contains warnings that prevent it from being submitted.")); |
255 | |
} |
256 | 0 | } |
257 | |
|
258 | |
}; |
259 | |
|
260 | 0 | HorizontalSection layoutSection = new HorizontalSection(); |
261 | 0 | layoutSection.addSection(tableSection); |
262 | 0 | layoutSection.addSection(generateReferenceDataSection()); |
263 | |
|
264 | 0 | verticalSection.addWidget(infoContainer1); |
265 | 0 | verticalSection.addSection(layoutSection); |
266 | 0 | verticalSection.addWidget(infoContainer2); |
267 | |
|
268 | 0 | return verticalSection; |
269 | |
|
270 | |
} else { |
271 | |
|
272 | 0 | VerticalSectionView verticalSection = new VerticalSectionView( |
273 | |
CourseSections.SUMMARY, |
274 | |
getLabel(LUUIConstants.SUMMARY_LABEL_KEY), modelId); |
275 | 0 | HorizontalSection layoutSection = new HorizontalSection(); |
276 | 0 | layoutSection.addSection(tableSection); |
277 | 0 | layoutSection.addSection(generateReferenceDataSection()); |
278 | 0 | verticalSection.addSection(layoutSection); |
279 | 0 | GWT.log("CourseSummaryConfigurer - Summary table needs a workflow controller to provide submit/validation mechanism"); |
280 | |
|
281 | 0 | return verticalSection; |
282 | |
} |
283 | |
|
284 | |
} |
285 | |
|
286 | |
private SummaryTableFieldBlock generateProposalDocumentsSection() { |
287 | 0 | SummaryTableFieldBlock block = new SummaryTableFieldBlock(); |
288 | 0 | block.addEditingHandler(new EditHandler(CourseSections.DOCUMENTS)); |
289 | 0 | block.setTitle(getLabel(LUUIConstants.TOOL_DOCUMENTS_LABEL_KEY)); |
290 | 0 | block.addSummaryTableFieldRow(getFieldRow("proposal/id", |
291 | |
generateMessageInfo(LUUIConstants.TOOL_DOCUMENTS_LABEL_KEY), |
292 | |
new DocumentList(LUUIConstants.REF_DOC_RELATION_PROPOSAL_TYPE, |
293 | |
false, false), new DocumentList( |
294 | |
LUUIConstants.REF_DOC_RELATION_PROPOSAL_TYPE, false, |
295 | |
false), null, new DocumentListBinding("proposal/id"), |
296 | |
false)); |
297 | 0 | return block; |
298 | |
} |
299 | |
|
300 | |
|
301 | |
private WarnContainer generateWorkflowWidgetContainer(Widget w) { |
302 | |
|
303 | 0 | WarnContainer warnContainer = new WarnContainer(); |
304 | |
|
305 | 0 | warnContainer.add(w); |
306 | 0 | w.addStyleName("ks-button-spacing"); |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | 0 | return warnContainer; |
321 | |
} |
322 | |
|
323 | |
@SuppressWarnings("unchecked") |
324 | |
public SummaryTableFieldBlock generateRetirementInfoSection() { |
325 | 0 | SummaryTableFieldBlock block = new SummaryTableFieldBlock(); |
326 | 0 | block.addEditingHandler(new EditHandler(CourseSections.COURSE_INFO)); |
327 | 0 | block.setTitle(getLabel(LUUIConstants.PROPOSED_RETIRE_INFORMATION_LABEL_KEY)); |
328 | 0 | block.addSummaryTableFieldRow(getFieldRow(PROPOSAL_TITLE_PATH, |
329 | |
generateMessageInfo(LUUIConstants.PROPOSED_PROPOSAL_TITLE_LABEL_KEY))); |
330 | 0 | block.addSummaryTableFieldRow(getFieldRow(PROPOSAL + "/" + PROPOSED_RATIONALE, |
331 | |
generateMessageInfo(LUUIConstants.RETIREMENT_RATIONALE_LABEL_KEY))); |
332 | 0 | block.addSummaryTableFieldRow(getFieldRow(COURSE + "/" + START_TERM, |
333 | |
generateMessageInfo(LUUIConstants.START_TERM_LABEL_KEY))); |
334 | 0 | block.addSummaryTableFieldRow(getFieldRow(PROPOSAL + "/" + PROPOSED_END_TERM, |
335 | |
generateMessageInfo(LUUIConstants.PROPOSED_END_TERM_LABEL_KEY))); |
336 | 0 | block.addSummaryTableFieldRow(getFieldRow(PROPOSAL + "/" + PROPOSED_LAST_TERM_OFFERED, |
337 | |
generateMessageInfo(LUUIConstants.PROPOSED_LAST_TERM_OFFERED_LABEL_KEY))); |
338 | 0 | block.addSummaryTableFieldRow(getFieldRow(PROPOSAL + "/" + PROPOSED_LAST_COURSE_CATALOG_YEAR, |
339 | |
generateMessageInfo(LUUIConstants.PROPOSED_LAST_COURSE_CATALOG_YEAR_LABEL_KEY))); |
340 | 0 | block.addSummaryTableFieldRow(getFieldRow(PROPOSAL + "/" + OTHER_COMMENTS, |
341 | |
generateMessageInfo(LUUIConstants.OTHER_COMMENTS_LABEL_KEY))); |
342 | |
|
343 | 0 | return block; |
344 | |
} |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
public SummaryTableFieldBlock generateCollaboratorSection() { |
350 | 0 | SummaryTableFieldBlock block = new SummaryTableFieldBlock(); |
351 | 0 | block.addEditingHandler(new EditHandler(CourseSections.PEOPLE_PERMISSONS)); |
352 | 0 | block.setTitle(getLabel(LUUIConstants.COLLABORATORS_LABEL_KEY)); |
353 | |
|
354 | |
|
355 | 0 | return block; |
356 | |
} |
357 | |
|
358 | |
|
359 | |
|
360 | |
protected VerticalSection generateReferenceDataSection() { |
361 | 0 | SectionTitle title = SectionTitle.generateH4Title("Reference Data"); |
362 | 0 | title.addStyleName("text-underline"); |
363 | |
|
364 | 0 | VerticalSection section = new VerticalSection(title); |
365 | 0 | section.addStyleName("readOnlySection"); |
366 | 0 | section.addStyleName("KS-Data-Box-ReadOnlyNeedsToBeOnTheRight"); |
367 | 0 | section.addStyleName("KS-Add-Data-Box"); |
368 | |
|
369 | 0 | addReadOnlyFieldJustTextStyle(section, COURSE + "/" + CreditCourseConstants.COURSE_CODE, generateMessageInfo(LUUIConstants.COURSE_NUMBER_LABEL_KEY), "ks-form-module-single-line-margin-narrow"); |
370 | 0 | addReadOnlyFieldJustTextStyle(section, COURSE + "/" + CreditCourseConstants.COURSE_TITLE, generateMessageInfo(LUUIConstants.COURSE_TITLE_LABEL_KEY), "ks-form-module-single-line-margin-narrow"); |
371 | |
|
372 | |
|
373 | 0 | FieldDescriptorReadOnly xlistsAndJoints = new FieldDescriptorReadOnly(CreditCourseConstants.CROSSLISTED_AND_JOINTS, generateMessageInfo(LUUIConstants.CROSSLISTED_AND_JOINTS_LABEL_KEY), null, new KSLabel()); |
374 | 0 | xlistsAndJoints.setWidgetBinding(new ModelWidgetBinding<KSLabel>() { |
375 | |
public void setModelValue(KSLabel widget, DataModel model, |
376 | |
String path) { |
377 | 0 | } |
378 | |
public void setWidgetValue(KSLabel widget, DataModel model, |
379 | |
String path) { |
380 | 0 | TreeSet<String> codes = new TreeSet<String>(); |
381 | 0 | Data crossListings = model.getRoot().get(CreditCourseConstants.CROSS_LISTINGS); |
382 | 0 | for(Property property:crossListings){ |
383 | 0 | codes.add((String) ((Data)property.getValue()).get(CreditCourseConstants.COURSE_CODE)); |
384 | |
} |
385 | 0 | Data joints = model.getRoot().get(CreditCourseConstants.JOINTS); |
386 | 0 | for(Property property:joints){ |
387 | 0 | String subjectArea = (String) ((Data)property.getValue()).get(CreditCourseConstants.SUBJECT_AREA); |
388 | 0 | String courseNumberSuffix = (String) ((Data)property.getValue()).get(CreditCourseConstants.COURSE_NUMBER_SUFFIX); |
389 | 0 | codes.add(subjectArea + courseNumberSuffix); |
390 | 0 | } |
391 | 0 | String output=""; |
392 | 0 | for(Iterator<String> iter=codes.iterator();iter.hasNext();){ |
393 | 0 | String code = iter.next(); |
394 | 0 | output += code; |
395 | 0 | if(iter.hasNext()){ |
396 | 0 | output += ", "; |
397 | |
} |
398 | 0 | } |
399 | 0 | widget.setText(output); |
400 | 0 | } |
401 | |
|
402 | |
}); |
403 | 0 | xlistsAndJoints.getFieldElement().addStyleName("ks-form-module-single-line-margin-narrow"); |
404 | 0 | section.addField(xlistsAndJoints); |
405 | |
|
406 | 0 | addReadOnlyFieldJustTextStyle(section, COURSE + "/" + CreditCourseConstants.CURRICULUM_OVERSIGHT_ORGS_, generateMessageInfo(LUUIConstants.ACADEMIC_SUBJECT_ORGS_KEY), "ks-form-module-single-line-margin-narrow"); |
407 | |
|
408 | 0 | return section; |
409 | |
} |
410 | |
|
411 | |
|
412 | |
protected FieldDescriptor addReadOnlyFieldJustText(Section section, String fieldKey, MessageKeyInfo messageKey){ |
413 | 0 | FieldDescriptor fd = addReadOnlyField(section, fieldKey, messageKey); |
414 | 0 | fd.getFieldElement().setHelp(null); |
415 | 0 | fd.getFieldElement().setInstructions(null); |
416 | 0 | fd.getFieldElement().setExamples(null); |
417 | 0 | fd.getFieldElement().setConstraintText(null); |
418 | 0 | return fd; |
419 | |
} |
420 | |
|
421 | |
protected FieldDescriptor addReadOnlyFieldJustTextStyle(Section section, String fieldKey, MessageKeyInfo messageKey, String styleName){ |
422 | 0 | FieldDescriptor fd = addReadOnlyField(section, fieldKey, messageKey); |
423 | 0 | fd.getFieldElement().setHelp(null); |
424 | 0 | fd.getFieldElement().setInstructions(null); |
425 | 0 | fd.getFieldElement().setExamples(null); |
426 | 0 | fd.getFieldElement().setConstraintText(null); |
427 | 0 | fd.getFieldElement().addStyleName(styleName); |
428 | 0 | return fd; |
429 | |
} |
430 | |
} |