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);
}
}
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"))));
}
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);
}
}
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();
}
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;
}
Aggregations