| 1 | |
package org.kuali.student.lum.lu.ui.course.client.widgets; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Date; |
| 5 | |
import java.util.List; |
| 6 | |
|
| 7 | |
import org.kuali.student.common.assembly.data.QueryPath; |
| 8 | |
import org.kuali.student.common.dto.DtoConstants; |
| 9 | |
import org.kuali.student.common.dto.StatusInfo; |
| 10 | |
import org.kuali.student.common.rice.StudentIdentityConstants; |
| 11 | |
import org.kuali.student.common.ui.client.application.Application; |
| 12 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
| 13 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
| 14 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
| 15 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; |
| 16 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
| 17 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 18 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
| 19 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
| 20 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
| 21 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
| 22 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
| 23 | |
import org.kuali.student.common.ui.client.widgets.KSRadioButton; |
| 24 | |
import org.kuali.student.common.ui.client.widgets.StylishDropDown; |
| 25 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
| 26 | |
import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; |
| 27 | |
import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; |
| 28 | |
import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; |
| 29 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
| 30 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
| 31 | |
import org.kuali.student.lum.lu.LUConstants; |
| 32 | |
import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants; |
| 33 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService; |
| 34 | |
import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync; |
| 35 | |
|
| 36 | |
import com.google.gwt.core.client.GWT; |
| 37 | |
import com.google.gwt.event.dom.client.ClickEvent; |
| 38 | |
import com.google.gwt.event.dom.client.ClickHandler; |
| 39 | |
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
| 40 | |
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
| 41 | |
import com.google.gwt.user.client.Window; |
| 42 | |
import com.google.gwt.user.client.ui.Anchor; |
| 43 | |
import com.google.gwt.user.client.ui.FlowPanel; |
| 44 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
| 45 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
| 46 | |
import com.google.gwt.user.client.ui.Widget; |
| 47 | |
|
| 48 | 0 | public class CourseWorkflowActionList extends StylishDropDown { |
| 49 | |
private static final String MSG_GROUP = "course"; |
| 50 | |
|
| 51 | 0 | private static final BlockingTask processingTask = new BlockingTask("Processing State Change...."); |
| 52 | 0 | private static final CourseRpcServiceAsync courseServiceAsync = GWT.create(CourseRpcService.class); |
| 53 | |
|
| 54 | |
private KSMenuItemData modifyCourseActionItem; |
| 55 | |
private KSMenuItemData activateCourseActionItem; |
| 56 | |
private KSMenuItemData inactivateCourseActionItem; |
| 57 | |
private KSMenuItemData retireCourseActionItem; |
| 58 | |
private KSMenuItemData copyCourseActionItem; |
| 59 | |
|
| 60 | 0 | private final KSLightBox activateDialog = new KSLightBox(); |
| 61 | 0 | private VerticalSection activateSection = new VerticalSection(); |
| 62 | |
|
| 63 | |
private boolean isCurrentVersion; |
| 64 | 0 | private boolean isInitialized = false; |
| 65 | |
private String courseId; |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 0 | private List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); |
| 70 | |
|
| 71 | |
public CourseWorkflowActionList(String label) { |
| 72 | 0 | super(label); |
| 73 | |
|
| 74 | 0 | this.setVisible(false); |
| 75 | 0 | this.addStyleName("KS-Workflow-DropDown"); |
| 76 | |
|
| 77 | 0 | } |
| 78 | |
|
| 79 | |
public CourseWorkflowActionList(String label, final ViewContext viewContext, final String modifyPath, DataModel model, final Callback<String> stateChangeCallback) { |
| 80 | 0 | super(label); |
| 81 | |
|
| 82 | 0 | this.setVisible(false); |
| 83 | 0 | this.addStyleName("KS-Workflow-DropDown"); |
| 84 | |
|
| 85 | 0 | init(viewContext, modifyPath, model, stateChangeCallback); |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
public void init (final ViewContext viewContext, final String modifyPath, final DataModel model, final Callback<String> stateChangeCallback) { |
| 89 | |
|
| 90 | 0 | if (!this.isInitialized) { |
| 91 | 0 | buildActivateDialog(stateChangeCallback); |
| 92 | |
|
| 93 | 0 | this.isCurrentVersion = CourseWorkflowActionList.isCurrentVersion(model); |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | 0 | if ("admin".equals(Application.getApplicationContext().getUserId())){ |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | 0 | modifyCourseActionItem = new KSMenuItemData(this.getMessage("cluModifyItem"), new ClickHandler(){ |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public void onClick(ClickEvent event) { |
| 106 | 0 | buildModifyDialog(viewContext, modifyPath, model); |
| 107 | 0 | } |
| 108 | |
}); |
| 109 | |
} else { |
| 110 | |
|
| 111 | |
|
| 112 | 0 | modifyCourseActionItem = new KSMenuItemData(this.getMessage("cluModifyItem"), new ClickHandler(){ |
| 113 | |
|
| 114 | |
@Override |
| 115 | |
public void onClick(ClickEvent event) { |
| 116 | 0 | doModifyActionItem(viewContext, modifyPath, model); |
| 117 | 0 | } |
| 118 | |
}); |
| 119 | |
} |
| 120 | |
|
| 121 | 0 | copyCourseActionItem = new KSMenuItemData(this.getMessage("cluCopyItem"), new ClickHandler(){ |
| 122 | |
@Override |
| 123 | |
public void onClick(ClickEvent event) { |
| 124 | 0 | if(hasCourseId(viewContext)){ |
| 125 | 0 | viewContext.setId((String)model.get(CreditCourseConstants.ID)); |
| 126 | 0 | viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); |
| 127 | 0 | viewContext.getAttributes().remove(StudentIdentityConstants.DOCUMENT_TYPE_NAME); |
| 128 | |
} |
| 129 | 0 | HistoryManager.navigate(modifyPath, viewContext); |
| 130 | 0 | } |
| 131 | |
}); |
| 132 | 0 | activateCourseActionItem = new KSMenuItemData(this.getMessage("cluActivateItem"), new ClickHandler(){ |
| 133 | |
|
| 134 | |
@Override |
| 135 | |
public void onClick(ClickEvent event) { |
| 136 | 0 | showStateDialog(DtoConstants.STATE_ACTIVE); |
| 137 | 0 | } |
| 138 | |
}); |
| 139 | 0 | inactivateCourseActionItem = new KSMenuItemData(this.getMessage("cluInactivateItem") + " (Not Yet Implemented)", new ClickHandler(){ |
| 140 | |
|
| 141 | |
@Override |
| 142 | |
public void onClick(ClickEvent event) { |
| 143 | |
|
| 144 | 0 | } |
| 145 | |
}); |
| 146 | 0 | retireCourseActionItem = new KSMenuItemData(this.getMessage("cluRetireItem") + " (Not Yet Implemented)", new ClickHandler(){ |
| 147 | |
|
| 148 | |
@Override |
| 149 | |
public void onClick(ClickEvent event) { |
| 150 | |
|
| 151 | 0 | } |
| 152 | |
}); |
| 153 | |
} |
| 154 | |
|
| 155 | 0 | this.isInitialized = true; |
| 156 | 0 | } |
| 157 | |
|
| 158 | |
private void doModifyActionItem(ViewContext viewContext, String modifyPath, DataModel model){ |
| 159 | 0 | if(hasCourseId(viewContext)){ |
| 160 | 0 | viewContext.setId(getCourseVersionIndId(model)); |
| 161 | 0 | viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); |
| 162 | 0 | viewContext.setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_COURSE_MODIFY); |
| 163 | |
} |
| 164 | |
|
| 165 | 0 | HistoryManager.navigate(modifyPath, viewContext); |
| 166 | 0 | } |
| 167 | |
|
| 168 | |
private void showStateDialog(String newState) { |
| 169 | 0 | if (newState.equals(DtoConstants.STATE_RETIRED)) { |
| 170 | |
|
| 171 | 0 | } else if (newState.equals(DtoConstants.STATE_ACTIVE)) { |
| 172 | |
|
| 173 | 0 | activateSection.setInstructions(getInstructions(newState)); |
| 174 | 0 | activateDialog.show(); |
| 175 | 0 | } else if (newState.equals(DtoConstants.STATE_INACTIVE)) { |
| 176 | |
|
| 177 | |
} |
| 178 | |
|
| 179 | 0 | } |
| 180 | |
|
| 181 | |
private String getInstructions(String newState) { |
| 182 | 0 | if (isCurrentVersion){ |
| 183 | |
|
| 184 | 0 | return "Activating this course makes it viewable and available for scheduling."; |
| 185 | |
} else { |
| 186 | |
|
| 187 | 0 | return "Activate this course makes it viewable and available for scheduling. The previous version will be inactivated, and available for reference in the version history."; |
| 188 | |
} |
| 189 | |
} |
| 190 | |
|
| 191 | |
private void buildActivateDialog(final Callback<String> stateChangeCallback){ |
| 192 | 0 | FlowPanel panel = new FlowPanel(); |
| 193 | |
|
| 194 | 0 | activateDialog.setMaxHeight(200); |
| 195 | 0 | activateDialog.setMaxWidth(200); |
| 196 | |
|
| 197 | |
|
| 198 | 0 | activateSection = new VerticalSection(SectionTitle.generateH2Title("Activate Course")); |
| 199 | |
|
| 200 | 0 | panel.add((Widget)activateSection); |
| 201 | |
|
| 202 | 0 | KSButton activate = new KSButton("Activate",new ClickHandler(){ |
| 203 | |
public void onClick(ClickEvent event) { |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | 0 | setCourseState(courseId, DtoConstants.STATE_ACTIVE, stateChangeCallback); |
| 208 | 0 | activateDialog.hide(); |
| 209 | 0 | } |
| 210 | |
}); |
| 211 | 0 | activateDialog.addButton(activate); |
| 212 | |
|
| 213 | 0 | KSButton cancel = new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ |
| 214 | |
public void onClick(ClickEvent event) { |
| 215 | 0 | activateDialog.hide(); |
| 216 | 0 | } |
| 217 | |
}); |
| 218 | 0 | activateDialog.addButton(cancel); |
| 219 | |
|
| 220 | 0 | activateDialog.setWidget(panel); |
| 221 | 0 | } |
| 222 | |
|
| 223 | |
private void buildModifyDialog(final ViewContext viewContext, final String modifyPath, final DataModel model){ |
| 224 | 0 | final KSLightBox modifyDialog = new KSLightBox(); |
| 225 | |
|
| 226 | |
|
| 227 | 0 | modifyDialog.setTitle((getMessage("modifyCourse"))); |
| 228 | |
|
| 229 | 0 | VerticalPanel layout = new VerticalPanel(); |
| 230 | 0 | layout.addStyleName("ks-form-module-fields"); |
| 231 | |
|
| 232 | 0 | final KSButton continueButton = new KSButton(getMessage("continue")); |
| 233 | |
|
| 234 | 0 | modifyDialog.addButton(continueButton); |
| 235 | 0 | Anchor cancelLink = new Anchor("Cancel"); |
| 236 | 0 | cancelLink.addClickHandler(new ClickHandler(){ |
| 237 | |
public void onClick(ClickEvent event) { |
| 238 | 0 | modifyDialog.hide(); |
| 239 | 0 | } |
| 240 | |
}); |
| 241 | 0 | modifyDialog.addButton(cancelLink); |
| 242 | |
|
| 243 | 0 | HorizontalPanel titlePanel = new HorizontalPanel(); |
| 244 | 0 | KSLabel titleLabel = new KSLabel(getMessage("modifyCourseSubTitle")); |
| 245 | 0 | titleLabel.addStyleName("bold"); |
| 246 | 0 | titlePanel.add(titleLabel); |
| 247 | |
|
| 248 | 0 | layout.add(titlePanel); |
| 249 | |
|
| 250 | 0 | final KSRadioButton radioOptionModifyNoVersion = new KSRadioButton("modifyCreditCourseButtonGroup", getMessage("modifyCourseNoVersion")); |
| 251 | 0 | final KSRadioButton radioOptionModifyWithVersion = new KSRadioButton("modifyCreditCourseButtonGroup", getMessage("modifyCourseWithVersion")); |
| 252 | 0 | final KSCheckBox curriculumReviewOption = new KSCheckBox(getMessage("useCurriculumReview")); |
| 253 | |
|
| 254 | 0 | radioOptionModifyNoVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ |
| 255 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
| 256 | 0 | if(event.getValue()){ |
| 257 | 0 | curriculumReviewOption.setEnabled(false); |
| 258 | 0 | curriculumReviewOption.setValue(false); |
| 259 | |
} |
| 260 | 0 | } |
| 261 | |
}); |
| 262 | 0 | radioOptionModifyNoVersion.setValue(true); |
| 263 | 0 | curriculumReviewOption.setEnabled(false); |
| 264 | |
|
| 265 | 0 | radioOptionModifyWithVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ |
| 266 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
| 267 | 0 | if(event.getValue()){ |
| 268 | 0 | curriculumReviewOption.setEnabled(true); |
| 269 | |
} |
| 270 | 0 | } |
| 271 | |
}); |
| 272 | |
|
| 273 | |
|
| 274 | 0 | layout.add(radioOptionModifyNoVersion); |
| 275 | 0 | layout.add(radioOptionModifyWithVersion); |
| 276 | 0 | layout.add(curriculumReviewOption); |
| 277 | |
|
| 278 | 0 | continueButton.addClickHandler(new ClickHandler(){ |
| 279 | |
@Override |
| 280 | |
public void onClick(ClickEvent event) { |
| 281 | 0 | if (radioOptionModifyNoVersion.getValue()){ |
| 282 | 0 | viewContext.setId(courseId); |
| 283 | 0 | viewContext.setIdType(IdType.OBJECT_ID); |
| 284 | 0 | Application.navigate(AppLocations.Locations.COURSE_ADMIN_NO_VERSION.getLocation(), viewContext); |
| 285 | 0 | } else if (radioOptionModifyWithVersion.getValue() && curriculumReviewOption.getValue()){ |
| 286 | 0 | doModifyActionItem(viewContext, modifyPath, model); |
| 287 | 0 | } else if (radioOptionModifyWithVersion.getValue()){ |
| 288 | 0 | if(hasCourseId(viewContext)){ |
| 289 | 0 | viewContext.setId(getCourseVersionIndId(model)); |
| 290 | 0 | viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); |
| 291 | |
|
| 292 | 0 | viewContext.setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_COURSE_MODIFY); |
| 293 | |
} |
| 294 | |
|
| 295 | 0 | Application.navigate(AppLocations.Locations.COURSE_ADMIN.getLocation(), viewContext); |
| 296 | |
} |
| 297 | 0 | modifyDialog.hide(); |
| 298 | 0 | } |
| 299 | |
}); |
| 300 | 0 | modifyDialog.setWidget(layout); |
| 301 | 0 | modifyDialog.show(); |
| 302 | 0 | } |
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
public static void setCourseState(final String courseId, final String newState, final Callback<String> stateChangeCallback) { |
| 315 | 0 | KSBlockingProgressIndicator.addTask(processingTask); |
| 316 | |
|
| 317 | 0 | courseServiceAsync.changeState(courseId, newState, new KSAsyncCallback<StatusInfo>() { |
| 318 | |
|
| 319 | |
@Override |
| 320 | |
public void handleFailure(Throwable caught) { |
| 321 | 0 | Window.alert("Error Updating State: "+caught.getMessage()); |
| 322 | 0 | KSBlockingProgressIndicator.removeTask(processingTask); |
| 323 | 0 | stateChangeCallback.exec(null); |
| 324 | 0 | } |
| 325 | |
|
| 326 | |
@Override |
| 327 | |
public void onSuccess(StatusInfo result) { |
| 328 | 0 | KSBlockingProgressIndicator.removeTask(processingTask); |
| 329 | 0 | stateChangeCallback.exec(newState); |
| 330 | 0 | } |
| 331 | |
}); |
| 332 | |
|
| 333 | 0 | } |
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
public void updateCourseActionItems(DataModel cluModel) { |
| 342 | 0 | String cluState = cluModel.get("state"); |
| 343 | 0 | courseId = cluModel.get(CreditCourseConstants.ID); |
| 344 | |
|
| 345 | 0 | items.clear(); |
| 346 | |
|
| 347 | 0 | if (cluState.equals(DtoConstants.STATE_APPROVED)) { |
| 348 | 0 | items.add(modifyCourseActionItem); |
| 349 | 0 | items.add(activateCourseActionItem); |
| 350 | 0 | if (isCurrentVersion) { |
| 351 | 0 | items.add(retireCourseActionItem); |
| 352 | |
} |
| 353 | 0 | } else if (cluState.equals(DtoConstants.STATE_ACTIVE)) { |
| 354 | 0 | items.add(modifyCourseActionItem); |
| 355 | 0 | items.add(inactivateCourseActionItem); |
| 356 | 0 | items.add(retireCourseActionItem); |
| 357 | 0 | } else if (cluState.equals(DtoConstants.STATE_INACTIVE)) { |
| 358 | 0 | items.add(activateCourseActionItem); |
| 359 | |
} |
| 360 | |
|
| 361 | 0 | items.add(copyCourseActionItem); |
| 362 | |
|
| 363 | 0 | setItems(items); |
| 364 | |
|
| 365 | 0 | } |
| 366 | |
|
| 367 | |
public boolean isEmpty() { |
| 368 | 0 | return (items.size() == 0); |
| 369 | |
} |
| 370 | |
|
| 371 | |
public String getMessage(String courseMessageKey) { |
| 372 | 0 | String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey); |
| 373 | 0 | if (msg == null) { |
| 374 | 0 | msg = courseMessageKey; |
| 375 | |
} |
| 376 | 0 | return msg; |
| 377 | |
} |
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
public static boolean isCurrentVersion(DataModel courseModel) { |
| 386 | 0 | Date curVerStartDt = courseModel.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_CURRENT_VERSION_START); |
| 387 | 0 | Date curVerEndDt = courseModel.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_CURRENT_VERSION_END); |
| 388 | 0 | if (curVerStartDt != null && curVerEndDt == null) |
| 389 | 0 | return true; |
| 390 | |
else |
| 391 | 0 | return false; |
| 392 | |
|
| 393 | |
} |
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
private boolean hasCourseId(ViewContext viewContext){ |
| 401 | 0 | return viewContext != null && viewContext.getId() != null && !viewContext.getId().isEmpty(); |
| 402 | |
} |
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
private String getCourseVersionIndId(DataModel courseModel){ |
| 411 | 0 | return (String)courseModel.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_IND_ID); |
| 412 | |
} |
| 413 | |
} |