Search in sources :

Example 16 with FormComponentState

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);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState)

Example 17 with FormComponentState

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;
}
Also used : JSONObject(org.json.JSONObject) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState)

Example 18 with FormComponentState

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;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState)

Example 19 with FormComponentState

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());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 20 with FormComponentState

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));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Aggregations

FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)24 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)18 Test (org.junit.Test)17 JSONObject (org.json.JSONObject)12 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)8 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)5 ApplicationContext (org.springframework.context.ApplicationContext)5 TranslationService (com.qcadoo.localization.api.TranslationService)4 ComponentState (com.qcadoo.view.api.ComponentState)4 DataDefinition (com.qcadoo.model.api.DataDefinition)3 Entity (com.qcadoo.model.api.Entity)3 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)3 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)2 FormComponent (com.qcadoo.view.api.components.FormComponent)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 ViewEventListenerHook (com.qcadoo.view.internal.hooks.ViewEventListenerHook)2 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)2 JSONArray (org.json.JSONArray)2 FieldDefinition (com.qcadoo.model.api.FieldDefinition)1 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)1