Count selected variants on an exchange

This commit is contained in:
Rohan Mitchell
2013-01-11 10:36:27 +11:00
parent a9fb10b0ca
commit d3189e333b
4 changed files with 82 additions and 11 deletions

View File

@@ -3,6 +3,14 @@ function AdminCreateOrderCycleCtrl($scope, OrderCycle, Enterprise) {
$scope.order_cycle = OrderCycle.order_cycle;
$scope.exchangeVariantsSelected = function(exchange) {
return OrderCycle.exchangeVariantsSelected(exchange);
};
$scope.enterpriseVariantsTotal = function(enterprise) {
return OrderCycle.enterpriseVariantsTotal(enterprise);
};
$scope.toggleProducts = function($event, exchange) {
$event.preventDefault();
OrderCycle.toggleProducts(exchange);
@@ -25,6 +33,14 @@ function AdminEditOrderCycleCtrl($scope, $location, OrderCycle, Enterprise) {
var order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1];
$scope.order_cycle = OrderCycle.load(order_cycle_id);
$scope.exchangeVariantsSelected = function(exchange) {
return OrderCycle.exchangeVariantsSelected(exchange);
};
$scope.enterpriseVariantsTotal = function(enterprise) {
return OrderCycle.enterpriseVariantsTotal(enterprise);
};
$scope.toggleProducts = function($event, exchange) {
$event.preventDefault();
OrderCycle.toggleProducts(exchange);
@@ -56,6 +72,28 @@ angular.module('order_cycle', ['ngResource']).
order_cycle: {incoming_exchanges: [],
outgoing_exchanges: []},
exchangeVariantsSelected: function(exchange) {
var numActiveVariants = 0;
angular.forEach(exchange.variants, function(active, id) {
if(active) {
numActiveVariants++;
}
});
return numActiveVariants;
},
enterpriseVariantsTotal: function(enterprise) {
var numVariants = 0;
angular.forEach(enterprise.supplied_products, function(product) {
numVariants += product.variants.length == 0 ? 1 : product.variants.length;
});
return numVariants;
},
toggleProducts: function(exchange) {
exchange.showProducts = !exchange.showProducts
},