| 1 |  |  package org.kuali.student.lum.lu.ui.course.client.widgets; | 
  | 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.dto.StatusInfo; | 
  | 9 |  |  import org.kuali.student.common.rice.StudentIdentityConstants; | 
  | 10 |  |  import org.kuali.student.common.ui.client.application.Application; | 
  | 11 |  |  import org.kuali.student.common.ui.client.application.KSAsyncCallback; | 
  | 12 |  |  import org.kuali.student.common.ui.client.application.ViewContext; | 
  | 13 |  |  import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; | 
  | 14 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; | 
  | 15 |  |  import org.kuali.student.common.ui.client.mvc.Callback; | 
  | 16 |  |  import org.kuali.student.common.ui.client.mvc.DataModel; | 
  | 17 |  |  import org.kuali.student.common.ui.client.mvc.history.HistoryManager; | 
  | 18 |  |  import org.kuali.student.common.ui.client.widgets.KSButton; | 
  | 19 |  |  import org.kuali.student.common.ui.client.widgets.KSCheckBox; | 
  | 20 |  |  import org.kuali.student.common.ui.client.widgets.KSLabel; | 
  | 21 |  |  import org.kuali.student.common.ui.client.widgets.KSLightBox; | 
  | 22 |  |  import org.kuali.student.common.ui.client.widgets.KSRadioButton; | 
  | 23 |  |  import org.kuali.student.common.ui.client.widgets.StylishDropDown; | 
  | 24 |  |  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; | 
  | 25 |  |  import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; | 
  | 26 |  |  import org.kuali.student.common.ui.client.widgets.notification.KSNotification; | 
  | 27 |  |  import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; | 
  | 28 |  |  import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; | 
  | 29 |  |  import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; | 
  | 30 |  |  import org.kuali.student.common.ui.shared.IdAttributes.IdType; | 
  | 31 |  |  import org.kuali.student.lum.common.client.widgets.AppLocations; | 
  | 32 |  |  import org.kuali.student.lum.lu.LUConstants; | 
  | 33 |  |  import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants; | 
  | 34 |  |  import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService; | 
  | 35 |  |  import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync; | 
  | 36 |  |   | 
  | 37 |  |  import com.google.gwt.core.client.GWT; | 
  | 38 |  |  import com.google.gwt.event.dom.client.ClickEvent; | 
  | 39 |  |  import com.google.gwt.event.dom.client.ClickHandler; | 
  | 40 |  |  import com.google.gwt.event.logical.shared.ValueChangeEvent; | 
  | 41 |  |  import com.google.gwt.event.logical.shared.ValueChangeHandler; | 
  | 42 |  |  import com.google.gwt.user.client.Window; | 
  | 43 |  |  import com.google.gwt.user.client.rpc.AsyncCallback; | 
  | 44 |  |  import com.google.gwt.user.client.ui.Anchor; | 
  | 45 |  |  import com.google.gwt.user.client.ui.FlowPanel; | 
  | 46 |  |  import com.google.gwt.user.client.ui.HorizontalPanel; | 
  | 47 |  |  import com.google.gwt.user.client.ui.VerticalPanel; | 
  | 48 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 49 |  |   | 
  | 50 | 0 |  public class CourseWorkflowActionList extends StylishDropDown { | 
  | 51 |  |      private static final String MSG_GROUP = "course"; | 
  | 52 |  |       | 
  | 53 | 0 |          private static final BlockingTask processingTask = new BlockingTask("Processing State Change...."); | 
  | 54 | 0 |          private static final CourseRpcServiceAsync courseServiceAsync = GWT.create(CourseRpcService.class);     | 
  | 55 |  |   | 
  | 56 |  |      private KSMenuItemData modifyCourseActionItem; | 
  | 57 |  |          private KSMenuItemData activateCourseActionItem; | 
  | 58 |  |          private KSMenuItemData inactivateCourseActionItem; | 
  | 59 |  |          private KSMenuItemData retireCourseActionItem; | 
  | 60 |  |          private KSMenuItemData copyCourseActionItem; | 
  | 61 |  |           | 
  | 62 | 0 |          private final KSLightBox activateDialog = new KSLightBox(); | 
  | 63 | 0 |          private VerticalSection activateSection = new VerticalSection(); | 
  | 64 |  |       | 
  | 65 |  |      private boolean isCurrentVersion; | 
  | 66 | 0 |      private Boolean isInitialized = false; | 
  | 67 |  |      private String courseId; | 
  | 68 |  |       | 
  | 69 | 0 |      private boolean hasAdminAccess = false; | 
  | 70 |  |          | 
  | 71 |  |       | 
  | 72 |  |       | 
  | 73 | 0 |      private final List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); | 
  | 74 |  |       | 
  | 75 |  |      public CourseWorkflowActionList(String label) { | 
  | 76 | 0 |              super(label); | 
  | 77 |  |               | 
  | 78 | 0 |              this.setVisible(false); | 
  | 79 | 0 |          this.addStyleName("KS-Workflow-DropDown"); | 
  | 80 |  |               | 
  | 81 | 0 |      } | 
  | 82 |  |   | 
  | 83 |  |          public CourseWorkflowActionList(String label, final ViewContext viewContext, final String modifyPath, DataModel model, final Callback<String> stateChangeCallback) { | 
  | 84 | 0 |              super(label); | 
  | 85 |  |           | 
  | 86 | 0 |              this.setVisible(false); | 
  | 87 | 0 |          this.addStyleName("KS-Workflow-DropDown"); | 
  | 88 |  |           | 
  | 89 | 0 |          init(viewContext, modifyPath, model, stateChangeCallback); | 
  | 90 | 0 |          } | 
  | 91 |  |           | 
  | 92 |  |          public void init (final ViewContext viewContext, final String modifyPath, final DataModel model, final Callback<String> stateChangeCallback) { | 
  | 93 |  |   | 
  | 94 | 0 |                  if (!this.isInitialized) { | 
  | 95 | 0 |                      buildActivateDialog(stateChangeCallback); | 
  | 96 |  |                       | 
  | 97 | 0 |                      this.isCurrentVersion = true; | 
  | 98 |  |                       | 
  | 99 |  |                       | 
  | 100 | 0 |                     modifyCourseActionItem = new KSMenuItemData(this.getMessage("cluModifyItem"), new ClickHandler(){ | 
  | 101 |  |           | 
  | 102 |  |                                  @Override | 
  | 103 |  |                                  public void onClick(ClickEvent event) { | 
  | 104 |  |                                           | 
  | 105 | 0 |                                          setupModifyCourseDialog(viewContext, modifyPath, model); | 
  | 106 | 0 |                                  } | 
  | 107 |  |                          }); | 
  | 108 |  |               | 
  | 109 | 0 |                      copyCourseActionItem = new KSMenuItemData(this.getMessage("cluCopyItem"), new ClickHandler(){ | 
  | 110 |  |                                  @Override | 
  | 111 |  |                                  public void onClick(ClickEvent event) { | 
  | 112 | 0 |                                      if(hasCourseId(viewContext)){ | 
  | 113 | 0 |                                              viewContext.setId((String)model.get(CreditCourseConstants.ID)); | 
  | 114 | 0 |                                                  viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); | 
  | 115 | 0 |                                                  viewContext.getAttributes().remove(StudentIdentityConstants.DOCUMENT_TYPE_NAME); | 
  | 116 |  |                                  } | 
  | 117 | 0 |                                          HistoryManager.navigate(modifyPath, viewContext); | 
  | 118 | 0 |                                  } | 
  | 119 |  |                          }); | 
  | 120 |  |   | 
  | 121 | 0 |                      activateCourseActionItem = new KSMenuItemData(this.getMessage("cluActivateItem"), new ClickHandler(){ | 
  | 122 |  |           | 
  | 123 |  |                                  @Override | 
  | 124 |  |                                  public void onClick(ClickEvent event) { | 
  | 125 | 0 |                                          showStateDialog(DtoConstants.STATE_ACTIVE); | 
  | 126 | 0 |                                  } | 
  | 127 |  |                          }); | 
  | 128 |  |                       | 
  | 129 | 0 |                      inactivateCourseActionItem = new KSMenuItemData(this.getMessage("cluInactivateItem") + " (Not Yet Implemented)", new ClickHandler(){ | 
  | 130 |  |           | 
  | 131 |  |                                  @Override | 
  | 132 |  |                                  public void onClick(ClickEvent event) { | 
  | 133 |  |                                                   | 
  | 134 | 0 |                                  } | 
  | 135 |  |                          }); | 
  | 136 |  |           | 
  | 137 | 0 |                      retireCourseActionItem = new KSMenuItemData(this.getMessage("cluRetireItem"), new ClickHandler(){ | 
  | 138 |  |           | 
  | 139 |  |                                  @Override | 
  | 140 |  |                                  public void onClick(ClickEvent event) { | 
  | 141 | 0 |                                      if(hasCourseId(viewContext)){ | 
  | 142 | 0 |                                                  viewContext.setId(courseId); | 
  | 143 | 0 |                                                  viewContext.setIdType(IdType.OBJECT_ID); | 
  | 144 |  |                                  } | 
  | 145 |  |                                           | 
  | 146 | 0 |                                      Application.navigate(AppLocations.Locations.COURSE_RETIRE.getLocation(), viewContext);                                     | 
  | 147 | 0 |                                  } | 
  | 148 |  |                          }); | 
  | 149 |  |                  } | 
  | 150 |  |                   | 
  | 151 | 0 |                  this.isInitialized = true; | 
  | 152 | 0 |      } | 
  | 153 |  |       | 
  | 154 |  |      private void doModifyActionItem(ViewContext viewContext, String modifyPath, DataModel model){ | 
  | 155 | 0 |              if(hasCourseId(viewContext)){ | 
  | 156 | 0 |                          viewContext.setId(getCourseVersionIndId(model)); | 
  | 157 | 0 |                          viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); | 
  | 158 | 0 |              viewContext.setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_COURSE_MODIFY); | 
  | 159 |  |          } | 
  | 160 |  |   | 
  | 161 | 0 |                  HistoryManager.navigate(modifyPath, viewContext); | 
  | 162 | 0 |      } | 
  | 163 |  |       | 
  | 164 |  |          private void showStateDialog(String newState) { | 
  | 165 | 0 |              if (newState.equals(DtoConstants.STATE_RETIRED)) { | 
  | 166 |  |                       | 
  | 167 | 0 |              } else if (newState.equals(DtoConstants.STATE_ACTIVE)) {                      | 
  | 168 |  |                       | 
  | 169 | 0 |                      activateSection.setInstructions(getInstructions(newState));                                     | 
  | 170 | 0 |                  activateDialog.show(); | 
  | 171 | 0 |              } else if (newState.equals(DtoConstants.STATE_SUSPENDED)) { | 
  | 172 |  |                       | 
  | 173 |  |              } | 
  | 174 |  |               | 
  | 175 | 0 |      } | 
  | 176 |  |           | 
  | 177 |  |      private String getInstructions(String newState) {             | 
  | 178 | 0 |              if (isCurrentVersion){ | 
  | 179 |  |                       | 
  | 180 | 0 |                      return "Activating this course makes it viewable and available for scheduling."; | 
  | 181 |  |              } else {  | 
  | 182 |  |                       | 
  | 183 | 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."; | 
  | 184 |  |              } | 
  | 185 |  |      } | 
  | 186 |  |       | 
  | 187 |  |      private void buildActivateDialog(final Callback<String> stateChangeCallback){ | 
  | 188 | 0 |              FlowPanel panel = new FlowPanel(); | 
  | 189 |  |               | 
  | 190 | 0 |              activateDialog.setMaxHeight(200); | 
  | 191 | 0 |              activateDialog.setMaxWidth(200); | 
  | 192 |  |               | 
  | 193 |  |               | 
  | 194 | 0 |              activateSection = new VerticalSection(SectionTitle.generateH2Title("Activate Course")); | 
  | 195 |  |               | 
  | 196 | 0 |          panel.add((Widget)activateSection); | 
  | 197 |  |               | 
  | 198 | 0 |              KSButton activate = new KSButton("Activate",new ClickHandler(){ | 
  | 199 |  |              public void onClick(ClickEvent event) { | 
  | 200 |  |                   | 
  | 201 |  |                   | 
  | 202 |  |                   | 
  | 203 | 0 |                  setCourseState(courseId, DtoConstants.STATE_ACTIVE, stateChangeCallback); | 
  | 204 | 0 |                  activateDialog.hide();                 | 
  | 205 | 0 |              } | 
  | 206 |  |              }); | 
  | 207 | 0 |              activateDialog.addButton(activate); | 
  | 208 |  |               | 
  | 209 | 0 |              KSButton cancel = new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ | 
  | 210 |  |              public void onClick(ClickEvent event) { | 
  | 211 | 0 |                  activateDialog.hide(); | 
  | 212 | 0 |              } | 
  | 213 |  |              }); | 
  | 214 | 0 |              activateDialog.addButton(cancel); | 
  | 215 |  |   | 
  | 216 | 0 |              activateDialog.setWidget(panel); | 
  | 217 | 0 |      } | 
  | 218 |  |       | 
  | 219 |  |      private void buildModifyDialog(final ViewContext viewContext, final String modifyPath, final DataModel model){ | 
  | 220 | 0 |              final KSLightBox modifyDialog = new KSLightBox(); | 
  | 221 |  |               | 
  | 222 |  |               | 
  | 223 | 0 |              modifyDialog.setTitle((getMessage("modifyCourse"))); | 
  | 224 |  |   | 
  | 225 | 0 |          final VerticalPanel layout = new VerticalPanel(); | 
  | 226 | 0 |          layout.addStyleName("ks-form-module-fields"); | 
  | 227 |  |                   | 
  | 228 | 0 |          final KSButton continueButton = new KSButton(getMessage("continue")); | 
  | 229 |  |           | 
  | 230 | 0 |          modifyDialog.addButton(continueButton); | 
  | 231 | 0 |          Anchor cancelLink = new Anchor("Cancel"); | 
  | 232 | 0 |          cancelLink.addClickHandler(new ClickHandler(){ | 
  | 233 |  |                          public void onClick(ClickEvent event) { | 
  | 234 | 0 |                                  modifyDialog.hide(); | 
  | 235 | 0 |                          } | 
  | 236 |  |          }); | 
  | 237 | 0 |          modifyDialog.addButton(cancelLink); | 
  | 238 |  |           | 
  | 239 | 0 |          HorizontalPanel titlePanel = new HorizontalPanel(); | 
  | 240 | 0 |          KSLabel titleLabel = new KSLabel(getMessage("modifyCourseSubTitle")); | 
  | 241 | 0 |          titleLabel.addStyleName("bold"); | 
  | 242 | 0 |          titlePanel.add(titleLabel); | 
  | 243 |  |           | 
  | 244 | 0 |          layout.add(titlePanel); | 
  | 245 |  |           | 
  | 246 | 0 |          final KSRadioButton radioOptionModifyNoVersion = new KSRadioButton("modifyCreditCourseButtonGroup", getMessage("modifyCourseNoVersion")); | 
  | 247 | 0 |          final KSRadioButton radioOptionModifyWithVersion = new KSRadioButton("modifyCreditCourseButtonGroup", getMessage("modifyCourseWithVersion")); | 
  | 248 | 0 |          final KSCheckBox curriculumReviewOption = new KSCheckBox(getMessage("useCurriculumReview")); | 
  | 249 |  |           | 
  | 250 | 0 |          radioOptionModifyNoVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ | 
  | 251 |  |                          public void onValueChange(ValueChangeEvent<Boolean> event) { | 
  | 252 | 0 |                                  if(event.getValue()){ | 
  | 253 | 0 |                              curriculumReviewOption.setEnabled(false); | 
  | 254 | 0 |                              curriculumReviewOption.setValue(false); | 
  | 255 |  |                                  } | 
  | 256 | 0 |                          } | 
  | 257 |  |          }); | 
  | 258 | 0 |          radioOptionModifyNoVersion.setValue(true); | 
  | 259 | 0 |              curriculumReviewOption.setEnabled(false); | 
  | 260 |  |           | 
  | 261 | 0 |          radioOptionModifyWithVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ | 
  | 262 |  |                          public void onValueChange(ValueChangeEvent<Boolean> event) { | 
  | 263 | 0 |                                  if(event.getValue()){ | 
  | 264 | 0 |                              curriculumReviewOption.setEnabled(true); | 
  | 265 |  |                                  } | 
  | 266 | 0 |                          } | 
  | 267 |  |          }); | 
  | 268 |  |           | 
  | 269 | 0 |          continueButton.addClickHandler(new ClickHandler(){ | 
  | 270 |  |                          @Override | 
  | 271 |  |                          public void onClick(ClickEvent event) { | 
  | 272 | 0 |                                  if (radioOptionModifyNoVersion.getValue()){ | 
  | 273 | 0 |                                          viewContext.setId(courseId); | 
  | 274 | 0 |                                          viewContext.setIdType(IdType.OBJECT_ID); | 
  | 275 | 0 |                                          Application.navigate(AppLocations.Locations.COURSE_ADMIN_NO_VERSION.getLocation(), viewContext); | 
  | 276 | 0 |                                  } else if (radioOptionModifyWithVersion.getValue()){ | 
  | 277 | 0 |                                      checkLatestVersion(viewContext, modifyPath, model, curriculumReviewOption.getValue());                             | 
  | 278 |  |                                       | 
  | 279 |  |                                  } | 
  | 280 | 0 |                              modifyDialog.hide(); | 
  | 281 | 0 |                          }                 | 
  | 282 |  |          }); | 
  | 283 |  |           | 
  | 284 |  |           | 
  | 285 |  |          | 
  | 286 | 0 |          layout.add(radioOptionModifyNoVersion); | 
  | 287 | 0 |          if(isCurrentVersion){ | 
  | 288 | 0 |                  layout.add(radioOptionModifyWithVersion); | 
  | 289 | 0 |              layout.add(curriculumReviewOption); | 
  | 290 |  |          } | 
  | 291 | 0 |          modifyDialog.setWidget(layout); | 
  | 292 | 0 |          modifyDialog.show(); | 
  | 293 | 0 |      } | 
  | 294 |  |       | 
  | 295 |  |       | 
  | 296 |  |   | 
  | 297 |  |   | 
  | 298 |  |   | 
  | 299 |  |   | 
  | 300 |  |   | 
  | 301 |  |   | 
  | 302 |  |   | 
  | 303 |  |   | 
  | 304 |  |      private void checkLatestVersion(final ViewContext viewContext, final String modifyPath, final DataModel model, final boolean reviewOption){ | 
  | 305 | 0 |          String courseVerIndId = getCourseVersionIndId(model); | 
  | 306 | 0 |          Long courseVersionSequence = getCourseVersionSequenceNumber(model); | 
  | 307 |  |       | 
  | 308 | 0 |          courseServiceAsync.isLatestVersion(courseVerIndId, courseVersionSequence, new AsyncCallback<Boolean>(){ | 
  | 309 |  |           | 
  | 310 |  |              public void onFailure(Throwable caught) { | 
  | 311 | 0 |                  KSNotifier.add(new KSNotification("Error determining latest version of course", false, 5000)); | 
  | 312 | 0 |              } | 
  | 313 |  |           | 
  | 314 |  |              public void onSuccess(Boolean result) { | 
  | 315 | 0 |                  if (result){ | 
  | 316 | 0 |                      if (reviewOption){ | 
  | 317 | 0 |                          doModifyActionItem(viewContext, modifyPath, model); | 
  | 318 |  |                      } else { | 
  | 319 | 0 |                          if(hasCourseId(viewContext)){ | 
  | 320 | 0 |                              viewContext.setId(getCourseVersionIndId(model)); | 
  | 321 | 0 |                              viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); | 
  | 322 |  |                               | 
  | 323 | 0 |                              viewContext.setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, LUConstants.PROPOSAL_TYPE_COURSE_MODIFY_ADMIN); | 
  | 324 |  |                          } | 
  | 325 |  |   | 
  | 326 | 0 |                          Application.navigate(AppLocations.Locations.COURSE_ADMIN.getLocation(), viewContext); | 
  | 327 |  |                      } | 
  | 328 |  |                  } else { | 
  | 329 | 0 |                      isCurrentVersion = false; | 
  | 330 | 0 |                      doUpdateCourseActionItems(model); | 
  | 331 | 0 |                      KSNotifier.add(new KSNotification("Error creating new version for course, this course is currently under modification.", false, 5000)); | 
  | 332 |  |                  } | 
  | 333 | 0 |              } | 
  | 334 |  |          }); | 
  | 335 | 0 |      } | 
  | 336 |  |       | 
  | 337 |  |       | 
  | 338 |  |       | 
  | 339 |  |           | 
  | 340 |  |   | 
  | 341 |  |   | 
  | 342 |  |   | 
  | 343 |  |   | 
  | 344 |  |   | 
  | 345 |  |   | 
  | 346 |  |   | 
  | 347 |  |      public static void setCourseState(final String courseId, final String newState, final Callback<String> stateChangeCallback) { | 
  | 348 | 0 |              KSBlockingProgressIndicator.addTask(processingTask); | 
  | 349 |  |               | 
  | 350 | 0 |              courseServiceAsync.changeState(courseId, newState, new KSAsyncCallback<StatusInfo>() { | 
  | 351 |  |                       | 
  | 352 |  |                      @Override | 
  | 353 |  |                   public void handleFailure(Throwable caught) { | 
  | 354 | 0 |                       Window.alert("Error Updating State: "+caught.getMessage()); | 
  | 355 | 0 |                       KSBlockingProgressIndicator.removeTask(processingTask); | 
  | 356 | 0 |                       stateChangeCallback.exec(null); | 
  | 357 | 0 |                   } | 
  | 358 |  |            | 
  | 359 |  |                   @Override | 
  | 360 |  |                   public void onSuccess(StatusInfo result) {                          | 
  | 361 | 0 |                           KSBlockingProgressIndicator.removeTask(processingTask); | 
  | 362 | 0 |                           if (!result.getSuccess()){ | 
  | 363 | 0 |                                   stateChangeCallback.exec(null); | 
  | 364 |  |                           } else { | 
  | 365 | 0 |                                   stateChangeCallback.exec(newState); | 
  | 366 |  |                           } | 
  | 367 | 0 |                   } | 
  | 368 |  |              }); | 
  | 369 |  |               | 
  | 370 | 0 |      } | 
  | 371 |  |       | 
  | 372 |  |       | 
  | 373 |  |           | 
  | 374 |  |   | 
  | 375 |  |   | 
  | 376 |  |   | 
  | 377 |  |   | 
  | 378 |  |      public void updateCourseActionItems(final DataModel cluModel) { | 
  | 379 |  |               | 
  | 380 |  |                   | 
  | 381 | 0 |                  String courseVerIndId = getCourseVersionIndId(cluModel); | 
  | 382 | 0 |                  Long courseVersionSequence = getCourseVersionSequenceNumber(cluModel); | 
  | 383 |  |                   | 
  | 384 | 0 |                  if(courseVerIndId==null){ | 
  | 385 | 0 |                          isCurrentVersion = true; | 
  | 386 | 0 |                          doUpdateCourseActionItems(cluModel); | 
  | 387 |  |                  }else{ | 
  | 388 | 0 |                          courseServiceAsync.isLatestVersion(courseVerIndId, courseVersionSequence, new AsyncCallback<Boolean>(){ | 
  | 389 |  |                                  public void onFailure(Throwable caught) { | 
  | 390 | 0 |                                          KSNotifier.add(new KSNotification("Error determining latest version of course", false, 5000)); | 
  | 391 | 0 |                                  } | 
  | 392 |  |                                   | 
  | 393 |  |                                  public void onSuccess(Boolean result) { | 
  | 394 | 0 |                                          isCurrentVersion = result; | 
  | 395 | 0 |                                          doUpdateCourseActionItems(cluModel); | 
  | 396 | 0 |                                  } | 
  | 397 |  |                          }); | 
  | 398 |  |                  } | 
  | 399 | 0 |      } | 
  | 400 |  |       | 
  | 401 |  |          private void doUpdateCourseActionItems(DataModel cluModel) { | 
  | 402 |  |                   | 
  | 403 | 0 |              final String cluState = cluModel.get("state"); | 
  | 404 | 0 |              courseId = cluModel.get(CreditCourseConstants.ID); | 
  | 405 |  |               | 
  | 406 | 0 |              items.clear();       | 
  | 407 |  |               | 
  | 408 | 0 |                  Application.getApplicationContext().getSecurityContext().checkScreenPermission("cluModifyItem", | 
  | 409 | 0 |                                  new Callback<Boolean>() { | 
  | 410 |  |                                          @Override | 
  | 411 |  |                                          public void exec(Boolean result) { | 
  | 412 |  |                                                   | 
  | 413 | 0 |                                                  if (!result){ | 
  | 414 | 0 |                                                      setItems(getNonAdminItems(cluState)); | 
  | 415 |  |                                                  } else { | 
  | 416 | 0 |                                                      setItems(getAdminItems(cluState)); | 
  | 417 |  |                                                  } | 
  | 418 |  |                                                   | 
  | 419 | 0 |                                              CourseWorkflowActionList.this.setEnabled(true); | 
  | 420 | 0 |                                                  if(CourseWorkflowActionList.this.isEmpty()) { | 
  | 421 | 0 |                                                          CourseWorkflowActionList.this.setVisible(false); | 
  | 422 |  |                                                  } | 
  | 423 |  |                                                  else{ | 
  | 424 | 0 |                                                          CourseWorkflowActionList.this.setVisible(true); | 
  | 425 |  |                                                  } | 
  | 426 | 0 |                                          } | 
  | 427 |  |                                  });                 | 
  | 428 | 0 |          } | 
  | 429 |  |           | 
  | 430 |  |          private List<KSMenuItemData> getNonAdminItems(String cluState){ | 
  | 431 | 0 |              if (cluState.equals(DtoConstants.STATE_APPROVED)) { | 
  | 432 | 0 |              items.add(modifyCourseActionItem); | 
  | 433 | 0 |              items.add(activateCourseActionItem); | 
  | 434 | 0 |          } else if (cluState.equals(DtoConstants.STATE_ACTIVE)) { | 
  | 435 | 0 |              items.add(modifyCourseActionItem); | 
  | 436 |  |   | 
  | 437 | 0 |          } else if (cluState.equals(DtoConstants.STATE_SUSPENDED)) { | 
  | 438 | 0 |              items.add(activateCourseActionItem); | 
  | 439 | 0 |          } else if (cluState.equals(DtoConstants.STATE_RETIRED)){ | 
  | 440 | 0 |              items.add(modifyCourseActionItem);           | 
  | 441 |  |          } | 
  | 442 | 0 |          items.add(copyCourseActionItem); | 
  | 443 |  |   | 
  | 444 | 0 |          if (!isCurrentVersion) { | 
  | 445 | 0 |              items.remove(modifyCourseActionItem); | 
  | 446 |  |          } | 
  | 447 |  |   | 
  | 448 | 0 |          return items; | 
  | 449 |  |      } | 
  | 450 |  |           | 
  | 451 |  |          private List<KSMenuItemData> getAdminItems(String cluState){ | 
  | 452 | 0 |              if (cluState.equals(DtoConstants.STATE_APPROVED)) { | 
  | 453 | 0 |              items.add(modifyCourseActionItem); | 
  | 454 | 0 |              items.add(activateCourseActionItem); | 
  | 455 | 0 |              if (isCurrentVersion){ | 
  | 456 | 0 |                  items.add(retireCourseActionItem); | 
  | 457 |  |              } | 
  | 458 | 0 |          } else if (cluState.equals(DtoConstants.STATE_ACTIVE)) { | 
  | 459 | 0 |              items.add(modifyCourseActionItem); | 
  | 460 |  |   | 
  | 461 | 0 |              items.add(retireCourseActionItem); | 
  | 462 | 0 |          } else if (cluState.equals(DtoConstants.STATE_SUSPENDED)) { | 
  | 463 | 0 |              items.add(activateCourseActionItem); | 
  | 464 | 0 |          } else if (cluState.equals(DtoConstants.STATE_RETIRED)){ | 
  | 465 | 0 |              items.add(modifyCourseActionItem);           | 
  | 466 | 0 |          } else if(cluState.equals(DtoConstants.STATE_SUPERSEDED)) { | 
  | 467 | 0 |              items.add(modifyCourseActionItem); | 
  | 468 |  |          } | 
  | 469 | 0 |              items.add(copyCourseActionItem); | 
  | 470 | 0 |              return items; | 
  | 471 |  |          } | 
  | 472 |  |           | 
  | 473 |  |      public boolean isEmpty() { | 
  | 474 | 0 |              return (items.size() == 0); | 
  | 475 |  |      } | 
  | 476 |  |       | 
  | 477 |  |      public String getMessage(String courseMessageKey) { | 
  | 478 | 0 |              String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey); | 
  | 479 | 0 |              if (msg == null) { | 
  | 480 | 0 |                      msg = courseMessageKey; | 
  | 481 |  |              } | 
  | 482 | 0 |              return msg; | 
  | 483 |  |      } | 
  | 484 |  |   | 
  | 485 |  |   | 
  | 486 |  |       | 
  | 487 |  |   | 
  | 488 |  |   | 
  | 489 |  |   | 
  | 490 |  |   | 
  | 491 |  |      private boolean hasCourseId(ViewContext viewContext){ | 
  | 492 | 0 |              return viewContext != null && viewContext.getId() != null && !viewContext.getId().isEmpty(); | 
  | 493 |  |      } | 
  | 494 |  |   | 
  | 495 |  |       | 
  | 496 |  |   | 
  | 497 |  |   | 
  | 498 |  |   | 
  | 499 |  |   | 
  | 500 |  |   | 
  | 501 |  |      private String getCourseVersionIndId(DataModel courseModel){ | 
  | 502 | 0 |              return (String)courseModel.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_IND_ID);             | 
  | 503 |  |      } | 
  | 504 |  |       | 
  | 505 |  |       | 
  | 506 |  |   | 
  | 507 |  |   | 
  | 508 |  |   | 
  | 509 |  |   | 
  | 510 |  |   | 
  | 511 |  |      private Long getCourseVersionSequenceNumber(DataModel courseModel){ | 
  | 512 | 0 |                     return (Long)courseModel.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_SEQ_NUMBER); | 
  | 513 |  |      } | 
  | 514 |  |   | 
  | 515 |  |      private void setupModifyCourseDialog(final ViewContext viewContext, final String modifyPath, final DataModel model) { | 
  | 516 | 0 |                  Application.getApplicationContext().getSecurityContext().checkScreenPermission("cluModifyItem", | 
  | 517 | 0 |                                  new Callback<Boolean>() { | 
  | 518 |  |                                          @Override | 
  | 519 |  |                                          public void exec(Boolean result) { | 
  | 520 | 0 |                                                  hasAdminAccess = result; | 
  | 521 | 0 |                                     if (hasAdminAccess){ | 
  | 522 |  |                                                       | 
  | 523 |  |                                               | 
  | 524 |  |                                               | 
  | 525 | 0 |                                                      buildModifyDialog(viewContext, modifyPath, model); | 
  | 526 |  |                                      } else { | 
  | 527 |  |                                               | 
  | 528 |  |                                               | 
  | 529 | 0 |                                          checkLatestVersion(viewContext, modifyPath, model, true); | 
  | 530 |  |                                      } | 
  | 531 |  |   | 
  | 532 |  |   | 
  | 533 | 0 |                                          } | 
  | 534 |  |                                  }); | 
  | 535 | 0 |          } | 
  | 536 |  |  } |