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