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