Search in sources :

Example 1 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class FormPanel method addSubForm.

private void addSubForm(FormTree formTree, FormTree.Node node) {
    SubFormReferenceType subFormType = (SubFormReferenceType) node.getType();
    FormTree subTree = formTree.subTree(subFormType.getClassId());
    SubFormKind subFormKind = subTree.getRootFormClass().getSubFormKind();
    if (subFormKind == SubFormKind.REPEATING) {
        RepeatingSubFormPanel subPanel = new RepeatingSubFormPanel(formSource, node, subTree, inputHandler);
        panel.add(subPanel, new CssFloatLayoutContainer.CssFloatData(1));
        repeatingSubForms.add(subPanel);
    } else {
        KeyedSubFormPanel subPanel = new KeyedSubFormPanel(recordRef, formSource, node, subTree, inputHandler);
        panel.add(subPanel, new CssFloatLayoutContainer.CssFloatData(1));
        keyedSubFormPanels.add(subPanel);
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) CssFloatLayoutContainer(com.sencha.gxt.widget.core.client.container.CssFloatLayoutContainer) SubFormKind(org.activityinfo.model.form.SubFormKind) FormTree(org.activityinfo.model.formTree.FormTree)

Example 2 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class FormInputViewModelTest method hiddenSubForm.

/**
 * Test the ViewModel for when the user does not have access to a referenced sub form.
 */
@Test
public void hiddenSubForm() {
    FormClass parentForm = new FormClass(ResourceId.valueOf("PARENT_FORM"));
    parentForm.addField(ResourceId.valueOf("F1")).setLabel("What is your name?").setType(TextType.SIMPLE);
    parentForm.addField(ResourceId.valueOf("F2")).setLabel("What are your secrets?").setType(new SubFormReferenceType(ResourceId.valueOf("SECRET_FORM")));
    FormTreeBuilder treeBuilder = new FormTreeBuilder(new FormMetadataProvider() {

        @Override
        public FormMetadata getFormMetadata(ResourceId formId) {
            if (formId.equals(parentForm.getId())) {
                return FormMetadata.of(1, parentForm, FormPermissions.owner());
            } else {
                return FormMetadata.forbidden(formId);
            }
        }
    });
    FormTree formTree = treeBuilder.queryTree(parentForm.getId());
    FormStore formStore = EasyMock.createMock(FormStore.class);
    EasyMock.replay(formStore);
    FormInputViewModelBuilder viewModelBuilder = new FormInputViewModelBuilder(formStore, formTree, new TestingActivePeriodMemory());
    FormInputViewModel viewModel = viewModelBuilder.build(new FormInputModel(new RecordRef(parentForm.getId(), ResourceId.valueOf("R1"))));
}
Also used : FormMetadataProvider(org.activityinfo.model.formTree.FormMetadataProvider) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormMetadata(org.activityinfo.model.form.FormMetadata) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) FormStore(org.activityinfo.ui.client.store.FormStore) Test(org.junit.Test)

Example 3 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class SubFormPane method addOrUpdateTab.

