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