1 | |
package org.kuali.student.lum.lu.ui.course.client.requirements; |
2 | |
|
3 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.BasicLayout; |
4 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; |
5 | |
import org.kuali.student.common.ui.client.mvc.*; |
6 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations; |
7 | |
import org.kuali.student.common.ui.client.widgets.dialog.ButtonMessageDialog; |
8 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup; |
9 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.YesNoCancelGroup; |
10 | |
|
11 | 0 | public class CourseRequirementsViewController extends BasicLayout { |
12 | |
|
13 | 0 | public enum CourseRequirementsViews { |
14 | 0 | PREVIEW, |
15 | 0 | MANAGE |
16 | |
} |
17 | |
|
18 | |
public static final String COURSE_RULES_MODEL_ID = "courseRulesModelId"; |
19 | |
public static final String CLU_PROPOSAL_MODEL = "cluProposalModel"; |
20 | |
|
21 | |
private CourseRequirementsSummaryView preview; |
22 | |
|
23 | |
public CourseRequirementsViewController(Controller controller, String name, Enum<?> viewType, boolean isReadOnly) { |
24 | 0 | super(CourseRequirementsViewController.class.getName()); |
25 | 0 | super.setController(controller); |
26 | 0 | super.setName(name); |
27 | 0 | super.setViewEnum(viewType); |
28 | 0 | super.setDefaultModelId(COURSE_RULES_MODEL_ID); |
29 | 0 | super.setParentController(controller); |
30 | |
|
31 | 0 | this.setDefaultView(CourseRequirementsViews.PREVIEW); |
32 | |
|
33 | |
|
34 | 0 | super.registerModel(COURSE_RULES_MODEL_ID, new ModelProvider<DataModel>() { |
35 | |
@Override |
36 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
37 | 0 | callback.onModelReady(new DataModel()); |
38 | 0 | } |
39 | |
}); |
40 | |
|
41 | |
|
42 | 0 | preview = new CourseRequirementsSummaryView(this, CourseRequirementsViews.PREVIEW, (isReadOnly ? "Course Requirements" : ""), CLU_PROPOSAL_MODEL, |
43 | |
new CourseRequirementsDataModel(this), isReadOnly); |
44 | 0 | super.addView(preview); |
45 | |
|
46 | 0 | if (!isReadOnly) { |
47 | 0 | CourseRequirementsManageView manageView = new CourseRequirementsManageView(this, CourseRequirementsViews.MANAGE, |
48 | |
"Add and Combine Rules", COURSE_RULES_MODEL_ID); |
49 | 0 | super.addView(manageView); |
50 | |
} |
51 | 0 | } |
52 | |
|
53 | |
@Override |
54 | |
public void updateModel() { |
55 | 0 | preview.updateModel(); |
56 | 0 | } |
57 | |
|
58 | |
@Override |
59 | |
public void beforeViewChange(final Enum<?> viewChangingTo, final Callback<Boolean> okToChange) { |
60 | |
|
61 | 0 | if (getCurrentView() == null) { |
62 | 0 | okToChange.exec(true); |
63 | 0 | return; |
64 | |
} |
65 | |
|
66 | 0 | super.beforeViewChange(viewChangingTo, new Callback<Boolean>() { |
67 | |
|
68 | |
@Override |
69 | |
public void exec(Boolean result) { |
70 | |
|
71 | |
|
72 | 0 | if (getCurrentView() instanceof CourseRequirementsManageView) { |
73 | 0 | okToChange.exec(true); |
74 | 0 | return; |
75 | |
} |
76 | |
|
77 | |
|
78 | 0 | if (viewChangingTo.name().equals(CourseRequirementsViewController.CourseRequirementsViews.MANAGE.name())) |
79 | |
{ |
80 | |
|
81 | 0 | okToChange.exec(true); |
82 | 0 | return; |
83 | |
} |
84 | |
|
85 | |
|
86 | 0 | if (!((SectionView) getCurrentView()).isDirty()) { |
87 | 0 | okToChange.exec(true); |
88 | 0 | return; |
89 | |
} |
90 | |
|
91 | |
|
92 | 0 | ButtonGroup<ButtonEnumerations.YesNoCancelEnum> buttonGroup = new YesNoCancelGroup(); |
93 | 0 | final ButtonMessageDialog<ButtonEnumerations.YesNoCancelEnum> dialog = |
94 | |
new ButtonMessageDialog<ButtonEnumerations.YesNoCancelEnum>("Warning", "You may have unsaved changes. Save changes?", buttonGroup); |
95 | 0 | buttonGroup.addCallback(new Callback<ButtonEnumerations.YesNoCancelEnum>() { |
96 | |
|
97 | |
@Override |
98 | |
public void exec(ButtonEnumerations.YesNoCancelEnum result) { |
99 | 0 | switch (result) { |
100 | |
case YES: |
101 | 0 | dialog.hide(); |
102 | 0 | preview.storeRules(true, new Callback<Boolean>() { |
103 | |
@Override |
104 | |
public void exec(Boolean result) { |
105 | 0 | okToChange.exec(result); |
106 | 0 | } |
107 | |
}); |
108 | 0 | break; |
109 | |
case NO: |
110 | 0 | dialog.hide(); |
111 | 0 | preview.revertRuleChanges(); |
112 | 0 | okToChange.exec(true); |
113 | 0 | break; |
114 | |
case CANCEL: |
115 | 0 | okToChange.exec(false); |
116 | 0 | dialog.hide(); |
117 | |
break; |
118 | |
} |
119 | 0 | } |
120 | |
}); |
121 | 0 | dialog.show(); |
122 | 0 | } |
123 | |
}); |
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public void beforeShow(final Callback<Boolean> onReadyCallback){ |
128 | 0 | showDefaultView(onReadyCallback); |
129 | 0 | } |
130 | |
} |