Fix indent.
This commit is contained in:
@ -35,242 +35,242 @@ var accountModule = angular.module('accountant.accounts', [
|
||||
ngUiNotification
|
||||
])
|
||||
|
||||
.config(function($resourceProvider) {
|
||||
// Keep trailing slashes to avoid redirect by flask..
|
||||
$resourceProvider.defaults.stripTrailingSlashes = false;
|
||||
})
|
||||
.config(function($resourceProvider) {
|
||||
// Keep trailing slashes to avoid redirect by flask..
|
||||
$resourceProvider.defaults.stripTrailingSlashes = false;
|
||||
})
|
||||
|
||||
.factory('Account', function($resource) {
|
||||
var Account = $resource(
|
||||
'/api/account/:id', {
|
||||
id: '@id'
|
||||
}
|
||||
);
|
||||
.factory('Account', function($resource) {
|
||||
var Account = $resource(
|
||||
'/api/account/:id', {
|
||||
id: '@id'
|
||||
}
|
||||
);
|
||||
|
||||
Account.prototype.getBalances = function() {
|
||||
var Balances = $resource('/api/account/:id/balances', {id: this.id});
|
||||
Account.prototype.getBalances = function() {
|
||||
var Balances = $resource('/api/account/:id/balances', {id: this.id});
|
||||
|
||||
this.balances = Balances.get();
|
||||
};
|
||||
this.balances = Balances.get();
|
||||
};
|
||||
|
||||
Account.prototype.getBalance = function(begin, end) {
|
||||
var Balance = $resource(
|
||||
'/api/account/:id/balance', {
|
||||
id: this.id,
|
||||
begin: begin.format('YYYY-MM-DD'),
|
||||
end: end.format('YYYY-MM-DD')
|
||||
Account.prototype.getBalance = function(begin, end) {
|
||||
var Balance = $resource(
|
||||
'/api/account/:id/balance', {
|
||||
id: this.id,
|
||||
begin: begin.format('YYYY-MM-DD'),
|
||||
end: end.format('YYYY-MM-DD')
|
||||
});
|
||||
|
||||
this.balance = Balance.get();
|
||||
};
|
||||
|
||||
return Account;
|
||||
})
|
||||
|
||||
.controller('AccountController', function(Account, Notification, $uibModal, $log, $q) {
|
||||
var vm = this;
|
||||
|
||||
/*
|
||||
* Return the class for an account current value compared to authorized
|
||||
* overdraft.
|
||||
*/
|
||||
vm.rowClass = function(account) {
|
||||
// eslint-disable-next-line camelcase
|
||||
if (!account || !account.authorized_overdraft || !account.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
if (account.current < account.authorized_overdraft) {
|
||||
return 'danger';
|
||||
} else if (account.current < 0) {
|
||||
return 'warning';
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Return the class for a value compared to account authorized overdraft.
|
||||
*/
|
||||
vm.valueClass = function(account, value) {
|
||||
if (!account || !value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
if (value < account.authorized_overdraft) {
|
||||
return 'text-danger';
|
||||
} else if (value < 0) {
|
||||
return 'text-warning';
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Add an empty account.
|
||||
*/
|
||||
vm.add = function() {
|
||||
var account = new Account({
|
||||
// eslint-disable-next-line camelcase
|
||||
authorized_overdraft: 0
|
||||
});
|
||||
|
||||
this.balance = Balance.get();
|
||||
};
|
||||
// Insert account at the begining of the array.
|
||||
return vm.modify(account);
|
||||
};
|
||||
|
||||
return Account;
|
||||
})
|
||||
|
||||
.controller('AccountController', function(Account, Notification, $uibModal, $log, $q) {
|
||||
var vm = this;
|
||||
|
||||
/*
|
||||
* Return the class for an account current value compared to authorized
|
||||
* overdraft.
|
||||
*/
|
||||
vm.rowClass = function(account) {
|
||||
// eslint-disable-next-line camelcase
|
||||
if (!account || !account.authorized_overdraft || !account.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
if (account.current < account.authorized_overdraft) {
|
||||
return 'danger';
|
||||
} else if (account.current < 0) {
|
||||
return 'warning';
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Return the class for a value compared to account authorized overdraft.
|
||||
*/
|
||||
vm.valueClass = function(account, value) {
|
||||
if (!account || !value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
if (value < account.authorized_overdraft) {
|
||||
return 'text-danger';
|
||||
} else if (value < 0) {
|
||||
return 'text-warning';
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Add an empty account.
|
||||
*/
|
||||
vm.add = function() {
|
||||
var account = new Account({
|
||||
// eslint-disable-next-line camelcase
|
||||
authorized_overdraft: 0
|
||||
});
|
||||
|
||||
// Insert account at the begining of the array.
|
||||
return vm.modify(account);
|
||||
};
|
||||
|
||||
/*
|
||||
* Save account.
|
||||
*/
|
||||
vm.save = function(account) {
|
||||
return account.$save().then(function(data) {
|
||||
Notification.success('Account #' + data.id + ' saved.');
|
||||
|
||||
vm.accounts = Account.query();
|
||||
|
||||
return data;
|
||||
}, function(result){
|
||||
$log.error('Error while saving account', account, result);
|
||||
|
||||
Notification.error(
|
||||
'Error while saving account: ' + result.message
|
||||
);
|
||||
|
||||
return $q.reject(result);
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Delete an account.
|
||||
*/
|
||||
vm.delete = function(account, $index) {
|
||||
var id = account.id;
|
||||
|
||||
$uibModal.open({
|
||||
component: 'accountDeleteModalComponent',
|
||||
resolve: {
|
||||
account: function() {
|
||||
return account;
|
||||
}
|
||||
}
|
||||
}).result.then(function(account) {
|
||||
return account.$delete().then(function() {
|
||||
Notification.success('account #' + id + ' deleted.');
|
||||
/*
|
||||
* Save account.
|
||||
*/
|
||||
vm.save = function(account) {
|
||||
return account.$save().then(function(data) {
|
||||
Notification.success('Account #' + data.id + ' saved.');
|
||||
|
||||
vm.accounts = Account.query();
|
||||
|
||||
return account;
|
||||
}, function(result) {
|
||||
return data;
|
||||
}, function(result){
|
||||
$log.error('Error while saving account', account, result);
|
||||
|
||||
Notification.error(
|
||||
'An error occurred while trying to delete account #' +
|
||||
id + ':<br />' + result
|
||||
'Error while saving account: ' + result.message
|
||||
);
|
||||
|
||||
return $q.reject(result);
|
||||
});
|
||||
}, function() {
|
||||
return false;
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* Open the popup to modify the account, save it on confirm.
|
||||
* @returns a promise.
|
||||
*/
|
||||
vm.modify = function(account) {
|
||||
return $uibModal.open({
|
||||
component: 'accountModifyModalComponent',
|
||||
resolve: {
|
||||
account: function() {
|
||||
return account;
|
||||
/*
|
||||
* Delete an account.
|
||||
*/
|
||||
vm.delete = function(account, $index) {
|
||||
var id = account.id;
|
||||
|
||||
$uibModal.open({
|
||||
component: 'accountDeleteModalComponent',
|
||||
resolve: {
|
||||
account: function() {
|
||||
return account;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).result.then(function(account) {
|
||||
return vm.save(account);
|
||||
}, function() {
|
||||
return false;
|
||||
});
|
||||
};
|
||||
}).result.then(function(account) {
|
||||
return account.$delete().then(function() {
|
||||
Notification.success('account #' + id + ' deleted.');
|
||||
|
||||
// Load accounts.
|
||||
vm.accounts = Account.query();
|
||||
})
|
||||
vm.accounts = Account.query();
|
||||
|
||||
.component('accountModifyModalComponent', {
|
||||
templateUrl: accountFormTmpl,
|
||||
bindings: {
|
||||
resolve: '<',
|
||||
close: '&',
|
||||
dismiss: '&'
|
||||
},
|
||||
controller: function() {
|
||||
var vm = this;
|
||||
return account;
|
||||
}, function(result) {
|
||||
Notification.error(
|
||||
'An error occurred while trying to delete account #' +
|
||||
id + ':<br />' + result
|
||||
);
|
||||
|
||||
vm.$onInit = function() {
|
||||
vm.account = vm.resolve.account;
|
||||
vm.authorized_overdraft = - vm.account.authorized_overdraft;
|
||||
};
|
||||
|
||||
vm.authorizedOverdraftChange = function() {
|
||||
vm.account.authorized_overdraft = - vm.authorized_overdraft;
|
||||
};
|
||||
|
||||
vm.ok = function() {
|
||||
vm.close({
|
||||
$value: vm.account
|
||||
return $q.reject(result);
|
||||
});
|
||||
}, function() {
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
vm.cancel = function() {
|
||||
vm.dismiss({
|
||||
$value: 'cancel'
|
||||
/*
|
||||
* Open the popup to modify the account, save it on confirm.
|
||||
* @returns a promise.
|
||||
*/
|
||||
vm.modify = function(account) {
|
||||
return $uibModal.open({
|
||||
component: 'accountModifyModalComponent',
|
||||
resolve: {
|
||||
account: function() {
|
||||
return account;
|
||||
}
|
||||
}
|
||||
}).result.then(function(account) {
|
||||
return vm.save(account);
|
||||
}, function() {
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
vm.title = function() {
|
||||
// FIXME Alexis Lahouze 2017-06-15 i18n
|
||||
if (vm.account.id) {
|
||||
return "Account #" + vm.account.id;
|
||||
} else {
|
||||
return "Account";
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
// Load accounts.
|
||||
vm.accounts = Account.query();
|
||||
})
|
||||
|
||||
.component('accountDeleteModalComponent', {
|
||||
templateUrl: accountDeleteTmpl,
|
||||
bindings: {
|
||||
resolve: '<',
|
||||
close: '&',
|
||||
dismiss: '&'
|
||||
},
|
||||
controller: function() {
|
||||
var vm = this;
|
||||
.component('accountModifyModalComponent', {
|
||||
templateUrl: accountFormTmpl,
|
||||
bindings: {
|
||||
resolve: '<',
|
||||
close: '&',
|
||||
dismiss: '&'
|
||||
},
|
||||
controller: function() {
|
||||
var vm = this;
|
||||
|
||||
vm.$onInit = function() {
|
||||
vm.account = vm.resolve.account;
|
||||
};
|
||||
vm.$onInit = function() {
|
||||
vm.account = vm.resolve.account;
|
||||
vm.authorized_overdraft = - vm.account.authorized_overdraft;
|
||||
};
|
||||
|
||||
vm.ok = function() {
|
||||
vm.close({
|
||||
$value: vm.account
|
||||
});
|
||||
};
|
||||
vm.authorizedOverdraftChange = function() {
|
||||
vm.account.authorized_overdraft = - vm.authorized_overdraft;
|
||||
};
|
||||
|
||||
vm.cancel = function() {
|
||||
vm.dismiss({
|
||||
$value: 'cancel'
|
||||
});
|
||||
};
|
||||
vm.ok = function() {
|
||||
vm.close({
|
||||
$value: vm.account
|
||||
});
|
||||
};
|
||||
|
||||
vm.title = function() {
|
||||
// FIXME Alexis Lahouze 2017-06-15 i18n
|
||||
if (vm.account.id) {
|
||||
return "Account #" + vm.account.id;
|
||||
} else {
|
||||
return "Account";
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
vm.cancel = function() {
|
||||
vm.dismiss({
|
||||
$value: 'cancel'
|
||||
});
|
||||
};
|
||||
|
||||
vm.title = function() {
|
||||
// FIXME Alexis Lahouze 2017-06-15 i18n
|
||||
if (vm.account.id) {
|
||||
return "Account #" + vm.account.id;
|
||||
} else {
|
||||
return "Account";
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
.component('accountDeleteModalComponent', {
|
||||
templateUrl: accountDeleteTmpl,
|
||||
bindings: {
|
||||
resolve: '<',
|
||||
close: '&',
|
||||
dismiss: '&'
|
||||
},
|
||||
controller: function() {
|
||||
var vm = this;
|
||||
|
||||
vm.$onInit = function() {
|
||||
vm.account = vm.resolve.account;
|
||||
};
|
||||
|
||||
vm.ok = function() {
|
||||
vm.close({
|
||||
$value: vm.account
|
||||
});
|
||||
};
|
||||
|
||||
vm.cancel = function() {
|
||||
vm.dismiss({
|
||||
$value: 'cancel'
|
||||
});
|
||||
};
|
||||
|
||||
vm.title = function() {
|
||||
// FIXME Alexis Lahouze 2017-06-15 i18n
|
||||
if (vm.account.id) {
|
||||
return "Account #" + vm.account.id;
|
||||
} else {
|
||||
return "Account";
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = accountModule;
|
||||
|
Reference in New Issue
Block a user