Search in sources :

Example 61 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class CompanyDefaultProductsListeners method addMultipleDefaultProducts.

public final void addMultipleDefaultProducts(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
    JSONObject obj = view.getJsonContext();
    if (obj.has("window.mainTab.product.companyId")) {
        CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
        GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
        Long companyId = obj.getLong("window.mainTab.product.companyId");
        try {
            tryCreatePositions(grid, companyId);
            view.addMessage("basic.companyDefaultProducts.info.generationSuccess", ComponentState.MessageType.SUCCESS);
            generated.setChecked(true);
        } catch (EntityRuntimeException ere) {
            generated.setChecked(false);
            view.addMessage("basic.companyDefaultProducts.error.defaultExists", ComponentState.MessageType.FAILURE, ere.getEntity().getBelongsToField(L_PRODUCT).getStringField(ProductFields.NUMBER));
        }
    }
}
Also used : JSONObject(org.json.JSONObject) GridComponent(com.qcadoo.view.api.components.GridComponent) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException)

Example 62 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class ImportService method shouldUpdate.

public boolean shouldUpdate(final ViewDefinitionState view) {
    boolean shouldUpdate = false;
    CheckBoxComponent shouldUpdateCheckBox = (CheckBoxComponent) view.getComponentByReference(L_SHOULD_UPDATE);
    if (Objects.nonNull(shouldUpdateCheckBox)) {
        shouldUpdate = shouldUpdateCheckBox.isChecked();
    }
    return shouldUpdate;
}
Also used : CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 63 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class OrdersGenerationFromProductsListeners method generateOrders.

public void generateOrders(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
    Entity entity = form.getPersistedEntityWithIncludedFormValues();
    entity = entity.getDataDefinition().validate(entity);
    if (!entity.isValid()) {
        form.setEntity(entity);
        return;
    }
    JSONObject context = view.getJsonContext();
    Set<Long> ids = Arrays.stream(context.getString("window.mainTab.form.gridLayout.selectedEntities").replaceAll("[\\[\\]]", "").split(",")).map(Long::valueOf).collect(Collectors.toSet());
    GenerationOrderResult result = new GenerationOrderResult(translationService, parameterService);
    try {
        generateOrders(result, ids, entity);
        result.showMessage(view);
    } catch (Exception exc) {
        view.addMessage("orders.ordersGenerationFromProducts.error.ordersNotGenerated", ComponentState.MessageType.FAILURE);
    }
    generated.setChecked(true);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) JSONObject(org.json.JSONObject) GenerationOrderResult(com.qcadoo.mes.masterOrders.GenerationOrderResult) JSONException(org.json.JSONException) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 64 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class SalesPlanMaterialRequirementDetailsListeners method generateSalesPlanMaterialRequirement.

public void generateSalesPlanMaterialRequirement(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent salesPlanMaterialRequirementForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    CheckBoxComponent generatedCheckBox = (CheckBoxComponent) view.getComponentByReference(SalesPlanMaterialRequirementFields.GENERATED);
    LookupComponent salesPlanLookup = (LookupComponent) view.getComponentByReference(SalesPlanMaterialRequirementFields.SALES_PLAN);
    FieldComponent workerField = (FieldComponent) view.getComponentByReference(SalesPlanMaterialRequirementFields.WORKER);
    FieldComponent dateField = (FieldComponent) view.getComponentByReference(SalesPlanMaterialRequirementFields.DATE);
    Entity salesPlan = salesPlanLookup.getEntity();
    if (validateSalesPlanMaterialRequirement(salesPlanMaterialRequirementForm, salesPlanLookup, salesPlan)) {
        workerField.setFieldValue(securityService.getCurrentUserName());
        dateField.setFieldValue(DateUtils.toDateTimeString(new Date()));
        generatedCheckBox.setChecked(true);
        Entity salesPlanMaterialRequirement = salesPlanMaterialRequirementForm.getEntity();
        List<Entity> salesPlanMaterialRequirementProducts = salesPlanMaterialRequirementHelper.generateSalesPlanMaterialRequirementProducts(salesPlanMaterialRequirement);
        salesPlanMaterialRequirement.setField(SalesPlanMaterialRequirementFields.SALES_PLAN_MATERIAL_REQUIREMENT_PRODUCTS, salesPlanMaterialRequirementProducts);
        salesPlanMaterialRequirement = salesPlanMaterialRequirement.getDataDefinition().save(salesPlanMaterialRequirement);
        salesPlanMaterialRequirementForm.setEntity(salesPlanMaterialRequirement);
        view.addMessage("masterOrders.salesPlanMaterialRequirement.generate.success", ComponentState.MessageType.SUCCESS);
    } else {
        view.addMessage("masterOrders.salesPlanMaterialRequirement.generate.failure", ComponentState.MessageType.FAILURE);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) Date(java.util.Date) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Example 65 with CheckBoxComponent

use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.

the class SalesPlanUseOtherTechnologyListeners method update.

public void update(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
    CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference(L_GENERATED);
    String ordersIds = view.getJsonContext().get("window.mainTab.salesPlanProduct.gridLayout.salesPlanProductsIds").toString();
    List<Long> salesPlanProductsIds = Lists.newArrayList(ordersIds.split(",")).stream().map(Long::valueOf).collect(Collectors.toList());
    DataDefinition salesPlanProductDataDefinition = dataDefinitionService.get(MasterOrdersConstants.PLUGIN_IDENTIFIER, MasterOrdersConstants.MODEL_SALES_PLAN_PRODUCT);
    List<Entity> salesPlanProducts = salesPlanProductDataDefinition.find().add(SearchRestrictions.in("id", salesPlanProductsIds)).list().getEntities();
    LookupComponent technologyLookup = (LookupComponent) view.getComponentByReference(SalesPlanProductFields.TECHNOLOGY);
    Entity technology = technologyLookup.getEntity();
    if (technology == null) {
        technologyLookup.addMessage("qcadooView.validate.field.error.missing", ComponentState.MessageType.FAILURE);
        view.addMessage("qcadooView.validate.global.error.custom", ComponentState.MessageType.FAILURE);
        return;
    }
    for (Entity salesPlanProduct : salesPlanProducts) {
        salesPlanProduct.setField(SalesPlanProductFields.TECHNOLOGY, technology);
        salesPlanProductDataDefinition.save(salesPlanProduct);
    }
    view.addMessage("masterOrders.salesPlanUseOtherTechnology.update.success", ComponentState.MessageType.SUCCESS);
    generated.setChecked(true);
}
Also used : Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) DataDefinition(com.qcadoo.model.api.DataDefinition) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent)

Aggregations

CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)100 FormComponent (com.qcadoo.view.api.components.FormComponent)38 Entity (com.qcadoo.model.api.Entity)33 FieldComponent (com.qcadoo.view.api.components.FieldComponent)30 GridComponent (com.qcadoo.view.api.components.GridComponent)19 LookupComponent (com.qcadoo.view.api.components.LookupComponent)11 Date (java.util.Date)7 JSONObject (org.json.JSONObject)7 BigDecimal (java.math.BigDecimal)6 ComponentState (com.qcadoo.view.api.ComponentState)4 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)4 IOException (java.io.IOException)4 MaterialFlowResourcesConstants (com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants)2 DataDefinition (com.qcadoo.model.api.DataDefinition)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)2 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)2 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)2 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)2