use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class SimpleFormPanel method onFieldUpdated.
public void onFieldUpdated(FormField field, FieldValue newValue) {
Optional<FormInstance> workingInstance = model.getWorkingInstance(field.getId(), getSelectedKey(field));
if (workingInstance.isPresent()) {
if (!Objects.equals(workingInstance.get().get(field.getId()), newValue)) {
workingInstance.get().set(field.getId(), newValue);
// skip handler must be applied after workingInstance is updated
relevanceHandler.onValueChange();
}
validateField(widgetCreator.get(field.getId()));
model.getChangedInstances().add(workingInstance.get());
} else {
FormClass formClass = model.getClassByField(field.getId());
if (formClass.isSubForm()) {
widgetCreator.get(field.getId()).setInvalid(I18N.CONSTANTS.subFormTabNotSelected());
widgetCreator.get(field.getId()).getFieldWidget().clearValue();
}
}
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormModel method getWorkingInstance.
public Optional<FormInstance> getWorkingInstance(ResourceId formFieldId, String keyId) {
FormClass classByField = getClassByField(formFieldId);
if (classByField.equals(rootFormClass)) {
return Optional.of(getWorkingRootInstance());
}
if (classByField.isSubForm()) {
Optional<FormInstance> valueInstance = getSubformValueInstance(classByField, getWorkingRootInstance(), keyId);
if (valueInstance.isPresent()) {
return valueInstance;
} else {
FormInstance newInstance = new FormInstance(ResourceId.generatedPeriodSubmissionId(getWorkingRootInstance().getId(), keyId), classByField.getId());
newInstance.setParentRecordId(getWorkingRootInstance().getId());
SubformValueKey valueKey = new SubformValueKey(classByField, getWorkingRootInstance());
Set<FormInstance> allInstances = subFormInstances.get(valueKey);
if (allInstances == null) {
allInstances = Sets.newHashSet();
subFormInstances.put(valueKey, allInstances);
}
allInstances.add(newInstance);
return Optional.of(newInstance);
}
}
throw new RuntimeException("Failed to identify working instance for field: " + formFieldId + ", keyId: " + keyId);
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormModel method getClassByField.
public FormClass getClassByField(ResourceId formFieldId) {
FormClass formClass = formFieldToFormClass.get(formFieldId);
Preconditions.checkNotNull(formClass, "Unknown field, id:" + formFieldId);
return formClass;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormDesignerActions method getFormClassesForPersistence.
private List<FormClass> getFormClassesForPersistence() {
List<FormClass> classesToPersist = Lists.newArrayList();
for (FormClass subForm : formDesigner.getModel().getSubforms()) {
classesToPersist.add(subForm);
}
// order is important, subform classes must be saved first
classesToPersist.add(formDesigner.getRootFormClass());
return classesToPersist;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class RelevancePanelPresenter method fieldList.
private List<FormField> fieldList(FieldWidgetContainer container) {
ResourceId thisFieldId = container.getFormField().getId();
FormClass formClass = container.getFormDesigner().getModel().getFormClassByElementId(thisFieldId);
List<FormField> formFields = new ArrayList<>();
for (FormField formField : formClass.getFields()) {
if (!formField.getId().equals(thisFieldId)) {
formFields.add(formField);
}
}
return formFields;
}
Aggregations