Search in sources :

Example 1 with FormInputViewModel

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);
        }
    }
}
Also used : CssFloatLayoutContainer(com.sencha.gxt.widget.core.client.container.CssFloatLayoutContainer) FormInputViewModel(org.activityinfo.ui.client.input.viewModel.FormInputViewModel)

Example 2 with FormInputViewModel

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));
}
Also used : FormInputViewModel(org.activityinfo.ui.client.input.viewModel.FormInputViewModel) ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef)

Aggregations

FormInputViewModel (org.activityinfo.ui.client.input.viewModel.FormInputViewModel)2 CssFloatLayoutContainer (com.sencha.gxt.widget.core.client.container.CssFloatLayoutContainer)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 RecordRef (org.activityinfo.model.type.RecordRef)1