Withdrawals and deleteLastSubmission()

This commit is contained in:
2016-04-19 15:58:20 +02:00
parent 51f70c3b45
commit a63d066b0a
10 changed files with 197 additions and 7 deletions
+34 -1
View File
@@ -63,7 +63,6 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
}
radioButtons[0].checked = true;
}
}
$scope.initList = function() {
@@ -104,6 +103,30 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
amount = '-' + amount;
}
// handle withdrawals
if ($scope.transaction.category._links.self.href === 'withdrawal') {
if (amount.charAt(0) === '-') {
amount = amount.substr(1);
}
var Withdrawal = $resource('/withdrawals');
var newWithdrawal = new Withdrawal({
"account" : $scope.account._links.self.href,
"amount" : amount,
"date" : $scope.transaction.date,
"user" : $scope.userinfo._links.self.href
});
newWithdrawal.$save(function(withdrawal) {
$scope.refreshList();
$scope.lastSubmission = newWithdrawal;
console.log(newWithdrawal);
});
return;
}
// via Resource (might be moved into a service)
var Transaction = $resource('/transactions');
@@ -118,6 +141,16 @@ transactionControllers.controller('TransactionListCtrl', [ '$scope', '$location'
newTransaction.$save(function(transaction) {
$scope.refreshList();
$scope.lastSubmission = newTransaction;
});
};
$scope.deleteLastSubmission = function() {
console.log($scope.lastSubmission._links.self.href);
var testTrns = $resource($scope.lastSubmission._links.self.href).delete(function() {
$scope.lastSubmission = undefined;
$scope.refreshList();
});
};