Search in sources :

Example 56 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class AnomalyExplanationDetailsListeners method selectedProductChange.

public void selectedProductChange(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity anomalyExplanation = form.getPersistedEntityWithIncludedFormValues();
    Entity selectedProduct = anomalyExplanation.getBelongsToField(AnomalyExplanationFields.PRODUCT);
    ComponentState productUnit = view.getComponentByReference("productUnit");
    ComponentState usedQuantity = view.getComponentByReference("usedQuantity");
    ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
    if (selectedProduct != null) {
        String selectedProductUnit = selectedProduct.getStringField(ProductFields.UNIT);
        productUnit.setFieldValue(selectedProductUnit);
        usedQuantity.setEnabled(true);
        String selectedProductAdditionalUnit = selectedProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
        if (isNotBlank(selectedProductAdditionalUnit)) {
            givenUnitComponent.setFieldValue(selectedProductAdditionalUnit);
        } else {
            givenUnitComponent.setFieldValue(selectedProductUnit);
        }
    } else {
        productUnit.setFieldValue(null);
        view.getComponentByReference("usedQuantity").setFieldValue(null);
        view.getComponentByReference("givenQuantity").setFieldValue(null);
        givenUnitComponent.setFieldValue(null);
        usedQuantity.setEnabled(false);
    }
    usedQuantity.performEvent(view, "onInputChange", ArrayUtils.EMPTY_STRING_ARRAY);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) ComponentState(com.qcadoo.view.api.ComponentState)

Example 57 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class TechnologiesWithUsingProductListHooks method showInfoIfNotUsed.

private void showInfoIfNotUsed(final ViewDefinitionState viewDefinitionState) {
    GridComponent grid = (GridComponent) viewDefinitionState.getComponentByReference(QcadooViewConstants.L_GRID);
    if (grid.getEntities().isEmpty()) {
        ComponentState form = viewDefinitionState.getComponentByReference(QcadooViewConstants.L_FORM);
        form.addMessage("technologies.product.info.notUsed", MessageType.INFO, true);
    }
}
Also used : GridComponent(com.qcadoo.view.api.components.GridComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 58 with ComponentState

use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.

the class TechnologyDetailsHooks method setTreeTabEditable.

public void setTreeTabEditable(final ViewDefinitionState view) {
    final boolean treeTabShouldBeEnabled = !isTemplateAccepted(view) && TechnologyState.DRAFT.equals(getTechnologyState(view)) && technologyIsAlreadySaved(view);
    ComponentState technologyTree = view.getComponentByReference(TECHNOLOGY_TREE_REFERENCE);
    technologyTree.setEnabled(treeTabShouldBeEnabled);
    Long selectedEntity = ((TreeComponent) technologyTree).getSelectedEntityId();
    for (String componentReference : Sets.newHashSet(OUT_PRODUCTS_REFERENCE, IN_PRODUCTS_REFERENCE)) {
        GridComponent grid = (GridComponent) view.getComponentByReference(componentReference);
        grid.setEnabled(treeTabShouldBeEnabled && Objects.nonNull(selectedEntity));
    }
}
Also used : TreeComponent(com.qcadoo.view.api.components.TreeComponent) GridComponent(com.qcadoo.view.api.components.GridComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 59 with ComponentState

use of com.qcadoo.view.api.ComponentState in project qcadoo by qcadoo.

the class ViewDefinitionStateImpl method renderContent.

@Override
protected JSONObject renderContent() throws JSONException {
    JSONObject json = new JSONObject();
    boolean isOk = true;
    List<InternalComponentState> states = getStatesAsList(getChildren().values());
    for (ComponentState state : states) {
        if (state.isHasError()) {
            isOk = false;
            break;
        }
    }
    json.put("status", isOk ? "ok" : "error");
    return json;
}
Also used : JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 60 with ComponentState

use of com.qcadoo.view.api.ComponentState in project qcadoo by qcadoo.

the class UserService method hidePasswordOnUpdateForm.

public void hidePasswordOnUpdateForm(final ViewDefinitionState state) {
    FormComponent form = (FormComponent) state.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent password = (FieldComponent) state.getComponentByReference("passwordTextInput");
    FieldComponent passwordConfirmation = (FieldComponent) state.getComponentByReference("passwordConfirmationTextInput");
    ComponentState changePasswordButton = state.getComponentByReference("changePasswordButton");
    password.setRequired(true);
    passwordConfirmation.setRequired(true);
    if (form.getEntityId() == null) {
        password.setVisible(true);
        passwordConfirmation.setVisible(true);
        changePasswordButton.setVisible(false);
    } else {
        password.setVisible(false);
        passwordConfirmation.setVisible(false);
        changePasswordButton.setVisible(true);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8