use of org.activityinfo.ui.client.input.viewModel.FormInputViewModel in project activityinfo by bedatadriven.
the class RepeatingSubFormPanel method updateView.
public void updateView(SubFormViewModel viewModel) {
this.viewModel = viewModel;
// First add any records which are not yet present.
for (FormInputViewModel subRecord : viewModel.getSubRecords()) {
FormPanel subPanel = panelMap.get(subRecord.getRecordRef());
if (subPanel == null) {
subPanel = new FormPanel(formSource, subTree, subRecord.getRecordRef(), inputHandler);
subPanel.init(subRecord);
recordContainer.add(subPanel, new CssFloatLayoutContainer.CssFloatData(1));
panelMap.put(subRecord.getRecordRef(), subPanel);
}
subPanel.updateView(subRecord);
}
// Now remove any that have been deleted
for (FormPanel formPanel : panelMap.values()) {
if (!viewModel.getSubRecordRefs().contains(formPanel.getRecordRef())) {
recordContainer.remove(formPanel);
}
}
}
use of org.activityinfo.ui.client.input.viewModel.FormInputViewModel in project activityinfo by bedatadriven.
the class RepeatingSubFormPanel method addRecordHandler.
private void addRecordHandler(SelectEvent event) {
// If we have a placeholder, then add it first, otherwise it will
// disappear
Optional<FormInputViewModel> placeholder = viewModel.getPlaceholder();
if (placeholder.isPresent()) {
inputHandler.addSubRecord(placeholder.get().getRecordRef());
}
// Add a new sub record with unique ID
ResourceId subFormId = subTree.getRootFormId();
ResourceId newSubRecordId = ResourceId.generateId();
inputHandler.addSubRecord(new RecordRef(subFormId, newSubRecordId));
}
Aggregations