Feature: get user's accounts

This commit is contained in:
2015-10-01 09:09:48 +00:00
parent 8ed20ebf78
commit fdedcdcdff
17 changed files with 476 additions and 82 deletions

View File

@@ -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);
};
}
})();

View File

@@ -0,0 +1,49 @@
<div class="container-fluid">
<div class="row">
<form name="form" ng-submit="vm.create()" role="form">
<div class="col-sm-4">
<div class="form-group">
<input name="reference" id="reference" class="form-control" placeholder="Reference" ng-model="vm.account.reference" />
</div>
</div>
<div class="col-sm-4">
<div class="form-group" ng-class="{'has-error': form.name.$dirty && form.name.$error.required}">
<input name="name" id="name" class="form-control" ng-model="vm.account.name" placeholder="name" required/>
<span ng-show="form.name.$dirty && form.name.$error.required" class="help-block">name is required</span>
</div>
</div>
<div class="col-sm-4">
<button type="submit" class="btn btn-primary" ng-disabled="form.$invalid || vm.dataLoading">
<i class="fa fa-fw fa-floppy-o"></i>
</button>
<img ng-if="vm.dataLoading" src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==" />
</div>
</form>
</div>
<div class="row" ng-repeat="account in vm.accounts">
<div class="col-sm-4">
<span e-form="rowform" e-name="reference" editable-text="account.reference">{{account.reference}}</span>
</div>
<div class="col-sm-4"><span e-form="rowform" e-name="name" editable-text="account.name" e-required>{{account.name}}</span></div>
<div class="col-sm-4">
<form editable-form name="rowform" onbeforesave="vm.edit($data, account)" ng-show="rowform.$visible" xclass="form-buttons form-inline" shown="inserted == account">
<button type="submit" ng-disabled="rowForm.$invalid || rowform.$waiting" title="Edit" class="btn btn-success">
<i class="fa fa-fw fa-floppy-o"></i>
</button>
<button type="button" ng-disabled="rowform.$waiting" title="Cancel" ng-click="rowform.$cancel()" class="btn btn-default">
<i class="fa fa-fw fa-ban"></i>
</button>
<a class="btn btn-danger" title="Delete" ng-disabled="rowForm.$waiting" ng-click="vm.drop(account)">
<i class="fa fa-fw fa-trash"></i>
</a>
</form>
<a class="btn btn-success" ng-click="rowform.$show()" ng-show="!rowform.$visible">
<i class="fa fa-fw fa-pencil"></i>
</a>
<a class="btn btn-primary" ng-click="vm.consult(account)" ng-show="!rowform.$visible">
<i class="fa fa-fw fa-eye"></i>
</a>
</div>
</div>
</div>