diff --git a/bower.json b/bower.json index bb9fc12..1d55bb6 100644 --- a/bower.json +++ b/bower.json @@ -7,7 +7,8 @@ "angular-route": "~1.4.1", "animate.css": "~3.3.0", "bootstrap": "~3.3.5", - "font-awesome": "~4.4.0" + "font-awesome": "~4.4.0", + "angular-xeditable": "~0.1.9" }, "devDependencies": { "angular-mocks": "~1.4.4" diff --git a/karma.conf.js b/karma.conf.js index becc510..02d8fa5 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,6 +18,7 @@ module.exports = function(config) { 'public/libs/angular/angular.js', 'public/libs/angular-route/angular-route.js', 'public/libs/angular-cookies/angular-cookies.js', + 'public/libs/angular-xeditable/dist/js/xeditable.min.js', 'public/libs/angular-mocks/angular-mocks.js', 'public/js/**/*.js', 'public/**/*.controller.js', diff --git a/public/accounts/accounts.controller.js b/public/accounts/accounts.controller.js new file mode 100644 index 0000000..f0475de --- /dev/null +++ b/public/accounts/accounts.controller.js @@ -0,0 +1,83 @@ +(function(){ + 'use strict'; + + angular + .module('cloudbudget') + .controller('AccountsController', AccountsController); + + AccountsController.$inject = ['$scope', '$location', '$rootScope', 'FlashService', 'AccountsService']; + + function AccountsController($scope, $location, $rootScope, 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); + }; + } +})(); \ No newline at end of file diff --git a/public/accounts/accounts.view.html b/public/accounts/accounts.view.html new file mode 100644 index 0000000..9e57d6f --- /dev/null +++ b/public/accounts/accounts.view.html @@ -0,0 +1,49 @@ +
\ No newline at end of file diff --git a/public/index.html b/public/index.html index 03b55df..c1cb949 100644 --- a/public/index.html +++ b/public/index.html @@ -5,7 +5,9 @@@@ -37,18 +34,21 @@