| 1 | |
package org.kuali.student.lum.program.client.major.view; |
| 2 | |
|
| 3 | |
import org.kuali.student.common.assembly.data.Data; |
| 4 | |
import org.kuali.student.common.assembly.data.Data.Property; |
| 5 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
| 6 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
| 7 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 8 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
| 9 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
| 10 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
| 11 | |
import org.kuali.student.lum.common.client.widgets.DropdownList; |
| 12 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
| 13 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
| 14 | |
import org.kuali.student.lum.program.client.ProgramSections; |
| 15 | |
import org.kuali.student.lum.program.client.ProgramStatus; |
| 16 | |
import org.kuali.student.lum.program.client.events.ModelLoadedEvent; |
| 17 | |
import org.kuali.student.lum.program.client.events.ProgramViewEvent; |
| 18 | |
import org.kuali.student.lum.program.client.major.ActionType; |
| 19 | |
import org.kuali.student.lum.program.client.major.MajorController; |
| 20 | |
|
| 21 | |
import com.google.gwt.core.client.GWT; |
| 22 | |
import com.google.gwt.event.dom.client.ChangeEvent; |
| 23 | |
import com.google.gwt.event.dom.client.ChangeHandler; |
| 24 | |
import com.google.gwt.event.shared.HandlerManager; |
| 25 | |
|
| 26 | |
|
| 27 | 0 | public class MajorViewController extends MajorController { |
| 28 | |
|
| 29 | 0 | private final DropdownList actionBox = new DropdownList(ActionType.getValues()); |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public MajorViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) { |
| 37 | 0 | super(programModel, viewContext, eventBus); |
| 38 | 0 | configurer = GWT.create(MajorViewConfigurer.class); |
| 39 | 0 | initHandlers(); |
| 40 | 0 | } |
| 41 | |
|
| 42 | |
private void initHandlers() { |
| 43 | 0 | actionBox.addChangeHandler(new ChangeHandler() { |
| 44 | |
@Override |
| 45 | |
public void onChange(ChangeEvent event) { |
| 46 | 0 | ActionType actionType = ActionType.of(actionBox.getSelectedValue()); |
| 47 | 0 | ViewContext viewContext = getViewContext(); |
| 48 | 0 | if (actionType == ActionType.MODIFY) { |
| 49 | 0 | ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum())); |
| 50 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext); |
| 51 | 0 | } else if (actionType == ActionType.MODIFY_VERSION) { |
| 52 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
| 53 | 0 | viewContext.setId(versionIndId); |
| 54 | 0 | viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); |
| 55 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext); |
| 56 | |
} |
| 57 | 0 | } |
| 58 | |
}); |
| 59 | 0 | eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() { |
| 60 | |
@Override |
| 61 | |
public void onEvent(ProgramViewEvent event) { |
| 62 | 0 | actionBox.setSelectedIndex(0); |
| 63 | 0 | } |
| 64 | |
}); |
| 65 | 0 | eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() { |
| 66 | |
@Override |
| 67 | |
public void onEvent(ModelLoadedEvent event) { |
| 68 | 0 | resetActionList(); |
| 69 | 0 | String type = context.getAttributes().get(ProgramConstants.TYPE); |
| 70 | 0 | if (type != null) { |
| 71 | 0 | context.getAttributes().remove(ProgramConstants.TYPE); |
| 72 | 0 | if (type.equals(ProgramConstants.VARIATION_TYPE_KEY)) { |
| 73 | 0 | showVariationView(); |
| 74 | |
} else { |
| 75 | |
|
| 76 | 0 | context.getAttributes().remove(ProgramConstants.VARIATION_ID); |
| 77 | 0 | showView(ProgramSections.VIEW_ALL); |
| 78 | |
} |
| 79 | |
} else { |
| 80 | 0 | context.getAttributes().remove(ProgramConstants.VARIATION_ID); |
| 81 | 0 | showView(ProgramSections.VIEW_ALL); |
| 82 | |
} |
| 83 | 0 | } |
| 84 | |
}); |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
protected void resetActionList() { |
| 88 | |
|
| 89 | 0 | ProgramStatus status = ProgramStatus.of(programModel); |
| 90 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
| 91 | 0 | Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER); |
| 92 | |
|
| 93 | 0 | actionBox.clear(); |
| 94 | 0 | if (status == ProgramStatus.ACTIVE){ |
| 95 | 0 | programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>(){ |
| 96 | |
public void onSuccess(Boolean isLatest) { |
| 97 | 0 | actionBox.setList(ActionType.getValues(isLatest)); |
| 98 | 0 | } |
| 99 | |
}); |
| 100 | |
} else { |
| 101 | 0 | actionBox.setList(ActionType.getValues(false)); |
| 102 | |
} |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
private void showVariationView() { |
| 106 | 0 | String variationId = context.getAttributes().get(ProgramConstants.VARIATION_ID); |
| 107 | 0 | if (variationId != null) { |
| 108 | 0 | final Data variationMap = getDataProperty(ProgramConstants.VARIATIONS); |
| 109 | 0 | if (variationMap != null) { |
| 110 | 0 | int row = 0; |
| 111 | 0 | for (Property p : variationMap) { |
| 112 | 0 | final Data variationData = p.getValue(); |
| 113 | 0 | if (variationData != null) { |
| 114 | 0 | if (variationData.get(ProgramConstants.ID).equals(variationId)) { |
| 115 | |
|
| 116 | |
|
| 117 | 0 | Data credData = getDataProperty(ProgramConstants.CREDENTIAL_PROGRAM); |
| 118 | 0 | variationData.set(ProgramConstants.CREDENTIAL_PROGRAM, credData); |
| 119 | 0 | ProgramRegistry.setData(variationData); |
| 120 | 0 | ProgramRegistry.setRow(row); |
| 121 | |
} |
| 122 | 0 | row++; |
| 123 | |
} |
| 124 | 0 | } |
| 125 | 0 | HistoryManager.navigate(AppLocations.Locations.VIEW_VARIATION.getLocation(), context); |
| 126 | |
} |
| 127 | |
} |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
@Override |
| 131 | |
protected void configureView() { |
| 132 | 0 | super.configureView(); |
| 133 | 0 | addContentWidget(actionBox); |
| 134 | 0 | initialized = true; |
| 135 | 0 | } |
| 136 | |
} |