| 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.ui.client.application.Application; | 
  | 8 |  |  import org.kuali.student.common.ui.client.application.KSAsyncCallback; | 
  | 9 |  |  import org.kuali.student.common.ui.client.application.ViewContext; | 
  | 10 |  |  import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; | 
  | 11 |  |  import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; | 
  | 12 |  |  import org.kuali.student.common.ui.client.mvc.Callback; | 
  | 13 |  |  import org.kuali.student.common.ui.client.mvc.DataModel; | 
  | 14 |  |  import org.kuali.student.common.ui.client.mvc.history.HistoryManager; | 
  | 15 |  |  import org.kuali.student.common.ui.client.widgets.KSButton; | 
  | 16 |  |  import org.kuali.student.common.ui.client.widgets.KSLightBox; | 
  | 17 |  |  import org.kuali.student.common.ui.client.widgets.StylishDropDown; | 
  | 18 |  |  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; | 
  | 19 |  |  import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; | 
  | 20 |  |  import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; | 
  | 21 |  |  import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; | 
  | 22 |  |  import org.kuali.student.common.ui.shared.IdAttributes.IdType; | 
  | 23 |  |  import org.kuali.student.core.assembly.data.QueryPath; | 
  | 24 |  |  import org.kuali.student.core.dto.StatusInfo; | 
  | 25 |  |  import org.kuali.student.core.rice.StudentIdentityConstants; | 
  | 26 |  |  import org.kuali.student.lum.common.client.lu.LUUIConstants; | 
  | 27 |  |  import org.kuali.student.lum.lu.assembly.data.client.constants.orch.CreditCourseConstants; | 
  | 28 |  |  import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService; | 
  | 29 |  |  import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcServiceAsync; | 
  | 30 |  |   | 
  | 31 |  |  import com.google.gwt.core.client.GWT; | 
  | 32 |  |  import com.google.gwt.event.dom.client.ClickEvent; | 
  | 33 |  |  import com.google.gwt.event.dom.client.ClickHandler; | 
  | 34 |  |  import com.google.gwt.user.client.Window; | 
  | 35 |  |  import com.google.gwt.user.client.ui.FlowPanel; | 
  | 36 |  |  import com.google.gwt.user.client.ui.Widget; | 
  | 37 |  |   | 
  | 38 | 0 |  public class CourseWorkflowActionList extends StylishDropDown { | 
  | 39 |  |      private static final String MSG_GROUP = "course"; | 
  | 40 |  |       | 
  | 41 |  |          private KSMenuItemData modifyCourseActionItem; | 
  | 42 |  |          private KSMenuItemData activateCourseActionItem; | 
  | 43 |  |          private KSMenuItemData inactivateCourseActionItem; | 
  | 44 |  |          private KSMenuItemData retireCourseActionItem; | 
  | 45 |  |           | 
  | 46 | 0 |          private final KSLightBox activateDialog = new KSLightBox(); | 
  | 47 | 0 |      private VerticalSection activateSection = new VerticalSection(); | 
  | 48 |  |       | 
  | 49 |  |      private boolean isCurrentVersion; | 
  | 50 | 0 |      private boolean isInitialized = false; | 
  | 51 |  |      private String courseId; | 
  | 52 |  |       | 
  | 53 | 0 |      private final BlockingTask processingTask = new BlockingTask("Processing State Change...."); | 
  | 54 |  |       | 
  | 55 | 0 |      CourseRpcServiceAsync rpcServiceAsync = GWT.create(CourseRpcService.class); | 
  | 56 |  |       | 
  | 57 |  |       | 
  | 58 | 0 |      private List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); | 
  | 59 |  |       | 
  | 60 |  |      public CourseWorkflowActionList(String label) { | 
  | 61 | 0 |              super(label); | 
  | 62 |  |               | 
  | 63 | 0 |              this.setVisible(false); | 
  | 64 | 0 |          this.addStyleName("KS-Workflow-DropDown"); | 
  | 65 |  |               | 
  | 66 | 0 |      } | 
  | 67 |  |   | 
  | 68 |  |          public CourseWorkflowActionList(String label, final ViewContext viewContext, final String modifyPath, DataModel model, final Callback<String> stateChangeCallback) { | 
  | 69 | 0 |              super(label); | 
  | 70 |  |           | 
  | 71 | 0 |              this.setVisible(false); | 
  | 72 | 0 |          this.addStyleName("KS-Workflow-DropDown"); | 
  | 73 |  |           | 
  | 74 | 0 |          init(viewContext, modifyPath, model, stateChangeCallback); | 
  | 75 | 0 |          } | 
  | 76 |  |           | 
  | 77 |  |          public void init (final ViewContext viewContext, final String modifyPath, final DataModel model, final Callback<String> stateChangeCallback) { | 
  | 78 |  |   | 
  | 79 | 0 |                  if (!this.isInitialized) { | 
  | 80 | 0 |                      buildActivateDialog(stateChangeCallback); | 
  | 81 |  |                       | 
  | 82 | 0 |                      this.isCurrentVersion = CourseWorkflowActionList.isCurrentVersion(model); | 
  | 83 |  |                       | 
  | 84 |  |                       | 
  | 85 | 0 |                      modifyCourseActionItem = new KSMenuItemData(this.getMessage("cluModifyItem"), new ClickHandler(){ | 
  | 86 |  |           | 
  | 87 |  |                                  @Override | 
  | 88 |  |                                  public void onClick(ClickEvent event) { | 
  | 89 | 0 |                                      if(viewContext != null && viewContext.getId() != null && !viewContext.getId().isEmpty()){ | 
  | 90 | 0 |                                                  viewContext.setId((String)model.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_IND_ID)); | 
  | 91 | 0 |                                                  viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); | 
  | 92 | 0 |                                      viewContext.setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, "kuali.proposal.type.course.modify"); | 
  | 93 |  |                                  } | 
  | 94 |  |   | 
  | 95 | 0 |                                          HistoryManager.navigate(modifyPath, viewContext); | 
  | 96 | 0 |                                  } | 
  | 97 |  |                          }); | 
  | 98 | 0 |                      activateCourseActionItem = new KSMenuItemData(this.getMessage("cluActivateItem"), new ClickHandler(){ | 
  | 99 |  |           | 
  | 100 |  |                                  @Override | 
  | 101 |  |                                  public void onClick(ClickEvent event) { | 
  | 102 | 0 |                                          showStateDialog(LUUIConstants.LU_STATE_ACTIVE); | 
  | 103 | 0 |                                  } | 
  | 104 |  |                          }); | 
  | 105 | 0 |                      inactivateCourseActionItem = new KSMenuItemData(this.getMessage("cluInactivateItem") + " (Not Yet Implemented)", new ClickHandler(){ | 
  | 106 |  |           | 
  | 107 |  |                                  @Override | 
  | 108 |  |                                  public void onClick(ClickEvent event) { | 
  | 109 |  |                                                   | 
  | 110 | 0 |                                  } | 
  | 111 |  |                          }); | 
  | 112 | 0 |                      retireCourseActionItem = new KSMenuItemData(this.getMessage("cluRetireItem") + " (Not Yet Implemented)", new ClickHandler(){ | 
  | 113 |  |           | 
  | 114 |  |                                  @Override | 
  | 115 |  |                                  public void onClick(ClickEvent event) { | 
  | 116 |  |                                                   | 
  | 117 | 0 |                                  } | 
  | 118 |  |                          }); | 
  | 119 |  |                  } | 
  | 120 |  |                   | 
  | 121 | 0 |                  this.isInitialized = true; | 
  | 122 | 0 |      } | 
  | 123 |  |       | 
  | 124 |  |      private void showStateDialog(String newState) { | 
  | 125 | 0 |              if (newState.equals(LUUIConstants.LU_STATE_RETIRED)) { | 
  | 126 |  |                       | 
  | 127 | 0 |              } else if (newState.equals(LUUIConstants.LU_STATE_ACTIVE)) {                      | 
  | 128 |  |                       | 
  | 129 | 0 |                      activateSection.setInstructions(getInstructions(newState));                                     | 
  | 130 | 0 |                  activateDialog.show(); | 
  | 131 | 0 |              } else if (newState.equals(LUUIConstants.LU_STATE_INACTIVE)) { | 
  | 132 |  |                       | 
  | 133 |  |              } | 
  | 134 |  |               | 
  | 135 | 0 |      } | 
  | 136 |  |       | 
  | 137 |  |      public static boolean isCurrentVersion(DataModel cluModel) { | 
  | 138 | 0 |              Date curVerStartDt = cluModel.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_CURRENT_VERSION_START);                 | 
  | 139 | 0 |              Date curVerEndDt = cluModel.get(CreditCourseConstants.VERSION_INFO + QueryPath.getPathSeparator() + CreditCourseConstants.VERSION_CURRENT_VERSION_END); | 
  | 140 | 0 |              if (curVerStartDt != null && curVerEndDt == null)  | 
  | 141 | 0 |                      return true; | 
  | 142 |  |              else | 
  | 143 | 0 |                      return false; | 
  | 144 |  |               | 
  | 145 |  |      } | 
  | 146 |  |       | 
  | 147 |  |      private String getInstructions(String newState) { | 
  | 148 |  |               | 
  | 149 | 0 |              if (isCurrentVersion) | 
  | 150 |  |                       | 
  | 151 | 0 |                      return "Activating this course makes it viewable and available for scheduling."; | 
  | 152 |  |              else  | 
  | 153 |  |                       | 
  | 154 | 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."; | 
  | 155 |  |      } | 
  | 156 |  |       | 
  | 157 |  |      private void buildActivateDialog(final Callback<String> stateChangeCallback){ | 
  | 158 | 0 |              FlowPanel panel = new FlowPanel(); | 
  | 159 |  |               | 
  | 160 | 0 |              activateDialog.setMaxHeight(200); | 
  | 161 | 0 |              activateDialog.setMaxWidth(200); | 
  | 162 |  |               | 
  | 163 |  |               | 
  | 164 | 0 |              activateSection = new VerticalSection(SectionTitle.generateH2Title("Activate Course")); | 
  | 165 |  |               | 
  | 166 | 0 |          panel.add((Widget)activateSection); | 
  | 167 |  |               | 
  | 168 | 0 |              KSButton activate = new KSButton("Activate",new ClickHandler(){ | 
  | 169 |  |              public void onClick(ClickEvent event) { | 
  | 170 |  |                   | 
  | 171 |  |                   | 
  | 172 |  |                   | 
  | 173 | 0 |                  setCourseState(LUUIConstants.LU_STATE_ACTIVE, stateChangeCallback); | 
  | 174 | 0 |                  activateDialog.hide();                 | 
  | 175 | 0 |              } | 
  | 176 |  |              }); | 
  | 177 | 0 |              activateDialog.addButton(activate); | 
  | 178 |  |               | 
  | 179 | 0 |              KSButton cancel = new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ | 
  | 180 |  |              public void onClick(ClickEvent event) { | 
  | 181 | 0 |                  activateDialog.hide(); | 
  | 182 | 0 |              } | 
  | 183 |  |              }); | 
  | 184 | 0 |              activateDialog.addButton(cancel); | 
  | 185 |  |   | 
  | 186 | 0 |              activateDialog.setWidget(panel); | 
  | 187 | 0 |      } | 
  | 188 |  |       | 
  | 189 |  |       | 
  | 190 |  |       | 
  | 191 |  |       | 
  | 192 |  |       | 
  | 193 |  |       | 
  | 194 |  |      private void setCourseState(final String newState, final Callback<String> stateChangeCallback) { | 
  | 195 | 0 |              KSBlockingProgressIndicator.addTask(processingTask); | 
  | 196 |  |               | 
  | 197 | 0 |              rpcServiceAsync.changeState(courseId, newState, new KSAsyncCallback<StatusInfo>() { | 
  | 198 |  |                       | 
  | 199 |  |                      @Override | 
  | 200 |  |                   public void handleFailure(Throwable caught) { | 
  | 201 | 0 |                       Window.alert("Error Updating State: "+caught.getMessage()); | 
  | 202 | 0 |                       KSBlockingProgressIndicator.removeTask(processingTask); | 
  | 203 |  |                        | 
  | 204 |  |                        | 
  | 205 | 0 |                       stateChangeCallback.exec(null); | 
  | 206 | 0 |                   } | 
  | 207 |  |            | 
  | 208 |  |                   @Override | 
  | 209 |  |                   public void onSuccess(StatusInfo result) {                          | 
  | 210 | 0 |                           KSBlockingProgressIndicator.removeTask(processingTask); | 
  | 211 |  |                            | 
  | 212 |  |                        | 
  | 213 | 0 |                           stateChangeCallback.exec(newState); | 
  | 214 | 0 |                   } | 
  | 215 |  |              }); | 
  | 216 |  |               | 
  | 217 | 0 |      } | 
  | 218 |  |       | 
  | 219 |  |       | 
  | 220 |  |       | 
  | 221 |  |      public void updateCourseActionItems(DataModel cluModel) { | 
  | 222 | 0 |              String cluState = cluModel.get("state"); | 
  | 223 | 0 |              courseId = cluModel.get(CreditCourseConstants.ID); | 
  | 224 |  |               | 
  | 225 | 0 |              items.clear();       | 
  | 226 |  |               | 
  | 227 | 0 |              if (cluState.equals(LUUIConstants.LU_STATE_APPROVED)) { | 
  | 228 | 0 |                      items.add(modifyCourseActionItem); | 
  | 229 | 0 |                      items.add(activateCourseActionItem); | 
  | 230 | 0 |                      if (isCurrentVersion) { | 
  | 231 | 0 |                              items.add(retireCourseActionItem); | 
  | 232 |  |                      } | 
  | 233 | 0 |              } else if (cluState.equals(LUUIConstants.LU_STATE_ACTIVE)) { | 
  | 234 | 0 |                      items.add(modifyCourseActionItem); | 
  | 235 | 0 |                      items.add(inactivateCourseActionItem); | 
  | 236 | 0 |                      items.add(retireCourseActionItem); | 
  | 237 | 0 |              } else if (cluState.equals(LUUIConstants.LU_STATE_INACTIVE)) { | 
  | 238 | 0 |                      items.add(activateCourseActionItem); | 
  | 239 |  |              } | 
  | 240 |  |                   | 
  | 241 | 0 |              setItems(items); | 
  | 242 |  |                       | 
  | 243 | 0 |      } | 
  | 244 |  |       | 
  | 245 |  |      public boolean isEmpty() { | 
  | 246 | 0 |              return (items.size() == 0); | 
  | 247 |  |      } | 
  | 248 |  |       | 
  | 249 |  |      public String getMessage(String courseMessageKey) { | 
  | 250 | 0 |              String msg = Application.getApplicationContext().getMessage(MSG_GROUP, courseMessageKey); | 
  | 251 | 0 |              if (msg == null) { | 
  | 252 | 0 |                      msg = courseMessageKey; | 
  | 253 |  |              } | 
  | 254 | 0 |              return msg; | 
  | 255 |  |      } | 
  | 256 |  |   | 
  | 257 |  |  } |