From 3dcbdad088dbaf7465b1982373d1328ab3291acc Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 17 Nov 2015 14:57:20 +1100 Subject: [PATCH] Show/hide all products --- .../order_cycles/services/order_cycle.js.coffee | 11 +++++++++++ app/views/admin/order_cycles/_form.html.haml | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee b/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee index e16ffcb6ce..8577185be1 100644 --- a/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee @@ -7,6 +7,7 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $ { order_cycle: {} + showProducts: {incoming: false, outgoing: false} loaded: false @@ -21,6 +22,10 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $ toggleProducts: (exchange) -> exchange.showProducts = !exchange.showProducts + toggleAllProducts: (direction) -> + this.showProducts[direction] = !this.showProducts[direction] + exchange.showProducts = this.showProducts[direction] for exchange in this.exchangesByDirection(direction) + setExchangeVariants: (exchange, variants, selected) -> direction = if exchange.incoming then "incoming" else "outgoing" editable = @order_cycle["editable_variants_for_#{direction}_exchanges"][exchange.enterprise_id] || [] @@ -80,6 +85,12 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $ distributors = (exchange.enterprise_id for exchange in this.order_cycle.outgoing_exchanges) jQuery.unique(suppliers.concat(distributors)).sort() + exchangesByDirection: (direction) -> + if direction == 'incoming' + this.order_cycle.incoming_exchanges + else + this.order_cycle.outgoing_exchanges + removeDistributionOfVariant: (variant_id) -> for exchange in this.order_cycle.outgoing_exchanges exchange.variants[variant_id] = false diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index ca78bf4203..4f2d52382e 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -8,7 +8,12 @@ %thead %tr %th Supplier - %th Products + %th + Products + = surround '(', ')' do + %a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('incoming')"} + %span{'ng-show' => "OrderCycle.showProducts['incoming']"} Collapse all + %span{'ng-hide' => "OrderCycle.showProducts['incoming']"} Expand all %th Receival details %th Fees %th.actions @@ -28,7 +33,12 @@ %thead %tr %th Distributor - %th Products + %th + Products + = surround '(', ')' do + %a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('outgoing')"} + %span{'ng-show' => "OrderCycle.showProducts['outgoing']"} Collapse all + %span{'ng-hide' => "OrderCycle.showProducts['outgoing']"} Expand all %th Pickup / Delivery details %th Fees %th.actions