| 1 | |
package org.kuali.student.lum.program.client.variation; |
| 2 | |
|
| 3 | |
import java.util.List; |
| 4 | |
|
| 5 | |
import org.kuali.student.common.assembly.data.Data; |
| 6 | |
import org.kuali.student.common.ui.client.application.Application; |
| 7 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
| 8 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport; |
| 9 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 10 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
| 11 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
| 12 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
| 13 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
| 14 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
| 15 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
| 16 | |
import org.kuali.student.lum.common.client.configuration.Configuration; |
| 17 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
| 18 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
| 19 | |
import org.kuali.student.lum.program.client.ProgramUtils; |
| 20 | |
import org.kuali.student.lum.program.client.events.UpdateEvent; |
| 21 | |
import org.kuali.student.lum.program.client.major.MajorManager; |
| 22 | |
import org.kuali.student.lum.program.client.properties.ProgramProperties; |
| 23 | |
|
| 24 | |
import com.google.gwt.core.client.GWT; |
| 25 | |
import com.google.gwt.event.dom.client.ClickEvent; |
| 26 | |
import com.google.gwt.event.dom.client.ClickHandler; |
| 27 | |
import com.google.gwt.user.client.Window; |
| 28 | |
import com.google.gwt.user.client.ui.Anchor; |
| 29 | |
import com.google.gwt.user.client.ui.FlexTable; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | public class VariationsBinding extends ModelWidgetBindingSupport<FlexTable> { |
| 35 | |
|
| 36 | |
private String url; |
| 37 | |
|
| 38 | |
private boolean editable; |
| 39 | |
|
| 40 | |
private Configuration configuration; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | 0 | private boolean isRightHandColumn = false; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | 0 | public VariationsBinding(String url, boolean editable, boolean isRightHandColumn) { |
| 60 | 0 | this.url = url; |
| 61 | 0 | this.editable = editable; |
| 62 | 0 | this.isRightHandColumn = isRightHandColumn; |
| 63 | 0 | } |
| 64 | |
|
| 65 | 0 | public VariationsBinding(String url, boolean editable) { |
| 66 | 0 | this.url = url; |
| 67 | 0 | this.editable = editable; |
| 68 | 0 | this.isRightHandColumn = false; |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
public VariationsBinding(String url, boolean editable, Configuration configuration) { |
| 72 | 0 | this(url, editable); |
| 73 | 0 | this.configuration = configuration; |
| 74 | 0 | this.isRightHandColumn = false; |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
@Override |
| 78 | |
public void setModelValue(FlexTable table, DataModel model, String path) { |
| 79 | 0 | GWT.log("VariationsBinding.setModelValue...", null); |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
@Override |
| 83 | |
public void setWidgetValue(final FlexTable table, final DataModel model, String path) { |
| 84 | 0 | table.clear(); |
| 85 | 0 | final Data variationMap = model.get(path); |
| 86 | 0 | if (variationMap != null) { |
| 87 | 0 | int row = 0; |
| 88 | 0 | for (final Data.Property property : variationMap) { |
| 89 | 0 | final Data variationData = property.getValue(); |
| 90 | 0 | final int currentRow = row; |
| 91 | |
|
| 92 | |
|
| 93 | 0 | if (isRightHandColumn == true){ |
| 94 | 0 | KSLabel label = new KSLabel(getVariationName(variationData)); |
| 95 | 0 | table.setWidget(row, 0, label ); |
| 96 | 0 | } |
| 97 | |
else { |
| 98 | |
|
| 99 | 0 | Anchor anchor = new Anchor(getVariationName(variationData)); |
| 100 | 0 | anchor.addClickHandler(new ClickHandler() { |
| 101 | |
@Override |
| 102 | |
public void onClick(ClickEvent event) { |
| 103 | 0 | ProgramRegistry.setData(variationData); |
| 104 | 0 | ProgramRegistry.setRow(currentRow); |
| 105 | 0 | ProgramUtils.addCredentialProgramDataToVariation(variationData, model); |
| 106 | 0 | String id = (String) model.get("id"); |
| 107 | 0 | ViewContext viewContext = new ViewContext(); |
| 108 | 0 | viewContext.setId(id); |
| 109 | 0 | viewContext.setIdType(IdType.OBJECT_ID); |
| 110 | 0 | if(model.get("proposal/id") != null){ |
| 111 | |
|
| 112 | 0 | variationData.set("isProposal", true); |
| 113 | |
} |
| 114 | 0 | if(variationData.get("id")!=null){ |
| 115 | 0 | viewContext.setAttribute(ProgramConstants.VARIATION_ID, variationData.get("id").toString()); |
| 116 | |
} |
| 117 | 0 | HistoryManager.navigate(url, viewContext); |
| 118 | 0 | } |
| 119 | |
}); |
| 120 | |
|
| 121 | 0 | table.setWidget(row, 0, anchor); |
| 122 | |
} |
| 123 | 0 | if (editable) { |
| 124 | 0 | KSButton removeButton = new KSButton(ProgramProperties.get().common_remove()); |
| 125 | 0 | table.setWidget(row, 1, removeButton); |
| 126 | 0 | removeButton.addClickHandler(new ClickHandler() { |
| 127 | |
|
| 128 | |
@Override |
| 129 | |
public void onClick(ClickEvent event) { |
| 130 | 0 | if (Window.confirm("Are you sure you want to delete specialization?")) { |
| 131 | 0 | variationMap.remove(new Data.IntegerKey(currentRow)); |
| 132 | 0 | MajorManager.getEventBus().fireEvent(new UpdateEvent()); |
| 133 | |
} |
| 134 | 0 | } |
| 135 | |
}); |
| 136 | 0 | if (configuration != null && configuration.checkPermission(model)) { |
| 137 | 0 | removeButton.setEnabled(false); |
| 138 | |
} |
| 139 | |
|
| 140 | |
} |
| 141 | |
|
| 142 | |
|
| 143 | 0 | if (hasWarnings(currentRow)){ |
| 144 | 0 | table.getRowFormatter().addStyleName(row, "warning"); |
| 145 | 0 | SpanPanel warning = new SpanPanel(); |
| 146 | 0 | warning.setHTML("<b> Warning </b> <br/>" + |
| 147 | |
Application.getApplicationContext().getMessage("validation", "validation.variation")); |
| 148 | 0 | table.setWidget(row, 2, warning); |
| 149 | 0 | } else { |
| 150 | 0 | table.getRowFormatter().removeStyleName(row, "warning"); |
| 151 | 0 | table.setWidget(row, 2, new KSLabel("")); |
| 152 | |
} |
| 153 | |
|
| 154 | 0 | row++; |
| 155 | 0 | } |
| 156 | |
} |
| 157 | 0 | } |
| 158 | |
|
| 159 | |
private String getVariationName(Data data) { |
| 160 | 0 | StringBuilder nameBuilder = new StringBuilder(); |
| 161 | 0 | nameBuilder.append(data.<Object>get(ProgramConstants.LONG_TITLE)); |
| 162 | 0 | nameBuilder.append(" (").append(data.<Object>get(ProgramConstants.CODE)).append(")"); |
| 163 | 0 | return nameBuilder.toString(); |
| 164 | |
} |
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
private boolean hasWarnings(int variationIndex){ |
| 174 | 0 | List<ValidationResultInfo> validationWarnings = Application.getApplicationContext().getValidationWarnings(); |
| 175 | 0 | for (ValidationResultInfo vr:validationWarnings){ |
| 176 | 0 | if (vr.getElement().contains(ProgramConstants.VARIATIONS + "/" + variationIndex)){ |
| 177 | 0 | return true; |
| 178 | |
} |
| 179 | |
} |
| 180 | 0 | return false; |
| 181 | |
} |
| 182 | |
} |