| 1 | |
package org.kuali.student.lum.program.client.major.view; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
import org.kuali.student.common.assembly.data.Data; |
| 6 | |
import org.kuali.student.common.assembly.data.Data.Property; |
| 7 | |
import org.kuali.student.common.ui.client.application.Application; |
| 8 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
| 9 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
| 10 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 11 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
| 12 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
| 13 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
| 14 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
| 15 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
| 16 | |
import org.kuali.student.common.ui.client.widgets.KSRadioButton; |
| 17 | |
import org.kuali.student.common.ui.shared.IdAttributes; |
| 18 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
| 19 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
| 20 | |
import org.kuali.student.lum.common.client.widgets.DropdownList; |
| 21 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
| 22 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
| 23 | |
import org.kuali.student.lum.program.client.ProgramSections; |
| 24 | |
import org.kuali.student.lum.program.client.ProgramStatus; |
| 25 | |
import org.kuali.student.lum.program.client.events.ModelLoadedEvent; |
| 26 | |
import org.kuali.student.lum.program.client.events.ProgramViewEvent; |
| 27 | |
import org.kuali.student.lum.program.client.major.ActionType; |
| 28 | |
import org.kuali.student.lum.program.client.major.MajorController; |
| 29 | |
|
| 30 | |
import com.google.gwt.core.client.GWT; |
| 31 | |
import com.google.gwt.event.dom.client.ChangeEvent; |
| 32 | |
import com.google.gwt.event.dom.client.ChangeHandler; |
| 33 | |
import com.google.gwt.event.dom.client.ClickEvent; |
| 34 | |
import com.google.gwt.event.dom.client.ClickHandler; |
| 35 | |
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
| 36 | |
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
| 37 | |
import com.google.gwt.event.shared.HandlerManager; |
| 38 | |
import com.google.gwt.user.client.ui.Anchor; |
| 39 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
| 40 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
| 41 | |
|
| 42 | |
|
| 43 | 0 | public class MajorViewController extends MajorController { |
| 44 | |
|
| 45 | |
|
| 46 | |
private static final String MSG_GROUP = "program"; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | 0 | private final DropdownList actionBox = new DropdownList(ActionType.getValuesForMajorDiscipline(false)); |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
private boolean isCurrentVersion; |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public MajorViewController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) { |
| 66 | 0 | super(programModel, viewContext, eventBus); |
| 67 | 0 | configurer = GWT.create(MajorViewConfigurer.class); |
| 68 | |
|
| 69 | |
|
| 70 | 0 | initHandlers(); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
private void initHandlers() { |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | 0 | actionBox.addChangeHandler(new ChangeHandler() { |
| 79 | |
@Override |
| 80 | |
public void onChange(ChangeEvent event) { |
| 81 | |
|
| 82 | |
|
| 83 | 0 | ActionType actionType = ActionType.of(actionBox.getSelectedValue()); |
| 84 | 0 | ViewContext viewContext = getViewContext(); |
| 85 | |
|
| 86 | |
|
| 87 | 0 | if (actionType == ActionType.MODIFY) { |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | 0 | buildModifyDialog(viewContext,"/HOME/CURRICULUM_HOME/COURSE_PROPOSAL",programModel); |
| 92 | |
} |
| 93 | |
|
| 94 | 0 | else if (actionType == ActionType.RETIRE) { |
| 95 | |
|
| 96 | |
} |
| 97 | 0 | } |
| 98 | |
}); |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | 0 | eventBus.addHandler(ProgramViewEvent.TYPE, new ProgramViewEvent.Handler() { |
| 103 | |
@Override |
| 104 | |
public void onEvent(ProgramViewEvent event) { |
| 105 | 0 | actionBox.setSelectedIndex(0); |
| 106 | 0 | } |
| 107 | |
}); |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | 0 | eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() { |
| 113 | |
@Override |
| 114 | |
public void onEvent(ModelLoadedEvent event) { |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | 0 | resetActionList(); |
| 121 | |
|
| 122 | 0 | String type = context.getAttributes().get(ProgramConstants.TYPE); |
| 123 | 0 | if (type != null) { |
| 124 | 0 | context.getAttributes().remove(ProgramConstants.TYPE); |
| 125 | 0 | if (type.equals(ProgramConstants.VARIATION_TYPE_KEY)) { |
| 126 | 0 | showVariationView(); |
| 127 | |
} else { |
| 128 | |
|
| 129 | 0 | context.getAttributes().remove(ProgramConstants.VARIATION_ID); |
| 130 | 0 | showView(ProgramSections.VIEW_ALL); |
| 131 | |
} |
| 132 | |
} else { |
| 133 | 0 | context.getAttributes().remove(ProgramConstants.VARIATION_ID); |
| 134 | 0 | showView(ProgramSections.VIEW_ALL); |
| 135 | |
} |
| 136 | 0 | } |
| 137 | |
}); |
| 138 | 0 | } |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
private void buildModifyDialog(final ViewContext viewContext, final String modifyPath, final DataModel model){ |
| 148 | 0 | final KSLightBox modifyDialog = new KSLightBox(); |
| 149 | |
|
| 150 | |
|
| 151 | 0 | modifyDialog.setTitle((getMessage("modifyProgramSubTitle"))); |
| 152 | |
|
| 153 | 0 | final VerticalPanel layout = new VerticalPanel(); |
| 154 | 0 | layout.addStyleName("ks-form-module-fields"); |
| 155 | |
|
| 156 | 0 | final KSButton continueButton = new KSButton(getMessage("continue")); |
| 157 | |
|
| 158 | 0 | modifyDialog.addButton(continueButton); |
| 159 | 0 | Anchor cancelLink = new Anchor("Cancel"); |
| 160 | |
|
| 161 | |
|
| 162 | 0 | cancelLink.addClickHandler(new ClickHandler(){ |
| 163 | |
public void onClick(ClickEvent event) { |
| 164 | 0 | modifyDialog.hide(); |
| 165 | 0 | } |
| 166 | |
}); |
| 167 | 0 | modifyDialog.addButton(cancelLink); |
| 168 | |
|
| 169 | 0 | HorizontalPanel titlePanel = new HorizontalPanel(); |
| 170 | 0 | KSLabel titleLabel = new KSLabel(getMessage("modifyProgramSubTitle")); |
| 171 | 0 | titleLabel.addStyleName("bold"); |
| 172 | 0 | titlePanel.add(titleLabel); |
| 173 | |
|
| 174 | 0 | layout.add(titlePanel); |
| 175 | |
|
| 176 | 0 | final KSRadioButton radioOptionModifyNoVersion = new KSRadioButton("modifyCreditProgramButtonGroup", getMessage("modifyProgramNoVersion")); |
| 177 | 0 | final KSRadioButton radioOptionModifyWithVersion = new KSRadioButton("modifyCreditProgramButtonGroup", getMessage("modifyProgramWithVersion")); |
| 178 | 0 | final KSCheckBox curriculumReviewOption = new KSCheckBox(getMessage("useCurriculumReview")); |
| 179 | |
|
| 180 | |
|
| 181 | 0 | radioOptionModifyNoVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ |
| 182 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
| 183 | 0 | if(event.getValue()){ |
| 184 | 0 | curriculumReviewOption.setEnabled(false); |
| 185 | 0 | curriculumReviewOption.setValue(false); |
| 186 | |
} |
| 187 | 0 | } |
| 188 | |
}); |
| 189 | 0 | radioOptionModifyNoVersion.setValue(true); |
| 190 | |
|
| 191 | |
|
| 192 | 0 | curriculumReviewOption.setEnabled(false); |
| 193 | |
|
| 194 | 0 | radioOptionModifyWithVersion.addValueChangeHandler(new ValueChangeHandler<Boolean>(){ |
| 195 | |
public void onValueChange(ValueChangeEvent<Boolean> event) { |
| 196 | 0 | if(event.getValue()){ |
| 197 | 0 | curriculumReviewOption.setEnabled(true); |
| 198 | |
} |
| 199 | 0 | } |
| 200 | |
}); |
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | 0 | continueButton.addClickHandler(new ClickHandler(){ |
| 206 | |
@Override |
| 207 | |
public void onClick(ClickEvent event) { |
| 208 | 0 | if (radioOptionModifyNoVersion.getValue()){ |
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | 0 | ProgramRegistry.setSection(ProgramSections.getEditSection(getCurrentViewEnum())); |
| 213 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext); |
| 214 | 0 | } else if (radioOptionModifyWithVersion.getValue() && curriculumReviewOption.getValue()){ |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | 0 | final ViewContext viewContext = new ViewContext(); |
| 226 | 0 | viewContext.setId(versionIndId); |
| 227 | 0 | viewContext.setIdType(IdAttributes.IdType.COPY_OF_OBJECT_ID); |
| 228 | 0 | Application.navigate(AppLocations.Locations.PROGRAM_PROPOSAL.getLocation(), viewContext); |
| 229 | |
|
| 230 | 0 | } else if (radioOptionModifyWithVersion.getValue()){ |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
| 242 | 0 | viewContext.setId(versionIndId); |
| 243 | 0 | viewContext.setIdType(IdType.COPY_OF_OBJECT_ID); |
| 244 | |
|
| 245 | |
|
| 246 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_PROGRAM.getLocation(), viewContext); |
| 247 | |
} |
| 248 | |
|
| 249 | |
|
| 250 | 0 | modifyDialog.hide(); |
| 251 | 0 | } |
| 252 | |
}); |
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | 0 | layout.add(radioOptionModifyNoVersion); |
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | 0 | if(isCurrentVersion){ |
| 263 | 0 | layout.add(radioOptionModifyWithVersion); |
| 264 | 0 | layout.add(curriculumReviewOption); |
| 265 | |
} |
| 266 | |
|
| 267 | 0 | modifyDialog.setWidget(layout); |
| 268 | 0 | modifyDialog.show(); |
| 269 | 0 | } |
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
public String getMessage(String programMessageKey) { |
| 280 | 0 | String msg = Application.getApplicationContext().getMessage(MSG_GROUP, programMessageKey); |
| 281 | 0 | if (msg == null) { |
| 282 | 0 | msg = programMessageKey; |
| 283 | |
} |
| 284 | 0 | return msg; |
| 285 | |
} |
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
protected void resetActionList() { |
| 293 | |
|
| 294 | |
|
| 295 | 0 | ProgramStatus status = ProgramStatus.of(programModel); |
| 296 | |
|
| 297 | |
|
| 298 | 0 | String versionIndId = getStringProperty(ProgramConstants.VERSION_IND_ID); |
| 299 | |
|
| 300 | |
|
| 301 | 0 | Long sequenceNumber = programModel.get(ProgramConstants.VERSION_SEQUENCE_NUMBER); |
| 302 | |
|
| 303 | |
|
| 304 | 0 | actionBox.clear(); |
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | 0 | programRemoteService.isLatestVersion(versionIndId, sequenceNumber, new KSAsyncCallback<Boolean>(){ |
| 309 | |
public void onSuccess(Boolean isLatest) { |
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | 0 | isCurrentVersion = isLatest; |
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | 0 | actionBox.setList(ActionType.getValuesForMajorDiscipline(isLatest)); |
| 319 | 0 | } |
| 320 | |
}); |
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | 0 | String referenceId = programModel.getRoot().get("id"); |
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | 0 | programRemoteService.isProposal( "kuali.proposal.referenceType.clu", referenceId, new KSAsyncCallback<Boolean>(){ |
| 333 | |
public void onSuccess(Boolean isProposal) { |
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | 0 | if (isProposal){ |
| 338 | 0 | actionBox.setVisible(false); |
| 339 | |
} |
| 340 | |
|
| 341 | 0 | } |
| 342 | |
}); |
| 343 | 0 | } |
| 344 | |
|
| 345 | |
private void showVariationView() { |
| 346 | 0 | String variationId = context.getAttributes().get(ProgramConstants.VARIATION_ID); |
| 347 | 0 | if (variationId != null) { |
| 348 | 0 | final Data variationMap = getDataProperty(ProgramConstants.VARIATIONS); |
| 349 | 0 | if (variationMap != null) { |
| 350 | 0 | int row = 0; |
| 351 | 0 | for (Property p : variationMap) { |
| 352 | 0 | final Data variationData = p.getValue(); |
| 353 | 0 | if (variationData != null) { |
| 354 | 0 | if (variationData.get(ProgramConstants.ID).equals(variationId)) { |
| 355 | |
|
| 356 | |
|
| 357 | 0 | Data credData = getDataProperty(ProgramConstants.CREDENTIAL_PROGRAM); |
| 358 | 0 | variationData.set(ProgramConstants.CREDENTIAL_PROGRAM, credData); |
| 359 | 0 | ProgramRegistry.setData(variationData); |
| 360 | 0 | ProgramRegistry.setRow(row); |
| 361 | |
} |
| 362 | 0 | row++; |
| 363 | |
} |
| 364 | 0 | } |
| 365 | 0 | HistoryManager.navigate(AppLocations.Locations.VIEW_VARIATION.getLocation(), context); |
| 366 | |
} |
| 367 | |
} |
| 368 | 0 | } |
| 369 | |
|
| 370 | |
@Override |
| 371 | |
protected void configureView() { |
| 372 | 0 | super.configureView(); |
| 373 | 0 | addContentWidget(actionBox); |
| 374 | 0 | initialized = true; |
| 375 | 0 | } |
| 376 | |
} |