Search in sources :

Example 91 with FormField

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

the class SubFormPatch method ensureSubFormHasPeriodField.

private static FormClass ensureSubFormHasPeriodField(FormClass formClass) {
    Optional<FormField> period = formClass.getFieldIfPresent(PERIOD_FIELD_ID);
    if (period.isPresent()) {
        return formClass;
    }
    // Add period field
    FormField periodField = new FormField(ResourceId.valueOf("period"));
    periodField.setLabel(fieldName(formClass.getSubFormKind()));
    periodField.setType(formClass.getSubFormKind().getPeriodType());
    periodField.setKey(true);
    periodField.setRequired(true);
    periodField.setVisible(true);
    formClass.getElements().add(0, periodField);
    return formClass;
}
Also used : FormField(org.activityinfo.model.form.FormField)

Example 92 with FormField

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

the class FormWidgetCreator method createWidgets.

public Promise<Void> createWidgets(final FormClass formClass, final FieldUpdated fieldUpdated) {
    List<Promise<Void>> promises = Lists.newArrayList();
    for (final FormField field : formClass.getFields()) {
        if (field.getType() instanceof SubFormReferenceType) {
            FormClass subForm = model.getSubFormByOwnerFieldId(field.getId());
            if (subForm.getSubFormKind() != SubFormKind.REPEATING) {
                // for repeating we create it internally in sub SimpleFormPanel
                Promise<Void> subFormWidgetsPromise = createWidgets(subForm, fieldUpdated);
                promises.add(subFormWidgetsPromise);
            }
        } else {
            Promise<Void> promise = widgetFactory.createWidget(formClass, field, new FieldUpdater<FieldValue>() {

                @Override
                public void onInvalid(String errorMessage) {
                    containers.get(field.getId()).setInvalid(errorMessage);
                }

                @Override
                public void update(FieldValue value) {
                    containers.get(field.getId()).setValid();
                    fieldUpdated.onFieldUpdated(field, value);
                }
            }).then(new Function<FormFieldWidget, Void>() {

                @Override
                public Void apply(FormFieldWidget widget) {
                    FieldContainer fieldContainer = containerFactory.createContainer(field, widget, 4);
                    containers.put(field.getId(), fieldContainer);
                    model.addContainerOfClass(formClass.getId(), fieldContainer);
                    return null;
                }
            });
            promises.add(promise);
        }
    }
    return Promise.waitAll(promises);
}
Also used : FieldUpdater(org.activityinfo.ui.client.component.form.field.FieldUpdater) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) Promise(org.activityinfo.promise.Promise) FormFieldWidget(org.activityinfo.ui.client.component.form.field.FormFieldWidget) FormClass(org.activityinfo.model.form.FormClass) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField)

Example 93 with FormField

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

the class SimpleFormPanel method validateField.

private boolean validateField(FieldContainer container) {
    FormField field = container.getField();
    FieldValue value = getCurrentValue(field);
    if (value != null && value.getTypeClass() != field.getType().getTypeClass()) {
        value = null;
    }
    if (!container.isInputValid()) {
        return false;
    }
    if (!container.getFieldWidget().isValid()) {
        return false;
    }
    Optional<Boolean> validatedBuiltInDates = validateBuiltinDates(container, field);
    if (validatedBuiltInDates.isPresent()) {
        return validatedBuiltInDates.get();
    }
    if (field.isRequired() && isEmpty(value) && field.isVisible() && !container.getFieldWidget().isReadOnly()) {
        // if field is not visible user doesn't have chance to fix it
        container.setInvalid(I18N.CONSTANTS.requiredFieldMessage());
        return false;
    } else {
        container.setValid();
        return true;
    }
}
Also used : FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField)

Example 94 with FormField

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

the class PartnerTable method getMapping.

