Withdrawals and deleteLastSubmission()
This commit is contained in:
@@ -28,4 +28,17 @@ body {
|
||||
|
||||
.clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#accountSelector {
|
||||
text-align: right;
|
||||
margin-right: 4em;
|
||||
}
|
||||
|
||||
.color-red {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.color-green {
|
||||
color: green;
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
<div>
|
||||
<div>
|
||||
<div><select ng-model='account' ng-change='refreshList()' ng-options="account.name for account in accounts track by account.id"></select></div>
|
||||
<div id="accountSelector"><select ng-model='account' ng-change='refreshList()' ng-options="account.name for account in accounts track by account.id"></select></div>
|
||||
|
||||
<div ng-show="lastSubmission" class='ui-state-highlight' style='text-align: center; padding: 0.5ex; width: 30em; margin:auto; margin-bottom: 2em;'>
|
||||
{{lastSubmission.date | date:'dd.MM.yyyy'}}
|
||||
<span ng-class="{ 'color-green': lastSubmission.amount > 0, 'color-red': lastSubmission.amount < 0 }">{{lastSubmission.amount}} €</span>
|
||||
|
||||
<span style='color: red; font-weight: bold;'><a href='' ng-click='deleteLastSubmission()'>löschen</a></span>
|
||||
</div>
|
||||
|
||||
|
||||
<form name="form" ng-submit="postTransaction()">
|
||||
<table border='0' cellpadding='1' style='margin: auto;'>
|
||||
<tr>
|
||||
<td align='right'>Betrag:</td>
|
||||
<td><input name="amount" ng-model='transaction.amount' type='text' required
|
||||
<td><input name="amount" ng-model='transaction.amount' type='text' required autofocus="autofocus"
|
||||
ng-pattern="/^[+-]?(?:\d+(?:[\.,]\d{0,2})?|[\.,]\d{1,2})$/" /><span ng-show="form.amount.$error.pattern"><br/>The value
|
||||
is not valid!</span></td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user