1 | |
package org.kuali.student.lum.program.client.variation; |
2 | |
|
3 | |
import com.google.gwt.core.client.GWT; |
4 | |
import com.google.gwt.event.dom.client.ClickEvent; |
5 | |
import com.google.gwt.event.dom.client.ClickHandler; |
6 | |
import com.google.gwt.user.client.Window; |
7 | |
import com.google.gwt.user.client.ui.Anchor; |
8 | |
import com.google.gwt.user.client.ui.FlexTable; |
9 | |
|
10 | |
import org.kuali.student.common.assembly.data.Data; |
11 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
12 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport; |
13 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
14 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
15 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
16 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
17 | |
import org.kuali.student.lum.common.client.configuration.Configuration; |
18 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
19 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
20 | |
import org.kuali.student.lum.program.client.ProgramUtils; |
21 | |
import org.kuali.student.lum.program.client.events.UpdateEvent; |
22 | |
import org.kuali.student.lum.program.client.major.MajorManager; |
23 | |
import org.kuali.student.lum.program.client.properties.ProgramProperties; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class VariationsBinding extends ModelWidgetBindingSupport<FlexTable> { |
29 | |
|
30 | |
private String url; |
31 | |
|
32 | |
private boolean editable; |
33 | |
|
34 | |
private Configuration configuration; |
35 | |
|
36 | 0 | public VariationsBinding(String url, boolean editable) { |
37 | 0 | this.url = url; |
38 | 0 | this.editable = editable; |
39 | 0 | } |
40 | |
|
41 | |
public VariationsBinding(String url, boolean editable, Configuration configuration) { |
42 | 0 | this(url, editable); |
43 | 0 | this.configuration = configuration; |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
public void setModelValue(FlexTable table, DataModel model, String path) { |
48 | 0 | GWT.log("VariationsBinding.setModelValue...", null); |
49 | 0 | } |
50 | |
|
51 | |
@Override |
52 | |
public void setWidgetValue(final FlexTable table, final DataModel model, String path) { |
53 | 0 | table.clear(); |
54 | 0 | final Data variationMap = model.get(path); |
55 | 0 | if (variationMap != null) { |
56 | 0 | int row = 0; |
57 | 0 | for (final Data.Property property : variationMap) { |
58 | 0 | final Data variationData = property.getValue(); |
59 | 0 | final int currentRow = row; |
60 | 0 | Anchor anchor = new Anchor(getVariationName(variationData)); |
61 | 0 | anchor.addClickHandler(new ClickHandler() { |
62 | |
@Override |
63 | |
public void onClick(ClickEvent event) { |
64 | 0 | ProgramRegistry.setData(variationData); |
65 | 0 | ProgramRegistry.setRow(currentRow); |
66 | 0 | ProgramUtils.addCredentialProgramDataToVariation(variationData, model); |
67 | 0 | String id = (String) model.get("id"); |
68 | 0 | ViewContext viewContext = new ViewContext(); |
69 | 0 | viewContext.setId(id); |
70 | 0 | viewContext.setIdType(IdType.OBJECT_ID); |
71 | 0 | HistoryManager.navigate(url, viewContext); |
72 | 0 | } |
73 | |
}); |
74 | 0 | table.setWidget(row, 0, anchor); |
75 | 0 | if (editable) { |
76 | 0 | KSButton removeButton = new KSButton(ProgramProperties.get().common_remove()); |
77 | 0 | table.setWidget(row, 1, removeButton); |
78 | 0 | removeButton.addClickHandler(new ClickHandler() { |
79 | |
|
80 | |
@Override |
81 | |
public void onClick(ClickEvent event) { |
82 | 0 | if (Window.confirm("Are you sure you want to delete specialization?")) { |
83 | 0 | variationMap.remove(new Data.IntegerKey(currentRow)); |
84 | 0 | MajorManager.getEventBus().fireEvent(new UpdateEvent()); |
85 | |
} |
86 | 0 | } |
87 | |
}); |
88 | 0 | if (configuration != null && configuration.checkPermission(model)) { |
89 | 0 | removeButton.setEnabled(false); |
90 | |
} |
91 | |
|
92 | |
} |
93 | 0 | row++; |
94 | 0 | } |
95 | |
} |
96 | 0 | } |
97 | |
|
98 | |
private String getVariationName(Data data) { |
99 | 0 | StringBuilder nameBuilder = new StringBuilder(); |
100 | 0 | nameBuilder.append(data.<Object>get(ProgramConstants.LONG_TITLE)); |
101 | 0 | nameBuilder.append(" (").append(data.<Object>get(ProgramConstants.CODE)).append(")"); |
102 | 0 | return nameBuilder.toString(); |
103 | |
} |
104 | |
} |