private void addOrUpdateTab(FormTree formTree, FormTree.Node node) {
    TabItemConfig tabItemConfig = tabs.get(node.getFieldId());
    if (tabItemConfig == null) {
        SubFormReferenceType subFormType = (SubFormReferenceType) node.getType();
        FormClass subForm = formTree.getFormClass(subFormType.getClassId());
        TabItemConfig config = new TabItemConfig(subForm.getLabel());
        tabs.put(node.getFieldId(), config);
        add(new SubFormGrid(viewModel, subForm.getId()), config);
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormClass(org.activityinfo.model.form.FormClass) TabItemConfig(com.sencha.gxt.widget.core.client.TabItemConfig)

Example 4 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class DropPanelDropController method previewDropNewWidget.

private void previewDropNewWidget(final DragContext context) throws VetoDragException {
    final Template template = ((DnDLabel) context.draggable).getTemplate();
    if (template instanceof FieldTemplate) {
        final FormField formField = ((FieldTemplate) template).create();
        vetoDropIfNeeded(context);
        FormClass formClass = formDesigner.getModel().getFormClassByElementId(resourceId);
        formDesigner.getFormFieldWidgetFactory().createWidget(formClass, formField, new FieldUpdater() {

            @Override
            public void onInvalid(String errorMessage) {
            }

            @Override
            public void update(Object value) {
                formDesigner.getSavedGuard().setSaved(false);
            }
        }).then(new Function<FormFieldWidget, Void>() {

            @Nullable
            @Override
            public Void apply(@Nullable FormFieldWidget formFieldWidget) {
                final FieldWidgetContainer fieldWidgetContainer = new FieldWidgetContainer(formDesigner, formFieldWidget, formField, resourceId);
                containerMap.put(formField.getId(), fieldWidgetContainer);
                drop(fieldWidgetContainer, context, formField);
                initFieldProperties(fieldWidgetContainer, formField);
                return null;
            }
        });
    } else if (template instanceof SectionTemplate) {
        final FormSection formSection = ((SectionTemplate) template).create();
        vetoDropIfNeeded(context);
        FieldsHolderWidgetContainer widgetContainer = FieldsHolderWidgetContainer.section(formDesigner, formSection, resourceId);
        // parent drop container
        containerMap.put(resourceId, widgetContainer);
        drop(widgetContainer, context, formSection);
    } else if (template instanceof LabelTemplate) {
        final FormLabel formLabel = ((LabelTemplate) template).create();
        final LabelWidgetContainer fieldWidgetContainer = new LabelWidgetContainer(formDesigner, formLabel, resourceId);
        containerMap.put(formLabel.getId(), fieldWidgetContainer);
        drop(fieldWidgetContainer, context, formLabel);
    } else if (template instanceof SubFormTemplate) {
        final FormField formField = ((SubFormTemplate) template).create();
        vetoDropIfNeeded(context);
        FormClass subForm = formDesigner.getModel().registerNewSubform(formField.getId(), ((SubFormTemplate) template).getKind());
        subForm.setDatabaseId(formDesigner.getRootFormClass().getDatabaseId());
        subForm.setParentFormId(formDesigner.getRootFormClass().getId());
        subForm.setLabel(formField.getLabel());
        SubFormReferenceType type = (SubFormReferenceType) formField.getType();
        type.setClassId(subForm.getId());
        final FieldsHolderWidgetContainer widgetContainer = FieldsHolderWidgetContainer.subform(formDesigner, formField, subForm, formField.getId());
        // parent drop container
        containerMap.put(formField.getId(), widgetContainer);
        drop(widgetContainer.asWidget(), context);
        int widgetIndex = dropTarget.getWidgetIndex(widgetContainer.asWidget());
        formDesigner.getModel().getElementContainer(resourceId).insertElement(widgetIndex, formField);
        formDesigner.getEventBus().fireEvent(new PanelUpdatedEvent(widgetContainer, PanelUpdatedEvent.EventType.ADDED));
        formDesigner.getDragController().makeDraggable(widgetContainer.asWidget(), widgetContainer.getDragHandle());
        removePositioner();
    }
    // forbid drop of source control widget
    throw new VetoDragException();
}
Also used : FieldUpdater(org.activityinfo.ui.client.component.form.field.FieldUpdater) VetoDragException(com.allen_sauer.gwt.dnd.client.VetoDragException) LabelWidgetContainer(org.activityinfo.ui.client.component.formdesigner.container.LabelWidgetContainer) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormFieldWidget(org.activityinfo.ui.client.component.form.field.FormFieldWidget) PanelUpdatedEvent(org.activityinfo.ui.client.component.formdesigner.event.PanelUpdatedEvent) FieldWidgetContainer(org.activityinfo.ui.client.component.formdesigner.container.FieldWidgetContainer) FieldsHolderWidgetContainer(org.activityinfo.ui.client.component.formdesigner.container.FieldsHolderWidgetContainer) Nullable(javax.annotation.Nullable)

Example 5 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class SchemaImporterV3 method getSubFormClass.

private FormClass getSubFormClass(FormClass masterForm, SourceRow row) {
    String subFormName = subForm.get(row);
    if (subFormName == null) {
        return masterForm;
    }
    FormClass subFormClass = subFormMap.get(subFormName);
    if (subFormClass == null) {
        subFormClass = new FormClass(ResourceId.generateId());
        subFormClass.setSubFormKind(parseSubFormKind(subFormType.get(row)));
        subFormClass.setParentFormId(masterForm.getId());
        subFormClass.setLabel(subFormName);
        subFormClass.setDatabaseId(databaseId);
        subFormMap.put(subFormName, subFormClass);
        FormField subFormField = new FormField(ResourceId.generateFieldId(SubFormReferenceType.TYPE_CLASS));
        subFormField.setLabel(subFormName);
        subFormField.setType(new SubFormReferenceType(subFormClass.getId()));
        subFormField.setVisible(true);
        masterForm.addElement(subFormField);
    }
    return subFormClass;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Aggregations

SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)28 FormClass (org.activityinfo.model.form.FormClass)17 FormField (org.activityinfo.model.form.FormField)15 ResourceId (org.activityinfo.model.resource.ResourceId)9 QuantityType (org.activityinfo.model.type.number.QuantityType)5 Test (org.junit.Test)5 EnumType (org.activityinfo.model.type.enumerated.EnumType)4 FormFieldWidget (org.activityinfo.ui.client.component.form.field.FormFieldWidget)4 FormTree (org.activityinfo.model.formTree.FormTree)3 ReferenceType (org.activityinfo.model.type.ReferenceType)3 FormStorage (org.activityinfo.store.spi.FormStorage)3 FieldUpdater (org.activityinfo.ui.client.component.form.field.FieldUpdater)3 FieldWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.FieldWidgetContainer)3 LabelWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.LabelWidgetContainer)3 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 FormClassProvider (org.activityinfo.model.formTree.FormClassProvider)2 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2