diff --git a/src/main/resources/static/js/controllers.js b/src/main/resources/static/js/controllers.js index b90e6d5..c2001f4 100644 --- a/src/main/resources/static/js/controllers.js +++ b/src/main/resources/static/js/controllers.js @@ -36,9 +36,13 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' $scope.accountUsers[i].outstandingSum = 0.0; for (j = 0; j < data[i]._embedded.transactions.length; j++) { + $scope.accountUsers[i].outstandings[j] = new Object(); + $scope.accountUsers[i].outstandings[j].date = data[i]._embedded.transactions[j].date; $scope.accountUsers[i].outstandings[j].description = data[i]._embedded.transactions[j].description; + + $scope.accountUsers[i].outstandings[j].href = data[i]._embedded.transactions[j]._links.self.href; $scope.accountUsers[i].outstandings[j].category = data[i]._embedded.transactions[j].category.name; if ($scope.accountUsers[i].outstandings[j].category === 'Private Entnahme') { // magic strings ftw @@ -236,7 +240,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' }); }; - $scope.openExpenses = function(user) { + $scope.openOutstandings = function(user) { var modalInstance = $uibModal.open({ templateUrl: 'outstandingsTemplate.html', controller: 'OutstandingsModalCtrl', @@ -246,7 +250,7 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location' }); modalInstance.result.then(function() { - refreshExpenses(); + $scope.refreshList(); }, function () { $log.info('OutstandingsModal dismissed ' + new Date()); }); @@ -309,7 +313,7 @@ transactionControllers.controller('DetailsModalCtrl', [ '$scope', '$resource', ' } } ]); -transactionControllers.controller('OutstandingsModalCtrl', [ '$scope', '$uibModalInstance', 'accountUser', function($scope, $uibModalInstance, accountUser) { +transactionControllers.controller('OutstandingsModalCtrl', [ '$scope', '$uibModalInstance', '$http', '$resource', '$q', 'accountUser', function($scope, $uibModalInstance, $http, $resource, $q, accountUser) { $scope.accountUser = accountUser; @@ -322,6 +326,21 @@ transactionControllers.controller('OutstandingsModalCtrl', [ '$scope', '$uibModa }; $scope.clearOutstandings = function() { - // TODO + var promises = new Array($scope.accountUser.outstandings.length); + for (i = 0; i < $scope.accountUser.outstandings.length; i++) { + if ($scope.accountUser.outstandings[i].category === 'Private Entnahme') { + // delete withdrawals + var resource = $resource($scope.accountUser.outstandings[i].href).remove(); + promises[i] = resource.$promise; + } + else { + // remove creditor from expenses + promises[i] = $http.patch($scope.accountUser.outstandings[i].href, '{ "creditor" : "" }'); + } + } + + $q.all(promises).then(function(data) { + $uibModalInstance.close('cleared outstandings'); + }); } } ]); diff --git a/src/main/resources/static/js/services.js b/src/main/resources/static/js/services.js index dc8faa0..72e8766 100644 --- a/src/main/resources/static/js/services.js +++ b/src/main/resources/static/js/services.js @@ -4,6 +4,9 @@ transactionServices.factory('Transaction', [ '$resource', function($resource) { return $resource('/transactions/:id', { id: '@id' }, { update : { method : 'PUT' + }, + patch : { + method : 'PATCH' } }); } ]); diff --git a/src/main/resources/static/partials/transaction-list.html b/src/main/resources/static/partials/transaction-list.html index f960656..44451ad 100644 --- a/src/main/resources/static/partials/transaction-list.html +++ b/src/main/resources/static/partials/transaction-list.html @@ -100,7 +100,7 @@
- {{user.name}} {{user.outstandingAmount}} €
+ {{user.name}} {{user.outstandingAmount}} €