| 1 | |
package org.kuali.student.lum.program.client.major.edit; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Iterator; |
| 5 | |
import java.util.List; |
| 6 | |
import java.util.Set; |
| 7 | |
import java.util.TreeSet; |
| 8 | |
|
| 9 | |
import org.kuali.student.common.assembly.data.Data; |
| 10 | |
import org.kuali.student.common.assembly.data.Data.Property; |
| 11 | |
import org.kuali.student.common.assembly.data.QueryPath; |
| 12 | |
import org.kuali.student.common.ui.client.application.Application; |
| 13 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
| 14 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; |
| 15 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
| 16 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
| 17 | |
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
| 18 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
| 19 | |
import org.kuali.student.common.ui.client.mvc.View; |
| 20 | |
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
| 21 | |
import org.kuali.student.common.ui.client.service.DataSaveResult; |
| 22 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
| 23 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract; |
| 24 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
| 25 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
| 26 | |
import org.kuali.student.common.ui.shared.IdAttributes; |
| 27 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
| 28 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
| 29 | |
import org.kuali.student.lum.common.client.configuration.LUMViews; |
| 30 | |
import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper; |
| 31 | |
import org.kuali.student.lum.common.client.widgets.AppLocations; |
| 32 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
| 33 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
| 34 | |
import org.kuali.student.lum.program.client.ProgramSections; |
| 35 | |
import org.kuali.student.lum.program.client.ProgramStatus; |
| 36 | |
import org.kuali.student.lum.program.client.ProgramUtils; |
| 37 | |
import org.kuali.student.lum.program.client.events.AddSpecializationEvent; |
| 38 | |
import org.kuali.student.lum.program.client.events.AfterSaveEvent; |
| 39 | |
import org.kuali.student.lum.program.client.events.ChangeViewEvent; |
| 40 | |
import org.kuali.student.lum.program.client.events.MetadataLoadedEvent; |
| 41 | |
import org.kuali.student.lum.program.client.events.ModelLoadedEvent; |
| 42 | |
import org.kuali.student.lum.program.client.events.SpecializationCreatedEvent; |
| 43 | |
import org.kuali.student.lum.program.client.events.SpecializationSaveEvent; |
| 44 | |
import org.kuali.student.lum.program.client.events.SpecializationUpdateEvent; |
| 45 | |
import org.kuali.student.lum.program.client.events.StateChangeEvent; |
| 46 | |
import org.kuali.student.lum.program.client.events.StoreRequirementIDsEvent; |
| 47 | |
import org.kuali.student.lum.program.client.events.UpdateEvent; |
| 48 | |
import org.kuali.student.lum.program.client.major.MajorController; |
| 49 | |
import org.kuali.student.lum.program.client.properties.ProgramProperties; |
| 50 | |
import org.kuali.student.lum.program.client.rpc.AbstractCallback; |
| 51 | |
import org.kuali.student.lum.program.client.widgets.ProgramSideBar; |
| 52 | |
|
| 53 | |
import com.google.gwt.core.client.GWT; |
| 54 | |
import com.google.gwt.event.dom.client.ClickEvent; |
| 55 | |
import com.google.gwt.event.dom.client.ClickHandler; |
| 56 | |
import com.google.gwt.event.shared.HandlerManager; |
| 57 | |
import com.google.gwt.user.client.Window; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | 0 | public class MajorEditController extends MajorController { |
| 63 | |
|
| 64 | 0 | private final KSButton saveButton = new KSButton(ProgramProperties.get().common_save()); |
| 65 | 0 | private final KSButton cancelButton = new KSButton(ProgramProperties.get().common_cancel(), KSButtonAbstract.ButtonStyle.ANCHOR_LARGE_CENTERED); |
| 66 | 0 | private final Set<String> existingVariationIds = new TreeSet<String>(); |
| 67 | |
|
| 68 | |
private ProgramStatus previousState; |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
public MajorEditController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) { |
| 76 | 0 | super(programModel, viewContext, eventBus); |
| 77 | 0 | configurer = GWT.create(MajorEditConfigurer.class); |
| 78 | 0 | sideBar.setState(ProgramSideBar.State.EDIT); |
| 79 | 0 | initHandlers(); |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
@Override |
| 83 | |
protected void configureView() { |
| 84 | 0 | super.configureView(); |
| 85 | 0 | if (!initialized) { |
| 86 | 0 | eventBus.fireEvent(new MetadataLoadedEvent(programModel.getDefinition(), this)); |
| 87 | 0 | List<Enum<?>> excludedViews = new ArrayList<Enum<?>>(); |
| 88 | 0 | excludedViews.add(ProgramSections.PROGRAM_REQUIREMENTS_EDIT); |
| 89 | 0 | excludedViews.add(ProgramSections.SUPPORTING_DOCUMENTS_EDIT); |
| 90 | 0 | excludedViews.add(ProgramSections.SUMMARY); |
| 91 | 0 | addCommonButton(ProgramProperties.get().program_menu_sections(), saveButton, excludedViews); |
| 92 | 0 | addCommonButton(ProgramProperties.get().program_menu_sections(), cancelButton, excludedViews); |
| 93 | 0 | initialized = true; |
| 94 | |
} |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
private void initHandlers() { |
| 98 | 0 | saveButton.addClickHandler(new ClickHandler() { |
| 99 | |
|
| 100 | |
@Override |
| 101 | |
public void onClick(ClickEvent event) { |
| 102 | 0 | doSave(); |
| 103 | 0 | } |
| 104 | |
}); |
| 105 | 0 | cancelButton.addClickHandler(new ClickHandler() { |
| 106 | |
|
| 107 | |
@Override |
| 108 | |
public void onClick(ClickEvent event) { |
| 109 | 0 | doCancel(); |
| 110 | 0 | } |
| 111 | |
}); |
| 112 | 0 | eventBus.addHandler(UpdateEvent.TYPE, new UpdateEvent.Handler() { |
| 113 | |
@Override |
| 114 | |
public void onEvent(UpdateEvent event) { |
| 115 | 0 | Enum<?> view = event.getCurrentView(); |
| 116 | 0 | if (view != null) { |
| 117 | 0 | setCurrentViewEnum(view); |
| 118 | |
} |
| 119 | 0 | doSave(event.getOkCallback()); |
| 120 | |
|
| 121 | 0 | } |
| 122 | |
}); |
| 123 | 0 | eventBus.addHandler(StateChangeEvent.TYPE, new StateChangeEvent.Handler() { |
| 124 | |
@Override |
| 125 | |
public void onEvent(final StateChangeEvent event) { |
| 126 | 0 | programModel.validateNextState(new Callback<List<ValidationResultInfo>>() { |
| 127 | |
@Override |
| 128 | |
public void exec(List<ValidationResultInfo> result) { |
| 129 | 0 | boolean isSectionValid = isValid(result, true); |
| 130 | 0 | if (isSectionValid) { |
| 131 | 0 | Callback<Boolean> callback = new Callback<Boolean>() { |
| 132 | |
@Override |
| 133 | |
public void exec(Boolean result) { |
| 134 | 0 | if (result) { |
| 135 | 0 | reloadMetadata = true; |
| 136 | 0 | loadMetadata(new Callback<Boolean>() { |
| 137 | |
@Override |
| 138 | |
public void exec(Boolean result) { |
| 139 | 0 | if (result) { |
| 140 | 0 | ProgramUtils.syncMetadata(configurer, programModel.getDefinition()); |
| 141 | 0 | HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), context); |
| 142 | |
} |
| 143 | 0 | } |
| 144 | |
}); |
| 145 | |
} |
| 146 | 0 | } |
| 147 | |
}; |
| 148 | 0 | previousState = ProgramStatus.of(programModel); |
| 149 | 0 | ProgramUtils.setStatus(programModel, event.getProgramStatus().getValue()); |
| 150 | 0 | saveData(callback); |
| 151 | 0 | } else { |
| 152 | 0 | KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); |
| 153 | |
} |
| 154 | 0 | } |
| 155 | |
}); |
| 156 | 0 | } |
| 157 | |
}); |
| 158 | |
|
| 159 | 0 | eventBus.addHandler(SpecializationSaveEvent.TYPE, new SpecializationSaveEvent.Handler() { |
| 160 | |
@Override |
| 161 | |
public void onEvent(SpecializationSaveEvent event) { |
| 162 | |
|
| 163 | 0 | Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS); |
| 164 | |
|
| 165 | 0 | existingVariationIds.clear(); |
| 166 | |
|
| 167 | 0 | for (Data.Property prop : currentVariations) { |
| 168 | 0 | String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); |
| 169 | 0 | existingVariationIds.add(existingId); |
| 170 | 0 | } |
| 171 | 0 | String updatedId = event.getData().get(ProgramConstants.ID); |
| 172 | 0 | Integer updatedKey = null; |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | 0 | if (updatedId != null) { |
| 179 | 0 | for (Data.Property prop : currentVariations) { |
| 180 | 0 | String id = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); |
| 181 | 0 | if (updatedId.equals(id)) { |
| 182 | 0 | updatedKey = prop.getKey(); |
| 183 | 0 | Data currentMetaInfo = ((Data) prop.getValue()).get("metaInfo"); |
| 184 | 0 | String latestVersionInd = currentMetaInfo.get("versionInd"); |
| 185 | 0 | Data newMetaInfo = event.getData().get("metaInfo"); |
| 186 | 0 | if (newMetaInfo == null) { |
| 187 | 0 | newMetaInfo = new Data(); |
| 188 | 0 | event.getData().set("metaInfo", newMetaInfo); |
| 189 | |
} |
| 190 | 0 | newMetaInfo.set("versionInd", latestVersionInd); |
| 191 | 0 | break; |
| 192 | |
} |
| 193 | 0 | } |
| 194 | |
|
| 195 | 0 | currentVariations.set(updatedKey, event.getData()); |
| 196 | |
} else { |
| 197 | 0 | currentVariations.add(event.getData()); |
| 198 | |
|
| 199 | |
} |
| 200 | 0 | doSave(); |
| 201 | 0 | } |
| 202 | |
}); |
| 203 | 0 | eventBus.addHandler(AddSpecializationEvent.TYPE, new AddSpecializationEvent.Handler() { |
| 204 | |
@Override |
| 205 | |
public void onEvent(AddSpecializationEvent event) { |
| 206 | 0 | String id = getStringProperty(ProgramConstants.ID); |
| 207 | 0 | ProgramRegistry.setRow((getDataProperty(ProgramConstants.VARIATIONS)).size()); |
| 208 | 0 | ProgramRegistry.setData(ProgramUtils.createNewSpecializationBasedOnMajor(programModel)); |
| 209 | 0 | ViewContext viewContext = new ViewContext(); |
| 210 | 0 | viewContext.setId(id); |
| 211 | 0 | viewContext.setIdType(IdAttributes.IdType.OBJECT_ID); |
| 212 | 0 | HistoryManager.navigate(AppLocations.Locations.EDIT_VARIATION.getLocation(), viewContext); |
| 213 | |
|
| 214 | 0 | } |
| 215 | |
}); |
| 216 | |
|
| 217 | 0 | eventBus.addHandler(StoreRequirementIDsEvent.TYPE, new StoreRequirementIDsEvent.Handler() { |
| 218 | |
@Override |
| 219 | |
public void onEvent(StoreRequirementIDsEvent event) { |
| 220 | 0 | List<String> ids = event.getProgramRequirementIds(); |
| 221 | |
|
| 222 | 0 | programModel.set(QueryPath.parse(ProgramConstants.PROGRAM_REQUIREMENTS), new Data()); |
| 223 | 0 | Data programRequirements = programModel.get(ProgramConstants.PROGRAM_REQUIREMENTS); |
| 224 | |
|
| 225 | 0 | if (programRequirements == null) { |
| 226 | 0 | Window.alert("Cannot find program requirements in data model."); |
| 227 | 0 | GWT.log("Cannot find program requirements in data model", null); |
| 228 | 0 | return; |
| 229 | |
} |
| 230 | |
|
| 231 | 0 | for (String id : ids) { |
| 232 | 0 | programRequirements.add(id); |
| 233 | |
} |
| 234 | 0 | doSave(); |
| 235 | 0 | } |
| 236 | |
}); |
| 237 | 0 | eventBus.addHandler(ChangeViewEvent.TYPE, new ChangeViewEvent.Handler() { |
| 238 | |
@Override |
| 239 | |
public void onEvent(ChangeViewEvent event) { |
| 240 | 0 | showView(event.getViewToken()); |
| 241 | 0 | } |
| 242 | |
}); |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
@Override |
| 246 | |
protected void loadModel(ModelRequestCallback<DataModel> callback) { |
| 247 | 0 | ViewContext viewContext = getViewContext(); |
| 248 | 0 | if (viewContext.getIdType() == IdType.COPY_OF_OBJECT_ID) { |
| 249 | 0 | createNewVersionAndLoadModel(callback, viewContext); |
| 250 | |
} else { |
| 251 | 0 | super.loadModel(callback); |
| 252 | |
} |
| 253 | 0 | } |
| 254 | |
|
| 255 | |
protected void createNewVersionAndLoadModel(final ModelRequestCallback<DataModel> callback, final ViewContext viewContext) { |
| 256 | 0 | Data data = new Data(); |
| 257 | 0 | Data versionData = new Data(); |
| 258 | 0 | versionData.set(new Data.StringKey("versionIndId"), getViewContext().getId()); |
| 259 | 0 | versionData.set(new Data.StringKey("versionComment"), "Major Disicpline Version"); |
| 260 | 0 | data.set(new Data.StringKey("versionInfo"), versionData); |
| 261 | |
|
| 262 | 0 | programRemoteService.saveData(data, new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_retrievingData()) { |
| 263 | |
@Override |
| 264 | |
public void onSuccess(DataSaveResult result) { |
| 265 | 0 | super.onSuccess(result); |
| 266 | 0 | programModel.setRoot(result.getValue()); |
| 267 | 0 | viewContext.setId(ProgramUtils.getProgramId(programModel)); |
| 268 | 0 | viewContext.setIdType(IdType.OBJECT_ID); |
| 269 | 0 | setHeaderTitle(); |
| 270 | 0 | setStatus(); |
| 271 | 0 | callback.onModelReady(programModel); |
| 272 | 0 | eventBus.fireEvent(new ModelLoadedEvent(programModel)); |
| 273 | 0 | } |
| 274 | |
|
| 275 | |
@Override |
| 276 | |
public void onFailure(Throwable caught) { |
| 277 | 0 | super.onFailure(caught); |
| 278 | 0 | callback.onRequestFail(caught); |
| 279 | 0 | } |
| 280 | |
}); |
| 281 | |
|
| 282 | 0 | } |
| 283 | |
|
| 284 | |
private void doSave(final Callback<Boolean> okCallback) { |
| 285 | 0 | requestModel(new ModelRequestCallback<DataModel>() { |
| 286 | |
@Override |
| 287 | |
public void onModelReady(DataModel model) { |
| 288 | 0 | MajorEditController.this.updateModelFromCurrentView(); |
| 289 | 0 | model.validate(new Callback<List<ValidationResultInfo>>() { |
| 290 | |
@Override |
| 291 | |
public void exec(List<ValidationResultInfo> result) { |
| 292 | 0 | boolean isSectionValid = isValid(result, true); |
| 293 | 0 | if (isSectionValid) { |
| 294 | 0 | saveData(okCallback); |
| 295 | |
} else { |
| 296 | 0 | okCallback.exec(false); |
| 297 | 0 | KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000)); |
| 298 | |
} |
| 299 | 0 | } |
| 300 | |
}); |
| 301 | |
|
| 302 | 0 | } |
| 303 | |
|
| 304 | |
@Override |
| 305 | |
public void onRequestFail(Throwable cause) { |
| 306 | 0 | GWT.log("Unable to retrieve model for validation and save", cause); |
| 307 | 0 | } |
| 308 | |
}); |
| 309 | 0 | } |
| 310 | |
|
| 311 | |
private void doCancel() { |
| 312 | 0 | showView(ProgramSections.SUMMARY); |
| 313 | 0 | } |
| 314 | |
|
| 315 | |
@Override |
| 316 | |
protected void doSave() { |
| 317 | 0 | doSave(NO_OP_CALLBACK); |
| 318 | 0 | } |
| 319 | |
|
| 320 | |
private void saveData(final Callback<Boolean> okCallback) { |
| 321 | 0 | programRemoteService.saveData(programModel.getRoot(), new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_savingData()) { |
| 322 | |
@Override |
| 323 | |
public void onSuccess(DataSaveResult result) { |
| 324 | 0 | super.onSuccess(result); |
| 325 | |
|
| 326 | 0 | List<ValidationResultInfo> validationResults = result.getValidationResults(); |
| 327 | 0 | if (validationResults != null && !validationResults.isEmpty()) { |
| 328 | 0 | if (previousState != null) { |
| 329 | 0 | ProgramUtils.setStatus(programModel, previousState.getValue()); |
| 330 | |
} |
| 331 | 0 | ProgramUtils.retrofitValidationResults(validationResults); |
| 332 | 0 | isValid(validationResults, false, true); |
| 333 | 0 | ProgramUtils.handleValidationErrorsForSpecializations(validationResults, programModel); |
| 334 | |
|
| 335 | |
|
| 336 | 0 | Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS); |
| 337 | |
|
| 338 | 0 | existingVariationIds.clear(); |
| 339 | |
|
| 340 | 0 | for (Iterator<Property> iter = currentVariations.iterator();iter.hasNext();) { |
| 341 | 0 | Property prop = iter.next(); |
| 342 | 0 | String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); |
| 343 | 0 | if(existingId==null){ |
| 344 | 0 | iter.remove(); |
| 345 | |
}else{ |
| 346 | 0 | existingVariationIds.add(existingId); |
| 347 | |
} |
| 348 | 0 | } |
| 349 | |
|
| 350 | 0 | okCallback.exec(false); |
| 351 | 0 | } else { |
| 352 | 0 | Data data = result.getValue(); |
| 353 | 0 | if (data != null) { |
| 354 | 0 | programModel.setRoot(result.getValue()); |
| 355 | |
} |
| 356 | 0 | previousState = null; |
| 357 | 0 | setHeaderTitle(); |
| 358 | 0 | setStatus(); |
| 359 | 0 | resetFieldInteractionFlag(); |
| 360 | 0 | configurer.applyPermissions(); |
| 361 | 0 | handleSpecializations(); |
| 362 | 0 | throwAfterSaveEvent(); |
| 363 | 0 | HistoryManager.logHistoryChange(); |
| 364 | 0 | ViewContext viewContext = getViewContext(); |
| 365 | 0 | viewContext.setId(getStringProperty(ProgramConstants.ID)); |
| 366 | 0 | viewContext.setIdType(IdType.OBJECT_ID); |
| 367 | |
|
| 368 | |
|
| 369 | 0 | ViewContext docContext = new ViewContext(); |
| 370 | 0 | docContext.setId(getStringProperty(ProgramConstants.ID)); |
| 371 | 0 | docContext.setIdType(IdType.OBJECT_ID); |
| 372 | 0 | docContext.setAttribute(ProgramConstants.TYPE, ProgramConstants.MAJOR_LU_TYPE_ID + '/' + ProgramSections.PROGRAM_DETAILS_VIEW); |
| 373 | 0 | RecentlyViewedHelper.addDocument(getProgramName(), |
| 374 | |
HistoryManager.appendContext(AppLocations.Locations.VIEW_PROGRAM.getLocation(), docContext)); |
| 375 | 0 | KSNotifier.show(ProgramProperties.get().common_successfulSave()); |
| 376 | 0 | okCallback.exec(true); |
| 377 | 0 | processCurrentView(); |
| 378 | |
} |
| 379 | 0 | } |
| 380 | |
}); |
| 381 | 0 | } |
| 382 | |
|
| 383 | |
private void processCurrentView() { |
| 384 | 0 | Enum<?> currentView = getCurrentViewEnum(); |
| 385 | 0 | if (currentView.name().equals(ProgramSections.VIEW_ALL.name())) { |
| 386 | 0 | HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), getViewContext()); |
| 387 | |
} else { |
| 388 | 0 | showView(currentView); |
| 389 | |
} |
| 390 | 0 | } |
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
private void handleSpecializations() { |
| 396 | 0 | String newVariationId = null; |
| 397 | 0 | Data variations = programModel.get(ProgramConstants.VARIATIONS); |
| 398 | 0 | for (Data.Property prop : variations) { |
| 399 | 0 | String varId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID); |
| 400 | 0 | if (!existingVariationIds.contains(varId)) { |
| 401 | 0 | newVariationId = varId; |
| 402 | 0 | existingVariationIds.add(newVariationId); |
| 403 | 0 | break; |
| 404 | |
} |
| 405 | 0 | } |
| 406 | 0 | if (newVariationId != null) { |
| 407 | 0 | eventBus.fireEvent(new SpecializationCreatedEvent(newVariationId)); |
| 408 | |
} else { |
| 409 | 0 | eventBus.fireEvent(new SpecializationUpdateEvent(variations)); |
| 410 | |
} |
| 411 | 0 | } |
| 412 | |
|
| 413 | |
private void throwAfterSaveEvent() { |
| 414 | 0 | eventBus.fireEvent(new AfterSaveEvent(programModel, this)); |
| 415 | 0 | } |
| 416 | |
|
| 417 | |
@Override |
| 418 | |
public void onModelLoadedEvent() { |
| 419 | 0 | Enum<?> changeSection = ProgramRegistry.getSection(); |
| 420 | 0 | if (changeSection != null) { |
| 421 | 0 | showView(changeSection); |
| 422 | 0 | ProgramRegistry.setSection(null); |
| 423 | |
} else { |
| 424 | 0 | String id = getStringProperty(ProgramConstants.ID); |
| 425 | 0 | if (id == null) { |
| 426 | 0 | showView(ProgramSections.PROGRAM_DETAILS_EDIT); |
| 427 | |
} else { |
| 428 | 0 | showView(ProgramSections.SUMMARY); |
| 429 | |
} |
| 430 | |
} |
| 431 | |
|
| 432 | 0 | } |
| 433 | |
|
| 434 | |
@Override |
| 435 | |
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
| 436 | 0 | if(!initialized){ |
| 437 | 0 | Application.getApplicationContext().clearCrossConstraintMap(null); |
| 438 | 0 | Application.getApplicationContext().clearPathToFieldMapping(null); |
| 439 | |
} |
| 440 | |
|
| 441 | 0 | super.beforeShow(onReadyCallback); |
| 442 | 0 | } |
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
@Override |
| 447 | |
public <V extends Enum<?>> void showView(V viewType, |
| 448 | |
final Callback<Boolean> onReadyCallback) { |
| 449 | 0 | Callback<Boolean> updateCrossConstraintsCallback = new Callback<Boolean>(){ |
| 450 | |
public void exec(Boolean result) { |
| 451 | 0 | onReadyCallback.exec(result); |
| 452 | 0 | for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){ |
| 453 | 0 | crossConstraint.reprocessWithUpdatedConstraints(); |
| 454 | |
} |
| 455 | 0 | } |
| 456 | |
}; |
| 457 | 0 | super.showView(viewType, updateCrossConstraintsCallback); |
| 458 | 0 | } |
| 459 | |
|
| 460 | |
|
| 461 | |
@Override |
| 462 | |
public void beforeViewChange(Enum<?> viewChangingTo, final Callback<Boolean> okToChangeCallback){ |
| 463 | 0 | if(LUMViews.VARIATION_EDIT.equals(viewChangingTo)){ |
| 464 | 0 | getView(ProgramSections.MANAGE_BODIES_EDIT, new Callback<View>(){ |
| 465 | |
@Override |
| 466 | |
public void exec(final View view) { |
| 467 | 0 | if(view!=null && view instanceof SectionView){ |
| 468 | 0 | requestModel(new ModelRequestCallback<DataModel>(){ |
| 469 | |
public void onModelReady(DataModel model) { |
| 470 | 0 | ((SectionView)view).updateWidgetData(model); |
| 471 | 0 | okToChangeCallback.exec(true); |
| 472 | 0 | } |
| 473 | |
public void onRequestFail(Throwable cause) { |
| 474 | 0 | okToChangeCallback.exec(false); |
| 475 | 0 | } |
| 476 | |
}); |
| 477 | |
}else{ |
| 478 | 0 | okToChangeCallback.exec(true); |
| 479 | |
} |
| 480 | 0 | }}); |
| 481 | |
}else{ |
| 482 | 0 | okToChangeCallback.exec(true); |
| 483 | |
} |
| 484 | 0 | } |
| 485 | |
} |