From 7e3b6e2b5db4b86a670be89b1da9debcf6be74c2 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 24 Nov 2019 14:52:19 +0000 Subject: [PATCH] Fix select all checkbox state in both incoming and outgoing exchanges by using the total count of variants to see if all variants are selected or not, even if not all variants are loaded --- .../order_cycles/controllers/incoming_controller.js.coffee | 2 ++ .../controllers/order_cycle_exchanges_controller.js.coffee | 3 +++ .../order_cycles/controllers/outgoing_controller.js.coffee | 5 +++++ app/views/admin/order_cycles/_exchange_form.html.haml | 6 +----- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/incoming_controller.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/incoming_controller.js.coffee index ef72e3f0e5..ea5a4216fa 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/incoming_controller.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/incoming_controller.js.coffee @@ -13,6 +13,8 @@ angular.module('admin.orderCycles').controller 'AdminOrderCycleIncomingCtrl', ($ params = { exchange_id: exchange.id, enterprise_id: exchange.enterprise_id, order_cycle_id: $scope.order_cycle.id, incoming: true} ExchangeProduct.countVariants params, (variants_count) -> enterprise.numVariants = variants_count + $scope.setSelectAllVariantsCheckboxValue(exchange, enterprise.numVariants) + return enterprise.numVariants $scope.addSupplier = ($event) -> diff --git a/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee index eb38dee815..1a81aca9cc 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee @@ -5,6 +5,9 @@ angular.module('admin.orderCycles') $scope.supplier_enterprises = Enterprise.producer_enterprises $scope.distributor_enterprises = Enterprise.hub_enterprises + $scope.setSelectAllVariantsCheckboxValue = (exchange, totalNumberOfVariants) -> + exchange.select_all_variants = $scope.exchangeSelectedVariants(exchange) >= totalNumberOfVariants + $scope.exchangeSelectedVariants = (exchange) -> OrderCycle.exchangeSelectedVariants(exchange) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee index 157a723672..31aec9677f 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/outgoing_controller.js.coffee @@ -9,6 +9,11 @@ angular.module('admin.orderCycles').controller 'AdminOrderCycleOutgoingCtrl', ($ $scope.incomingExchangeVariantsFor = (enterprise_id) -> $filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id]) + $scope.exchangeTotalVariants = (exchange) -> + totalNumberOfVariants = $scope.incomingExchangeVariantsFor(exchange.enterprise_id).length + $scope.setSelectAllVariantsCheckboxValue(exchange, totalNumberOfVariants) + totalNumberOfVariants + $scope.addDistributor = ($event) -> $event.preventDefault() OrderCycle.addDistributor $scope.new_distributor_id diff --git a/app/views/admin/order_cycles/_exchange_form.html.haml b/app/views/admin/order_cycles/_exchange_form.html.haml index b89016c22b..267d6f242f 100644 --- a/app/views/admin/order_cycles/_exchange_form.html.haml +++ b/app/views/admin/order_cycles/_exchange_form.html.haml @@ -1,11 +1,7 @@ %tr{ ng: { class: "'#{type} #{type}-{{ exchange.enterprise_id }}'" } } %td{:class => "#{type}_name"} {{ enterprises[exchange.enterprise_id].name }} %td.products.panel-toggle.text-center{ name: "products" } - {{ exchangeSelectedVariants(exchange) }} / - - if type == 'supplier' - {{ exchangeTotalVariants(exchange) }} - - else - {{ (incomingExchangeVariantsFor(exchange.enterprise_id)).length }} + {{ exchangeSelectedVariants(exchange) }} / {{ exchangeTotalVariants(exchange) }} = t('.selected') - if type == 'supplier' %td.receival-details