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