Files
InventoryTraker-Box/InventoryTraker.Web/js/inventory/InventoryDistributeDirective.js
T
poprhythm a5fcb46e04 InventoryType from XML
Transaction updates
2016-08-25 13:00:09 -04:00

50 lines
1.2 KiB
JavaScript

(function() {
"use strict";
window.app.directive('inventoryDistribute', inventoryDistribute);
function inventoryDistribute() {
return {
templateUrl: '/inventory/template/inventoryDistribute.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
controller.$inject = ['$scope', 'inventorySvc'];
function controller($scope, inventorySvc) {
var vm = this;
vm.save = save;
vm.saving = false;
vm.quantities = angular.copy(inventorySvc.inventories);
vm.distribution = {};
vm.errorMessage = null;
function getInventoryDistributeQuantities(inventory) {
var invQty = [];
inventory.forEach(function (i) {
if (i.distributeQuantity > 0)
invQty.push({ inventoryId: i.id, quantity: i.distributeQuantity });
});
return invQty;
}
function save() {
vm.saving = true;
vm.distribution.inventoryQuantities = getInventoryDistributeQuantities(vm.quantities);
inventorySvc.distribute(vm.distribution)
.success(function () {
//Close the modal
$scope.$close();
})
.error(function(data) {
vm.errorMessage =
'There was a problem distributing the inventory: ' + data.errorMessage;
})
.finally(function() {
vm.saving = false;
});
}
}
})();