Search in sources :

Example 6 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class SimpleFormPanel method onFieldUpdated.

public void onFieldUpdated(FormField field, FieldValue newValue) {
    Optional<FormInstance> workingInstance = model.getWorkingInstance(field.getId(), getSelectedKey(field));
    if (workingInstance.isPresent()) {
        if (!Objects.equals(workingInstance.get().get(field.getId()), newValue)) {
            workingInstance.get().set(field.getId(), newValue);
            // skip handler must be applied after workingInstance is updated
            relevanceHandler.onValueChange();
        }
        validateField(widgetCreator.get(field.getId()));
        model.getChangedInstances().add(workingInstance.get());
    } else {
        FormClass formClass = model.getClassByField(field.getId());
        if (formClass.isSubForm()) {
            widgetCreator.get(field.getId()).setInvalid(I18N.CONSTANTS.subFormTabNotSelected());
            widgetCreator.get(field.getId()).getFieldWidget().clearValue();
        }
    }
}
Also used : FormClass(org.activityinfo.model.form.FormClass) FormInstance(org.activityinfo.model.form.FormInstance)

Example 7 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class FormModel method getWorkingInstance.

public Optional<FormInstance> getWorkingInstance(ResourceId formFieldId, String keyId) {
    FormClass classByField = getClassByField(formFieldId);
    if (classByField.equals(rootFormClass)) {
        return Optional.of(getWorkingRootInstance());
    }
    if (classByField.isSubForm()) {
        Optional<FormInstance> valueInstance = getSubformValueInstance(classByField, getWorkingRootInstance(), keyId);
        if (valueInstance.isPresent()) {
            return valueInstance;
        } else {
            FormInstance newInstance = new FormInstance(ResourceId.generatedPeriodSubmissionId(getWorkingRootInstance().getId(), keyId), classByField.getId());
            newInstance.setParentRecordId(getWorkingRootInstance().getId());
            SubformValueKey valueKey = new SubformValueKey(classByField, getWorkingRootInstance());
            Set<FormInstance> allInstances = subFormInstances.get(valueKey);
            if (allInstances == null) {
                allInstances = Sets.newHashSet();
                subFormInstances.put(valueKey, allInstances);
            }
            allInstances.add(newInstance);
            return Optional.of(newInstance);
        }
    }
    throw new RuntimeException("Failed to identify working instance for field: " + formFieldId + ", keyId: " + keyId);
}
Also used : FormClass(org.activityinfo.model.form.FormClass) FormInstance(org.activityinfo.model.form.FormInstance)

Example 8 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class FormModel method getClassByField.

public FormClass getClassByField(ResourceId formFieldId) {
    FormClass formClass = formFieldToFormClass.get(formFieldId);
    Preconditions.checkNotNull(formClass, "Unknown field, id:" + formFieldId);
    return formClass;
}
Also used : FormClass(org.activityinfo.model.form.FormClass)

Example 9 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class FormDesignerActions method getFormClassesForPersistence.

private List<FormClass> getFormClassesForPersistence() {
    List<FormClass> classesToPersist = Lists.newArrayList();
    for (FormClass subForm : formDesigner.getModel().getSubforms()) {
        classesToPersist.add(subForm);
    }
    // order is important, subform classes must be saved first
    classesToPersist.add(formDesigner.getRootFormClass());
    return classesToPersist;
}
Also used : FormClass(org.activityinfo.model.form.FormClass)

Example 10 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class RelevancePanelPresenter method fieldList.

private List<FormField> fieldList(FieldWidgetContainer container) {
    ResourceId thisFieldId = container.getFormField().getId();
    FormClass formClass = container.getFormDesigner().getModel().getFormClassByElementId(thisFieldId);
    List<FormField> formFields = new ArrayList<>();
    for (FormField formField : formClass.getFields()) {
        if (!formField.getId().equals(thisFieldId)) {
            formFields.add(formField);
        }
    }
    return formFields;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) ArrayList(java.util.ArrayList) FormField(org.activityinfo.model.form.FormField)

Aggregations

FormClass (org.activityinfo.model.form.FormClass)109 FormField (org.activityinfo.model.form.FormField)49 ResourceId (org.activityinfo.model.resource.ResourceId)41 Test (org.junit.Test)38 QuantityType (org.activityinfo.model.type.number.QuantityType)20 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)19 FormInstance (org.activityinfo.model.form.FormInstance)14 EnumType (org.activityinfo.model.type.enumerated.EnumType)12 JsonValue (org.activityinfo.json.JsonValue)11 FormTree (org.activityinfo.model.formTree.FormTree)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 ColumnSet (org.activityinfo.model.query.ColumnSet)8 QueryModel (org.activityinfo.model.query.QueryModel)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 FieldValue (org.activityinfo.model.type.FieldValue)7 Quantity (org.activityinfo.model.type.number.Quantity)7 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)6 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)6 ColumnView (org.activityinfo.model.query.ColumnView)5