private TableMapping getMapping(ResourceId formId) throws SQLException {
    int databaseId = CuidAdapter.getLegacyIdFromCuid(formId);
    TableMappingBuilder mapping = TableMappingBuilder.newMapping(formId, "partner");
    mapping.setFormLabel("Partner");
    mapping.setDatabaseId(CuidAdapter.databaseId(databaseId));
    mapping.setPrimaryKeyMapping(CuidAdapter.PARTNER_DOMAIN, "partnerId");
    mapping.setFromClause("partnerindatabase pd LEFT JOIN partner base ON (pd.partnerId=base.partnerId)");
    mapping.setBaseFilter("pd.databaseId=" + databaseId);
    mapping.setVersion(databaseVersionMap.getSchemaVersion(databaseId));
    // Schema is static
    mapping.setSchemaVersion(1L);
    FormField nameField = new FormField(field(formId, NAME_FIELD)).setRequired(true).setLabel("Name").setCode("label").setKey(true).setType(TextType.SIMPLE);
    mapping.addTextField(nameField, "name");
    FormField fullNameField = new FormField(field(formId, FULL_NAME_FIELD)).setLabel("Full Name").setRequired(false).setType(TextType.SIMPLE);
    mapping.addTextField(fullNameField, "FullName");
    return mapping.build();
}
Also used : TableMappingBuilder(org.activityinfo.store.mysql.mapping.TableMappingBuilder) FormField(org.activityinfo.model.form.FormField)

Example 95 with FormField

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

the class ProjectTable method getMapping.

@Override
public TableMapping getMapping(QueryExecutor executor, ResourceId formId) throws SQLException {
    int databaseId = CuidAdapter.getLegacyIdFromCuid(formId);
    TableMappingBuilder mapping = TableMappingBuilder.newMapping(formId, "partner");
    mapping.setFormLabel("Project");
    mapping.setDatabaseId(CuidAdapter.databaseId(databaseId));
    mapping.setPrimaryKeyMapping(CuidAdapter.PROJECT_DOMAIN, "projectId");
    mapping.setFromClause("project base");
    mapping.setBaseFilter("dateDeleted IS NULL AND databaseId=" + databaseId);
    mapping.setDeleteMethod(DeleteMethod.SOFT_BY_DATE);
    mapping.setVersion(databaseVersionMap.getSchemaVersion(databaseId));
    // Schema is static
    mapping.setSchemaVersion(1L);
    FormField nameField = new FormField(field(formId, NAME_FIELD)).setRequired(true).setLabel("Name").setCode("label").setKey(true).setType(TextType.SIMPLE);
    mapping.addTextField(nameField, "name");
    FormField fullNameField = new FormField(field(formId, FULL_NAME_FIELD)).setLabel("Description").setRequired(false).setType(TextType.SIMPLE);
    mapping.addTextField(fullNameField, "description");
    return mapping.build();
}
Also used : TableMappingBuilder(org.activityinfo.store.mysql.mapping.TableMappingBuilder) FormField(org.activityinfo.model.form.FormField)

Aggregations

FormField (org.activityinfo.model.form.FormField)119 FormClass (org.activityinfo.model.form.FormClass)48 ResourceId (org.activityinfo.model.resource.ResourceId)32 Test (org.junit.Test)30 QuantityType (org.activityinfo.model.type.number.QuantityType)18 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)17 ReferenceType (org.activityinfo.model.type.ReferenceType)16 EnumType (org.activityinfo.model.type.enumerated.EnumType)14 FieldValue (org.activityinfo.model.type.FieldValue)12 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)11 JsonValue (org.activityinfo.json.JsonValue)9 FormTree (org.activityinfo.model.formTree.FormTree)9 FormInstance (org.activityinfo.model.form.FormInstance)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 ColumnSet (org.activityinfo.model.query.ColumnSet)6 QueryModel (org.activityinfo.model.query.QueryModel)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)5 Quantity (org.activityinfo.model.type.number.Quantity)5 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)5 ArrayList (java.util.ArrayList)4