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