| 1 |  |  package org.kuali.student.lum.lu.ui.course.client.views; | 
  | 2 |  |   | 
  | 3 |  |  import java.util.ArrayList; | 
  | 4 |  |  import java.util.List; | 
  | 5 |  |   | 
  | 6 |  |  import org.kuali.student.common.assembly.data.LookupMetadata; | 
  | 7 |  |  import org.kuali.student.common.assembly.data.Metadata; | 
  | 8 |  |  import org.kuali.student.common.assembly.data.QueryPath; | 
  | 9 |  |  import org.kuali.student.common.search.dto.SearchParam; | 
  | 10 |  |  import org.kuali.student.common.search.dto.SearchRequest; | 
  | 11 |  |  import org.kuali.student.common.search.dto.SortDirection; | 
  | 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.mvc.Callback; | 
  | 15 |  |  import org.kuali.student.common.ui.client.mvc.ViewComposite; | 
  | 16 |  |  import org.kuali.student.common.ui.client.mvc.history.HistoryManager; | 
  | 17 |  |  import org.kuali.student.common.ui.client.service.MetadataRpcService; | 
  | 18 |  |  import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync; | 
  | 19 |  |  import org.kuali.student.common.ui.client.widgets.KSButton; | 
  | 20 |  |  import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; | 
  | 21 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout; | 
  | 22 |  |  import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout; | 
  | 23 |  |  import org.kuali.student.common.ui.client.widgets.search.SearchResultsTable; | 
  | 24 |  |  import org.kuali.student.common.ui.shared.IdAttributes.IdType; | 
  | 25 |  |  import org.kuali.student.lum.common.client.widgets.AppLocations; | 
  | 26 |  |  import org.kuali.student.lum.lu.ui.course.client.controllers.VersionsController; | 
  | 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.Window; | 
  | 32 |  |   | 
  | 33 | 0 |  public class SelectVersionsView extends ViewComposite{ | 
  | 34 |  |   | 
  | 35 |  |   | 
  | 36 | 0 |          private VerticalFieldLayout layout = new VerticalFieldLayout(); | 
  | 37 |  |           | 
  | 38 | 0 |          private ButtonLayout buttons = new ButtonLayout(); | 
  | 39 | 0 |          SearchResultsTable table = new SearchResultsTable(); | 
  | 40 | 0 |          MetadataRpcServiceAsync metadataServiceAsync = GWT.create(MetadataRpcService.class); | 
  | 41 |  |          private String id1; | 
  | 42 |  |          private String id2; | 
  | 43 |  |           | 
  | 44 |  |          private VersionsController parent; | 
  | 45 |  |   | 
  | 46 |  |          public SelectVersionsView(VersionsController controller, String name, | 
  | 47 |  |                          Enum<?> viewType) { | 
  | 48 | 0 |                  super(controller, name, viewType); | 
  | 49 | 0 |                  this.initWidget(layout); | 
  | 50 | 0 |                  layout.addStyleName("selectVersions"); | 
  | 51 |  |                   | 
  | 52 |  |                   | 
  | 53 |  |                   | 
  | 54 | 0 |                  layout.addWidget(table); | 
  | 55 | 0 |                  layout.addButtonLayout(buttons); | 
  | 56 | 0 |                  parent = controller; | 
  | 57 |  |                   | 
  | 58 | 0 |                  layout.setLayoutTitle(SectionTitle.generateH2Title("Select Versions")); | 
  | 59 | 0 |                  layout.setInstructions("Select two drafts to compare, or select one to view"); | 
  | 60 | 0 |                  buttons.addButton(new KSButton("Show Version(s)", new ClickHandler(){ | 
  | 61 |  |   | 
  | 62 |  |                          @Override | 
  | 63 |  |                          public void onClick(ClickEvent event) { | 
  | 64 | 0 |                                  if(table.getSelectedIds().size() == 1){ | 
  | 65 | 0 |                                          id1 = table.getSelectedIds().get(0); | 
  | 66 | 0 |                                          id2 = null; | 
  | 67 | 0 |                                          ViewContext context = new ViewContext(); | 
  | 68 | 0 |                                          context.setId(id1); | 
  | 69 | 0 |                                          getController().setViewContext(context); | 
  | 70 | 0 |                                          getController().showView(VersionsController.Views.VERSION_VIEW); | 
  | 71 | 0 |                                  } | 
  | 72 | 0 |                                  else if(table.getSelectedIds().size() == 2){ | 
  | 73 | 0 |                                          id1 = table.getSelectedIds().get(0); | 
  | 74 | 0 |                                          id2 = table.getSelectedIds().get(1); | 
  | 75 | 0 |                                          ViewContext context = new ViewContext(); | 
  | 76 | 0 |                                          context.setId(id1); | 
  | 77 | 0 |                                          context.setAttribute("docId2", id2); | 
  | 78 | 0 |                                          getController().setViewContext(context); | 
  | 79 | 0 |                                          getController().showView(VersionsController.Views.VERSION_COMPARE); | 
  | 80 | 0 |                                  } | 
  | 81 |  |                                  else{ | 
  | 82 | 0 |                                          Window.alert("Please select either a single version to VIEW or two versions to COMPARE"); | 
  | 83 |  |                                  } | 
  | 84 | 0 |                          } | 
  | 85 |  |                  })); | 
  | 86 | 0 |                  buttons.addButton(new KSButton("Return to Current Course", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ | 
  | 87 |  |   | 
  | 88 |  |                          @Override | 
  | 89 |  |                          public void onClick(ClickEvent event) { | 
  | 90 | 0 |                                  ViewContext context = new ViewContext(); | 
  | 91 | 0 |                                  context.setId(parent.getCurrentVersionId()); | 
  | 92 | 0 |                                  context.setIdType(IdType.OBJECT_ID); | 
  | 93 | 0 |                                  HistoryManager.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), context); | 
  | 94 | 0 |                          } | 
  | 95 |  |                  })); | 
  | 96 | 0 |          } | 
  | 97 |  |   | 
  | 98 |  |          @Override | 
  | 99 |  |          public void beforeShow(final Callback<Boolean> onReadyCallback) { | 
  | 100 |  |                   | 
  | 101 | 0 |              Metadata searchMetadata = parent.getDefinition().getMetadata(QueryPath.concat("searchCourseVersions")); | 
  | 102 |  |               | 
  | 103 | 0 |              LookupMetadata versionSearch = searchMetadata.getInitialLookup(); | 
  | 104 |  |   | 
  | 105 |  |   | 
  | 106 |  |   | 
  | 107 |  |   | 
  | 108 |  |   | 
  | 109 |  |   | 
  | 110 | 0 |              table.performSearch(generateRequest(versionSearch), versionSearch.getResults(), versionSearch.getResultReturnKey(), false); | 
  | 111 | 0 |                  onReadyCallback.exec(true); | 
  | 112 |  |   | 
  | 113 | 0 |          } | 
  | 114 |  |           | 
  | 115 |  |          private SearchRequest generateRequest(LookupMetadata versionSearch){ | 
  | 116 | 0 |              SearchRequest sr = new SearchRequest(); | 
  | 117 | 0 |          List<SearchParam> params = new ArrayList<SearchParam>(); | 
  | 118 | 0 |          SearchParam param = new SearchParam(); | 
  | 119 | 0 |          param.setKey("lu.queryParam.cluVersionIndId"); | 
  | 120 | 0 |          param.setValue(parent.getVersionIndId()); | 
  | 121 | 0 |          params.add(param); | 
  | 122 | 0 |          sr.setSortDirection(SortDirection.DESC); | 
  | 123 | 0 |          sr.setParams(params); | 
  | 124 | 0 |          sr.setSearchKey(versionSearch.getSearchTypeId()); | 
  | 125 | 0 |          if (versionSearch.getResultSortKey() != null) { | 
  | 126 | 0 |              sr.setSortColumn(versionSearch.getResultSortKey()); | 
  | 127 |  |          } | 
  | 128 | 0 |          return sr; | 
  | 129 |  |          } | 
  | 130 |  |   | 
  | 131 |  |           | 
  | 132 |  |          public String getId1() { | 
  | 133 | 0 |                  return id1; | 
  | 134 |  |          } | 
  | 135 |  |   | 
  | 136 |  |          public String getId2() { | 
  | 137 | 0 |                  return id2; | 
  | 138 |  |          } | 
  | 139 |  |  } |