Search in sources :

Example 96 with FormClass

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

the class BatchingFormTreeBuilder method fetchFormClasses.

private List<FormClass> fetchFormClasses(Iterable<ResourceId> formIds) {
    List<FormClass> fetched = new ArrayList<>();
    // Identify the forms that we don't already have in the cache
    Set<ResourceId> toFetch = new HashSet<>();
    for (ResourceId formClassId : formIds) {
        if (!formCache.containsKey(formClassId)) {
            toFetch.add(formClassId);
        }
    }
    // Fetch from the store
    Map<ResourceId, FormClass> formClasses = catalog.getFormClasses(toFetch);
    // Store back to the cache
    for (FormClass formClass : formClasses.values()) {
        formCache.put(formClass.getId(), formClass);
        fetched.add(formClass);
    }
    return fetched;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass)

Example 97 with FormClass

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

the class FormForest method getReferencedForms.

public List<FormClass> getReferencedForms() {
    Set<ResourceId> visited = new HashSet<>();
    List<FormClass> list = new ArrayList<>();
    // Depth-first search for natural ordering
    for (FormTree formTree : trees.values()) {
        collectReferenced(formTree, formTree.getRootFields(), visited, list);
    }
    return list;
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass)

Example 98 with FormClass

use of org.activityinfo.model.form.FormClass 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 99 with FormClass

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

the class SimpleFormPanel method getSelectedKey.

/**
 * Returns selected key/tab for given field or otherwise null if nothing is selected or it is root instance (no key).
 *
 * @return selected key/tab for given field or otherwise null if nothing is selected or it is root instance (no key).
 */
public String getSelectedKey(FormField field) {
    FormClass formClass = model.getClassByField(field.getId());
    if (formClass.isSubForm()) {
        SubFormPanel subformPanel = widgetCreator.getSubformPanel(formClass);
        if (subformPanel instanceof PeriodSubFormPanel) {
            PeriodSubFormPanel periodSubFormPanel = (PeriodSubFormPanel) subformPanel;
            Tab selectedTab = periodSubFormPanel.getSelectedTab();
            if (selectedTab != null) {
                return selectedTab.getId();
            }
        }
    }
    return null;
}
Also used : PeriodSubFormPanel(org.activityinfo.ui.client.component.form.subform.PeriodSubFormPanel) RepeatingSubFormPanel(org.activityinfo.ui.client.component.form.subform.RepeatingSubFormPanel) SubFormPanel(org.activityinfo.ui.client.component.form.subform.SubFormPanel) Tab(org.activityinfo.ui.client.component.form.subform.Tab) FormClass(org.activityinfo.model.form.FormClass) PeriodSubFormPanel(org.activityinfo.ui.client.component.form.subform.PeriodSubFormPanel)

Example 100 with FormClass

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

the class SimpleFormPanel method validateBuiltinDates.

private Optional<Boolean> validateBuiltinDates(FieldContainer container, FormField field) {
    if (BuiltinFields.isBuiltInDate(field.getId())) {
        FormClass rootFormClass = getModel().getRootFormClass();
        DateRange dateRange = BuiltinFields.getDateRange(getModel().getWorkingRootInstance(), rootFormClass);
        if (!dateRange.isValidWithNull()) {
            container.setInvalid(I18N.CONSTANTS.inconsistentDateRangeWarning());
            return Optional.of(false);
        } else {
            if (dateRange.isValid()) {
                getWidgetCreator().get(BuiltinFields.getStartDateField(rootFormClass).getId()).setValid();
                getWidgetCreator().get(BuiltinFields.getEndDateField(rootFormClass).getId()).setValid();
                return Optional.of(true);
            }
        }
    }
    return Optional.absent();
}
Also used : DateRange(org.activityinfo.model.date.DateRange) FormClass(org.activityinfo.model.form.FormClass)

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