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