Remove inventory, delete transactions
This commit is contained in:
@@ -14,25 +14,49 @@
|
||||
}
|
||||
}
|
||||
|
||||
controller.$inject = ['$scope', 'inventorySvc', 'transactionSvc'];
|
||||
function controller($scope, inventorySvc, transactionSvc) {
|
||||
controller.$inject = ['$scope', '$uibModal', 'inventorySvc', 'transactionSvc'];
|
||||
function controller($scope, $uibModal, inventorySvc, transactionSvc) {
|
||||
var vm = this;
|
||||
vm.inventory = angular.copy($scope.inventory);
|
||||
vm.inventory = $scope.inventory;
|
||||
vm.transactions = [];
|
||||
|
||||
function loadTransactions() {
|
||||
function refreshTransactions() {
|
||||
vm.loadingTransactions = true;
|
||||
vm.transactions = [];
|
||||
transactionSvc
|
||||
.filterByInventoryId(vm.inventory.id)
|
||||
.success(function(data) {
|
||||
angular.merge(vm.transactions, data.transactions);
|
||||
});
|
||||
.success(function (data) {
|
||||
if (data.transactions.length === 0) {
|
||||
$scope.$parent.$close();
|
||||
} else {
|
||||
angular.copy(data.transactions, vm.transactions);
|
||||
}
|
||||
})
|
||||
.finally(function(){vm.loadingTransactions = false;});
|
||||
}
|
||||
|
||||
loadTransactions();
|
||||
refreshTransactions(); // initial call
|
||||
|
||||
vm.save = save;
|
||||
vm.deleteTransaction = deleteTransaction;
|
||||
vm.removeInventory = removeInventory;
|
||||
vm.saving = false;
|
||||
vm.errorMessage = null;
|
||||
vm.errorMessages = [];
|
||||
vm.confirmDeleteTransaction = false;
|
||||
vm.loadingTransactions = false;
|
||||
|
||||
function deleteTransaction(transactionId) {
|
||||
vm.confirmDeleteTransaction = false;
|
||||
transactionSvc
|
||||
.deleteTransaction(transactionId)
|
||||
.success(refreshTransactions);
|
||||
}
|
||||
|
||||
function removeInventory() {
|
||||
$uibModal.open({
|
||||
template: '<inventory-remove inventory="inventory" />',
|
||||
scope: angular.extend($scope.$new(true), { inventory: vm.inventory })
|
||||
}).closed.then(refreshTransactions);
|
||||
}
|
||||
|
||||
function save() {
|
||||
vm.saving = true;
|
||||
@@ -42,7 +66,7 @@
|
||||
$scope.$parent.$close();
|
||||
})
|
||||
.error(function(data) {
|
||||
vm.errorMessage = 'There was a problem saving changes to the inventory: ' + data.errorMessage;
|
||||
vm.errorMessages = angular.copy(data.errorMessages, vm.errorMessages);
|
||||
})
|
||||
.finally(function() {
|
||||
vm.saving = false;
|
||||
|
||||
Reference in New Issue
Block a user