1 | |
package org.kuali.student.lum.program.client.major.view; |
2 | |
|
3 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
4 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
5 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
6 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
7 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
8 | |
import org.kuali.student.core.assembly.data.Data; |
9 | |
import org.kuali.student.core.assembly.data.Data.Property; |
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 | 0 | showView(ProgramSections.VIEW_ALL); |
76 | |
} |
77 | |
} else { |
78 | 0 | showView(ProgramSections.VIEW_ALL); |
79 | |
} |
80 | 0 | } |
81 | |
}); |
82 | 0 | } |
83 | |
|
84 | |
protected void resetActionList() { |
85 | |
|
86 | 0 | ProgramStatus status = ProgramStatus.of(programModel); |
87 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
88 | 0 | Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER); |
89 | |
|
90 | 0 | actionBox.clear(); |
91 | 0 | if (status == ProgramStatus.ACTIVE){ |
92 | 0 | programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>(){ |
93 | |
public void onSuccess(Boolean isLatest) { |
94 | 0 | actionBox.setList(ActionType.getValues(isLatest)); |
95 | 0 | } |
96 | |
}); |
97 | |
} else { |
98 | 0 | actionBox.setList(ActionType.getValues(false)); |
99 | |
} |
100 | 0 | } |
101 | |
|
102 | |
private void showVariationView() { |
103 | 0 | String variationId = context.getAttributes().get(ProgramConstants.VARIATION_ID); |
104 | 0 | if (variationId != null) { |
105 | 0 | context.getAttributes().remove(ProgramConstants.VARIATION_ID); |
106 | 0 | final Data variationMap = getDataProperty(ProgramConstants.VARIATIONS); |
107 | 0 | if (variationMap != null) { |
108 | 0 | int row = 0; |
109 | 0 | for (Property p : variationMap) { |
110 | 0 | final Data variationData = p.getValue(); |
111 | 0 | if (variationData != null) { |
112 | 0 | if (variationData.get(ProgramConstants.ID).equals(variationId)) { |
113 | |
|
114 | |
|
115 | 0 | Data credData = getDataProperty(ProgramConstants.CREDENTIAL_PROGRAM); |
116 | 0 | variationData.set(ProgramConstants.CREDENTIAL_PROGRAM, credData); |
117 | 0 | ProgramRegistry.setData(variationData); |
118 | 0 | ProgramRegistry.setRow(row); |
119 | |
} |
120 | 0 | row++; |
121 | |
} |
122 | 0 | } |
123 | 0 | HistoryManager.navigate(AppLocations.Locations.VIEW_VARIATION.getLocation(), context); |
124 | |
} |
125 | |
} |
126 | 0 | } |
127 | |
|
128 | |
@Override |
129 | |
protected void configureView() { |
130 | 0 | super.configureView(); |
131 | 0 | addContentWidget(actionBox); |
132 | 0 | initialized = true; |
133 | 0 | } |
134 | |
} |