1 | |
package org.kuali.student.lum.program.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 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
11 | |
import org.kuali.student.lum.program.client.properties.ProgramProperties; |
12 | |
import org.kuali.student.lum.program.client.widgets.EditableHeader; |
13 | |
|
14 | |
import com.google.gwt.event.shared.HandlerManager; |
15 | |
|
16 | 0 | public class ProgramRequirementsViewController extends BasicLayout { |
17 | |
|
18 | 0 | public enum ProgramRequirementsViews { |
19 | 0 | PREVIEW, |
20 | 0 | MANAGE |
21 | |
} |
22 | |
|
23 | |
public static final String PROGRAM_RULES_MODEL_ID = "programRulesModelId"; |
24 | |
private ProgramRequirementsSummaryView preview; |
25 | |
boolean reloadFlag; |
26 | |
|
27 | |
public ProgramRequirementsViewController(Controller controller, HandlerManager eventBus, String name, Enum<?> viewType, boolean isReadOnly, EditableHeader header, boolean reloadFlag) { |
28 | 0 | this(controller, eventBus, name, viewType, isReadOnly, header); |
29 | 0 | this.reloadFlag = reloadFlag; |
30 | 0 | } |
31 | |
|
32 | |
public ProgramRequirementsViewController(Controller controller, HandlerManager eventBus, String name, Enum<?> viewType, boolean isReadOnly, EditableHeader header) { |
33 | 0 | super(ProgramRequirementsViewController.class.getName()); |
34 | 0 | super.setController(controller); |
35 | 0 | super.setName(name); |
36 | 0 | super.setViewEnum(viewType); |
37 | 0 | super.setDefaultModelId(PROGRAM_RULES_MODEL_ID); |
38 | 0 | super.setParentController(controller); |
39 | |
|
40 | 0 | this.setDefaultView(ProgramRequirementsViews.PREVIEW); |
41 | |
|
42 | |
|
43 | 0 | super.registerModel(PROGRAM_RULES_MODEL_ID, new ModelProvider<DataModel>() { |
44 | |
@Override |
45 | |
public void requestModel(final ModelRequestCallback<DataModel> callback) { |
46 | 0 | callback.onModelReady(new DataModel()); |
47 | 0 | } |
48 | |
}); |
49 | |
|
50 | |
|
51 | 0 | String previewTitle = ProgramProperties.get().program_menu_sections_requirements(); |
52 | 0 | if (isReadOnly && (header != null)) { |
53 | 0 | preview = new ProgramRequirementsSummaryView(this, eventBus, ProgramRequirementsViews.PREVIEW, "", ProgramConstants.PROGRAM_MODEL_ID, isReadOnly, header); |
54 | |
} else { |
55 | 0 | preview = new ProgramRequirementsSummaryView(this, eventBus, ProgramRequirementsViews.PREVIEW, (isReadOnly ? previewTitle : ""), ProgramConstants.PROGRAM_MODEL_ID, isReadOnly); |
56 | |
} |
57 | 0 | super.addView(preview); |
58 | |
|
59 | 0 | if (!isReadOnly) { |
60 | 0 | ProgramRequirementsManageView manageView = new ProgramRequirementsManageView(this, ProgramRequirementsViews.MANAGE, "Add and Combine Rules", PROGRAM_RULES_MODEL_ID); |
61 | 0 | super.addView(manageView); |
62 | |
} |
63 | 0 | } |
64 | |
|
65 | |
@Override |
66 | |
public void updateModel() { |
67 | 0 | preview.updateModel(); |
68 | 0 | } |
69 | |
|
70 | |
@Override |
71 | |
public void beforeViewChange(final Enum<?> viewChangingTo, final Callback<Boolean> okToChange) { |
72 | |
|
73 | 0 | if (getCurrentView() == null) { |
74 | 0 | okToChange.exec(true); |
75 | 0 | return; |
76 | |
} |
77 | |
|
78 | 0 | super.beforeViewChange(viewChangingTo, new Callback<Boolean>() { |
79 | |
|
80 | |
@Override |
81 | |
public void exec(Boolean result) { |
82 | |
|
83 | |
|
84 | |
|
85 | 0 | if (viewChangingTo.name().equals(ProgramRequirementsViews.MANAGE.name())) |
86 | |
{ |
87 | 0 | okToChange.exec(true); |
88 | 0 | return; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | 0 | if (getCurrentView() instanceof ProgramRequirementsManageView) { |
94 | 0 | okToChange.exec(true); |
95 | 0 | return; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | 0 | if (viewChangingTo.name().equals(ProgramRequirementsViews.PREVIEW.name())) { |
103 | 0 | preview.getRules().setupRules(ProgramRequirementsViewController.this, new Callback<Boolean>() { |
104 | |
@Override |
105 | |
public void exec(Boolean result) { |
106 | 0 | okToChange.exec(result); |
107 | 0 | return; |
108 | |
} |
109 | |
}); |
110 | 0 | return; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | 0 | if (!((SectionView) getCurrentView()).isDirty()) { |
116 | 0 | okToChange.exec(true); |
117 | 0 | return; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | 0 | ButtonGroup<ButtonEnumerations.YesNoCancelEnum> buttonGroup = new YesNoCancelGroup(); |
123 | 0 | final ButtonMessageDialog<ButtonEnumerations.YesNoCancelEnum> dialog = |
124 | |
new ButtonMessageDialog<ButtonEnumerations.YesNoCancelEnum>("Warning", "You may have unsaved changes. Save changes?", buttonGroup); |
125 | 0 | buttonGroup.addCallback(new Callback<ButtonEnumerations.YesNoCancelEnum>() { |
126 | |
|
127 | |
@Override |
128 | |
public void exec(ButtonEnumerations.YesNoCancelEnum result) { |
129 | 0 | switch (result) { |
130 | |
case YES: |
131 | 0 | dialog.hide(); |
132 | 0 | preview.storeRules(new Callback<Boolean>() { |
133 | |
@Override |
134 | |
public void exec(Boolean result) { |
135 | 0 | okToChange.exec(true); |
136 | 0 | } |
137 | |
}); |
138 | 0 | break; |
139 | |
case NO: |
140 | 0 | dialog.hide(); |
141 | |
|
142 | 0 | okToChange.exec(true); |
143 | 0 | break; |
144 | |
case CANCEL: |
145 | 0 | okToChange.exec(false); |
146 | 0 | dialog.hide(); |
147 | |
break; |
148 | |
} |
149 | 0 | } |
150 | |
}); |
151 | 0 | dialog.show(); |
152 | 0 | } |
153 | |
}); |
154 | 0 | } |
155 | |
|
156 | |
@Override |
157 | |
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
158 | 0 | showDefaultView(onReadyCallback); |
159 | 0 | } |
160 | |
|
161 | |
public ProgramRequirementsSummaryView getProgramRequirementsView() { |
162 | 0 | return preview; |
163 | |
} |
164 | |
} |