use of com.qcadoo.view.internal.components.form.FormComponentState in project mes by qcadoo.
the class MaintenanceEventContextService method confirmOrChangeContext.
public void confirmOrChangeContext(ViewDefinitionState view, ComponentState componentState, String[] args) {
FormComponent formComponent = (FormComponentState) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity maintenanceEventContextEntity = prepareContextEntity(formComponent.getEntity());
if (maintenanceEventContextEntity.getBooleanField(MaintenanceEventContextFields.CONFIRMED)) {
maintenanceEventContextEntity = changeContext(view, maintenanceEventContextEntity);
} else {
Date dateFrom = maintenanceEventContextEntity.getDateField(MaintenanceEventContextFields.DATE_FROM);
Date dateTo = maintenanceEventContextEntity.getDateField(MaintenanceEventContextFields.DATE_TO);
if (Objects.nonNull(dateFrom) && Objects.nonNull(dateTo) && dateTo.before(dateFrom)) {
view.addMessage("cmmsMachineParts.plannedEventsList.window.contextTab.error.datesOrder", ComponentState.MessageType.FAILURE);
return;
}
maintenanceEventContextEntity = confirmContext(maintenanceEventContextEntity, args);
}
formComponent.setEntity(maintenanceEventContextEntity);
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class AwesomeDynamicListState method render.
@Override
public JSONObject render() throws JSONException {
JSONObject json = super.render();
if (!json.has(JSON_CONTENT)) {
JSONObject childerJson = new JSONObject();
for (FormComponentState form : forms) {
childerJson.put(form.getName(), form.render());
}
JSONObject content = new JSONObject();
content.put("innerFormChanges", childerJson);
json.put(JSON_CONTENT, content);
}
return json;
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class AwesomeDynamicListState method renderContent.
@Override
protected JSONObject renderContent() throws JSONException {
JSONObject json = new JSONObject();
JSONArray formValues = new JSONArray();
for (FormComponentState formState : forms) {
formValues.put(formState.render());
}
json.put(JSON_FORM_VALUES, formValues);
json.put(JSON_REQUIRED, isRequired());
return json;
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldInitialeFormWithNullEntityId.
@Test
public void shouldInitialeFormWithNullEntityId() throws Exception {
// given
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
InternalComponentState componentState = new FormComponentState(pattern);
JSONObject json = new JSONObject();
JSONObject jsonContent = new JSONObject();
jsonContent.put(FormComponentState.JSON_ENTITY_ID, (String) null);
json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
JSONObject jsonChildren = new JSONObject();
json.put(AbstractComponentState.JSON_CHILDREN, jsonChildren);
// when
componentState.initialize(json, Locale.ENGLISH);
// then
assertNull(componentState.getFieldValue());
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class ComponentStateTest method shouldNotHaveRequestUpdateStateIfNotValid.
@Test
public void shouldNotHaveRequestUpdateStateIfNotValid() throws Exception {
// given
TranslationService translationService = mock(TranslationService.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
AbstractComponentState componentState = new FormComponentState(pattern);
componentState.setTranslationService(translationService);
componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
componentState.addMessage("test", MessageType.FAILURE);
// when
JSONObject json = componentState.render();
// then
assertFalse(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
Aggregations