| 1 | |
package org.kuali.student.lum.program.client.versions; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.List; |
| 5 | |
|
| 6 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
| 7 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
| 8 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
| 9 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 10 | |
import org.kuali.student.common.ui.client.mvc.ViewComposite; |
| 11 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
| 12 | |
import org.kuali.student.common.ui.client.service.MetadataRpcService; |
| 13 | |
import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync; |
| 14 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
| 15 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
| 16 | |
import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout; |
| 17 | |
import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout; |
| 18 | |
import org.kuali.student.common.ui.client.widgets.search.SearchResultsTable; |
| 19 | |
import org.kuali.student.core.assembly.data.LookupMetadata; |
| 20 | |
import org.kuali.student.core.assembly.data.Metadata; |
| 21 | |
import org.kuali.student.core.assembly.data.QueryPath; |
| 22 | |
import org.kuali.student.core.search.dto.SearchParam; |
| 23 | |
import org.kuali.student.core.search.dto.SearchRequest; |
| 24 | |
import org.kuali.student.core.search.dto.SortDirection; |
| 25 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
| 26 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
| 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 org.kuali.student.lum.program.client.ProgramRegistry; |
| 32 | |
|
| 33 | 0 | public class ProgramSelectVersionsView extends ViewComposite{ |
| 34 | |
|
| 35 | 0 | private VerticalFieldLayout layout = new VerticalFieldLayout(); |
| 36 | 0 | private ButtonLayout buttons = new ButtonLayout(); |
| 37 | 0 | SearchResultsTable table = new SearchResultsTable(); |
| 38 | 0 | MetadataRpcServiceAsync metadataServiceAsync = GWT.create(MetadataRpcService.class); |
| 39 | |
|
| 40 | |
private ProgramVersionsController parent; |
| 41 | |
private DataModel programModel; |
| 42 | |
|
| 43 | |
public ProgramSelectVersionsView(DataModel model, ProgramVersionsController controller,String name, Enum<?> viewType) { |
| 44 | 0 | super(controller, name, viewType); |
| 45 | 0 | this.initWidget(layout); |
| 46 | 0 | layout.addStyleName("selectVersions"); |
| 47 | 0 | layout.addWidget(table); |
| 48 | 0 | layout.addButtonLayout(buttons); |
| 49 | 0 | parent = controller; |
| 50 | 0 | this.programModel = model; |
| 51 | 0 | layout.setLayoutTitle(SectionTitle.generateH2Title("Program Versions")); |
| 52 | 0 | layout.setInstructions("Select a version to view"); |
| 53 | |
|
| 54 | 0 | table.setMutipleSelect(false); |
| 55 | 0 | buttons.addButton(new KSButton("Select", new ClickHandler(){ |
| 56 | |
|
| 57 | |
@Override |
| 58 | |
public void onClick(ClickEvent event) { |
| 59 | 0 | if(table.getSelectedIds().size() == 1){ |
| 60 | 0 | String id = table.getSelectedIds().get(0); |
| 61 | 0 | ViewContext viewContext = parent.getViewContext(); |
| 62 | 0 | viewContext.setId(id); |
| 63 | 0 | navigateToProgramView(viewContext); |
| 64 | |
} |
| 65 | 0 | } |
| 66 | |
})); |
| 67 | |
|
| 68 | 0 | buttons.addButton(new KSButton("Return to Selected Program", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ |
| 69 | |
|
| 70 | |
@Override |
| 71 | |
public void onClick(ClickEvent event) { |
| 72 | 0 | ViewContext viewContext = parent.getViewContext(); |
| 73 | 0 | viewContext.setId((String)programModel.get(ProgramConstants.ID)); |
| 74 | 0 | navigateToProgramView(viewContext); |
| 75 | 0 | } |
| 76 | |
})); |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
private void navigateToProgramView(ViewContext viewContext){ |
| 80 | 0 | ProgramRegistry.setCreateNew(true); |
| 81 | 0 | switch (parent.getType()){ |
| 82 | 0 | case MAJOR: HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), viewContext); break; |
| 83 | 0 | case CORE: HistoryManager.navigate(AppLocations.Locations.VIEW_CORE_PROGRAM.getLocation(), viewContext); break; |
| 84 | 0 | case CREDENTIAL: HistoryManager.navigate(AppLocations.Locations.VIEW_BACC_PROGRAM.getLocation(), viewContext); break; |
| 85 | |
} |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
@Override |
| 89 | |
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
| 90 | 0 | Metadata searchMetadata = programModel.getDefinition().getMetadata(QueryPath.concat("searchProgramVersions")); |
| 91 | 0 | LookupMetadata versionSearch = searchMetadata.getInitialLookup(); |
| 92 | 0 | table.performSearch(generateRequest(versionSearch), versionSearch.getResults(), versionSearch.getResultReturnKey(), false); |
| 93 | 0 | onReadyCallback.exec(true); |
| 94 | 0 | } |
| 95 | |
|
| 96 | |
private SearchRequest generateRequest(LookupMetadata versionSearch){ |
| 97 | 0 | SearchRequest sr = new SearchRequest(); |
| 98 | 0 | List<SearchParam> params = new ArrayList<SearchParam>(); |
| 99 | 0 | SearchParam param = new SearchParam(); |
| 100 | 0 | param.setKey("lu.queryParam.cluVersionIndId"); |
| 101 | 0 | String versionIndId = programModel.get(ProgramConstants.VERSION_IND_ID); |
| 102 | 0 | versionIndId = (versionIndId == null ? "":versionIndId); |
| 103 | 0 | param.setValue(versionIndId); |
| 104 | 0 | params.add(param); |
| 105 | 0 | sr.setSortDirection(SortDirection.DESC); |
| 106 | 0 | sr.setParams(params); |
| 107 | 0 | sr.setSearchKey(versionSearch.getSearchTypeId()); |
| 108 | 0 | if (versionSearch.getResultSortKey() != null) { |
| 109 | 0 | sr.setSortColumn(versionSearch.getResultSortKey()); |
| 110 | |
} |
| 111 | 0 | return sr; |
| 112 | |
} |
| 113 | |
|
| 114 | |
|
| 115 | |
} |