1 | |
package org.kuali.student.lum.lu.ui.course.client.controllers; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
|
6 | |
import org.kuali.student.common.assembly.data.QueryPath; |
7 | |
import org.kuali.student.common.dto.DtoConstants; |
8 | |
import org.kuali.student.common.ui.client.application.Application; |
9 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
10 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection; |
11 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
12 | |
import org.kuali.student.common.ui.client.event.ActionEvent; |
13 | |
import org.kuali.student.common.ui.client.event.SaveActionEvent; |
14 | |
import org.kuali.student.common.ui.client.mvc.ActionCompleteCallback; |
15 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
16 | |
import org.kuali.student.common.ui.client.util.WindowTitleUtils; |
17 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
18 | |
import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; |
19 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
20 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
21 | |
import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities; |
22 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
23 | |
import org.kuali.student.lum.lu.LUConstants; |
24 | |
import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants; |
25 | |
import org.kuali.student.lum.lu.ui.course.client.configuration.CourseAdminConfigurer; |
26 | |
import org.kuali.student.lum.lu.ui.course.client.widgets.CourseWorkflowActionList; |
27 | |
|
28 | |
import com.google.gwt.core.client.GWT; |
29 | |
import com.google.gwt.event.dom.client.ClickEvent; |
30 | |
import com.google.gwt.event.dom.client.ClickHandler; |
31 | |
import com.google.gwt.user.client.DOM; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class CourseAdminController extends CourseProposalController{ |
43 | |
|
44 | 0 | List<KSButton> cancelButtons = new ArrayList<KSButton>(); |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@Override |
50 | |
protected void initializeController() { |
51 | |
|
52 | 0 | super.cfg = GWT.create(CourseAdminConfigurer.class); |
53 | 0 | super.proposalPath = cfg.getProposalPath(); |
54 | 0 | super.workflowUtil = new WorkflowUtilities(CourseAdminController.this ,proposalPath); |
55 | |
|
56 | 0 | cfg.setState(DtoConstants.STATE_DRAFT.toUpperCase()); |
57 | 0 | cfg.setNextState(DtoConstants.STATE_APPROVED.toUpperCase()); |
58 | 0 | super.setDefaultModelId(cfg.getModelId()); |
59 | 0 | super.registerModelsAndHandlers(); |
60 | 0 | super.addStyleName("ks-course-admin"); |
61 | 0 | currentDocType = LUConstants.PROPOSAL_TYPE_COURSE_CREATE_ADMIN; |
62 | |
|
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
@Override |
69 | |
public KSButton getSaveButton(){ |
70 | 0 | return new KSButton("Save", new ClickHandler(){ |
71 | |
public void onClick(ClickEvent event) { |
72 | 0 | handleButtonClick(DtoConstants.STATE_DRAFT); |
73 | 0 | } |
74 | |
}); |
75 | |
} |
76 | |
|
77 | |
public KSButton getApproveButton(){ |
78 | 0 | return new KSButton("Approve", new ClickHandler(){ |
79 | |
public void onClick(ClickEvent event) { |
80 | 0 | handleButtonClick(DtoConstants.STATE_APPROVED); |
81 | 0 | } |
82 | |
}); |
83 | |
} |
84 | |
|
85 | |
public KSButton getApproveAndActivateButton(){ |
86 | 0 | return new KSButton("Approve and Activate", new ClickHandler(){ |
87 | |
public void onClick(ClickEvent event) { |
88 | 0 | handleButtonClick(DtoConstants.STATE_ACTIVE); |
89 | 0 | } |
90 | |
}); |
91 | |
} |
92 | |
|
93 | |
public KSButton getCancelButton(){ |
94 | 0 | KSButton cancelButton = new KSButton("Cancel Proposal", new ClickHandler(){ |
95 | |
public void onClick(ClickEvent event) { |
96 | |
|
97 | 0 | workflowUtil.cancel(new Callback<Boolean>(){ |
98 | |
@Override |
99 | |
public void exec(Boolean result) { |
100 | 0 | if (result){ |
101 | 0 | Application.navigate(AppLocations.Locations.CURRICULUM_MANAGEMENT.getLocation()); |
102 | |
} |
103 | 0 | } |
104 | |
|
105 | |
}); |
106 | 0 | } |
107 | |
}); |
108 | |
|
109 | 0 | if (LUConstants.PROPOSAL_TYPE_COURSE_CREATE_ADMIN.equals(currentDocType)){ |
110 | |
|
111 | |
|
112 | 0 | cancelButton.setEnabled(false); |
113 | |
} |
114 | |
|
115 | 0 | cancelButtons.add(cancelButton); |
116 | 0 | return cancelButton; |
117 | |
} |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
protected void handleButtonClick(final String state){ |
127 | 0 | cluProposalModel.set(QueryPath.parse(CreditCourseConstants.STATE), state); |
128 | 0 | final SaveActionEvent saveActionEvent = new SaveActionEvent(false); |
129 | |
|
130 | 0 | if (DtoConstants.STATE_APPROVED.equalsIgnoreCase(state) || DtoConstants.STATE_ACTIVE.equalsIgnoreCase(state)){ |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | 0 | saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){ |
137 | |
@Override |
138 | |
public void onActionComplete(ActionEvent actionEvent) { |
139 | 0 | if (saveActionEvent.isSaveSuccessful()){ |
140 | 0 | workflowUtil.blanketApprove(new Callback<Boolean>(){ |
141 | |
@Override |
142 | |
public void exec(Boolean result) { |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | 0 | final ViewContext viewContext = new ViewContext(); |
150 | 0 | viewContext.setId((String)cluProposalModel.get(CreditCourseConstants.ID)); |
151 | 0 | viewContext.setIdType(IdType.OBJECT_ID); |
152 | 0 | if (DtoConstants.STATE_APPROVED.equalsIgnoreCase(state)){ |
153 | 0 | KSNotifier.show("Course approved. It may take a minute or two for course status to be updated. Refresh to see latest status."); |
154 | 0 | Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext); |
155 | 0 | } else if (DtoConstants.STATE_ACTIVE.equalsIgnoreCase(state)){ |
156 | |
|
157 | 0 | CourseWorkflowActionList.setCourseState(viewContext.getId(), DtoConstants.STATE_ACTIVE, new Callback<String>(){ |
158 | |
@Override |
159 | |
public void exec(String result) { |
160 | 0 | if (result == null){ |
161 | 0 | KSNotifier.show("Course approved, but activation failed."); |
162 | |
} else { |
163 | 0 | KSNotifier.show("Course approved and activated. It may take a minute or two for course status to be updated. Refresh to see latest status."); |
164 | |
} |
165 | 0 | Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext); |
166 | 0 | } |
167 | |
}); |
168 | |
} |
169 | |
|
170 | 0 | } |
171 | |
}); |
172 | |
} |
173 | 0 | } |
174 | |
}); |
175 | |
} else { |
176 | |
|
177 | 0 | saveActionEvent.setActionCompleteCallback(new ActionCompleteCallback(){ |
178 | |
@Override |
179 | |
public void onActionComplete(ActionEvent action) { |
180 | 0 | for (KSButton cancelButton:cancelButtons){ |
181 | 0 | cancelButton.setEnabled(true); |
182 | |
} |
183 | 0 | } |
184 | |
}); |
185 | |
} |
186 | |
|
187 | 0 | CourseAdminController.this.fireApplicationEvent(saveActionEvent); |
188 | 0 | } |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
@Override |
194 | |
protected void setHeaderTitle(){ |
195 | |
String title; |
196 | 0 | if (cluProposalModel.get(cfg.getProposalTitlePath()) != null){ |
197 | 0 | title = getProposalTitle(); |
198 | |
} |
199 | |
else{ |
200 | 0 | title = "New Course (Admin Proposal)"; |
201 | |
} |
202 | 0 | this.setContentTitle(title); |
203 | 0 | this.setName(title); |
204 | 0 | WindowTitleUtils.setContextTitle(title); |
205 | 0 | currentTitle = title; |
206 | 0 | } |
207 | |
|
208 | |
private String getProposalTitle(){ |
209 | 0 | StringBuffer sb = new StringBuffer(); |
210 | 0 | sb.append(cluProposalModel.get(cfg.getProposalTitlePath())); |
211 | 0 | sb.append(" (Admin Proposal)"); |
212 | 0 | return sb.toString(); |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public void addMenuItemSection(String parentMenu, final String sectionName, final String sectionId, final Section section) { |
225 | 0 | KSMenuItemData parentItem = null; |
226 | 0 | for (int i = 0; i < topLevelMenuItems.size(); i++) { |
227 | 0 | if (topLevelMenuItems.get(i).getLabel().equals(parentMenu)) { |
228 | 0 | parentItem = topLevelMenuItems.get(i); |
229 | 0 | break; |
230 | |
} |
231 | |
} |
232 | |
|
233 | 0 | KSMenuItemData item = new KSMenuItemData(sectionName); |
234 | 0 | ((BaseSection)section).setSectionId(sectionId); |
235 | 0 | item.setClickHandler(new ClickHandler(){ |
236 | |
public void onClick(ClickEvent event) { |
237 | |
|
238 | 0 | DOM.getElementById(sectionId).scrollIntoView(); |
239 | 0 | } |
240 | |
}); |
241 | |
|
242 | 0 | if (parentItem != null) { |
243 | 0 | parentItem.addSubItem(item); |
244 | |
} else { |
245 | 0 | topLevelMenuItems.add(item); |
246 | |
} |
247 | |
|
248 | 0 | menu.refresh(); |
249 | 0 | } |
250 | |
|
251 | |
} |