| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- (function(){
- 'use strict';
-
- angular
- .module('cloudbudget')
- .controller('AccountsController', AccountsController);
-
- AccountsController.$inject = ['$scope', '$location', 'FlashService', 'AccountsService'];
-
- function AccountsController($scope, $location, FlashService, AccountsService) {
- var vm = this;
-
- vm.dataLoading = false;
- vm.accounts = [];
- vm.create = create;
- vm.drop = drop;
- vm.edit = edit;
- vm.consult = consult;
-
- (function init() {
- vm.dataLoading = true;
- AccountsService.list()
- .then(function(response) {
- if( response.success ) {
- vm.accounts = response.accounts;
- } else {
- FlashService.error(response.message);
- }
- vm.dataLoading = false;
- })
- })();
-
- function create() {
- vm.dataLoading = true;
- AccountsService.create(vm.account)
- .then( function(response) {
- if( response.success) {
- vm.accounts.push(response.account);
- } else {
- FlashService.error(response.message);
- }
-
- vm.dataLoading = false;
- });
- vm.account = angular.copy({});
- $scope.form.$setPristine();
- };
-
- function drop(account) {
- vm.dataLoading = true;
- AccountsService.drop(account)
- .then(function(response) {
- if( response.success ) {
- var index = vm.accounts.indexOf(account);
- vm.accounts.splice(index, 1);
- } else {
- FlashService.error( response.message );
- }
- vm.dataLoading = false;
- });
- };
-
- function edit(altered, origin) {
- vm.dataLoading = true;
- return AccountsService.edit(origin._id, altered)
- .then( function(response) {
- if( response.success ) {
- var index = vm.accounts.map(function (item) {
- return item._id;
- }).indexOf(origin._id);
- vm.accounts[index] = response.account;
- } else {
- FlashService.error( response.message );
- return false;
- }
- })
- };
-
- function consult(account) {
- $location.path('/account/' + account._id);
- };
- }
- })();
|