Refactored 'accounts' to be more general with 'destinations'
This commit is contained in:
@ -1,27 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('lemur')
|
||||
|
||||
.config(function config($routeProvider) {
|
||||
$routeProvider.when('/accounts/create', {
|
||||
templateUrl: '/angular/accounts/account/account.tpl.html',
|
||||
controller: 'AccountsCreateController'
|
||||
});
|
||||
$routeProvider.when('/accounts/:id/edit', {
|
||||
templateUrl: '/angular/accounts/account/account.tpl.html',
|
||||
controller: 'AccountsEditController'
|
||||
});
|
||||
})
|
||||
|
||||
.controller('AccountsCreateController', function ($scope, AccountService, LemurRestangular){
|
||||
$scope.account = LemurRestangular.restangularizeElement(null, {}, 'accounts');
|
||||
$scope.save = AccountService.create;
|
||||
})
|
||||
|
||||
.controller('AccountsEditController', function ($scope, $routeParams, AccountService, AccountApi) {
|
||||
AccountApi.get($routeParams.id).then(function (account) {
|
||||
$scope.account = account;
|
||||
});
|
||||
|
||||
$scope.save = AccountService.update;
|
||||
});
|
@ -1,45 +0,0 @@
|
||||
<h2 class="featurette-heading"><span ng-show="!account.fromServer">Create</span><span ng-show="account.fromServer">Edit</span> Account <span class="text-muted"><small>next in line please
|
||||
</small></span></h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<a href="/#/accounts/" class="btn btn-danger pull-right">Cancel</a>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form name="createForm" class="form-horizontal" role="form" novalidate>
|
||||
<div class="form-group"
|
||||
ng-class="{'has-error': createForm.name.$invalid, 'has-success': !createForm.name.$invalid&&createForm.name.$dirty}">
|
||||
<label class="control-label col-sm-2">
|
||||
Name
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<input name="name" ng-model="account.label" placeholder="Name" class="form-control" required/>
|
||||
<p ng-show="createForm.name.$invalid && !createForm.name.$pristine" class="help-block">You must enter an account name</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group"
|
||||
ng-class="{'has-error': createForm.accountNumber.$invalid, 'has-success': !createForm.accountNumber.$invalid&&createForm.accountNumber.$dirty}">
|
||||
<label class="control-label col-sm-2">
|
||||
Account Number
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="number" name="accountNumber" ng-model="account.accountNumber" placeholder="111111111111" class="form-control" ng-minlength="12" ng-maxlength="12" required/>
|
||||
<p ng-show="createForm.accountNumber.$invalid && !createForm.accountNumber.$pristine" class="help-block">You must enter an account number</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2">
|
||||
Comments
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea name="comments" ng-model="account.comments" placeholder="Something elegant" class="form-control" ></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<button ng-click="save(account)" type="submit" ng-disabled="createForm.$invalid" class="btn btn-primary pull-right">Save</button>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
53
lemur/static/app/angular/accounts/services.js
vendored
53
lemur/static/app/angular/accounts/services.js
vendored
@ -1,53 +0,0 @@
|
||||
'use strict';
|
||||
angular.module('lemur')
|
||||
.service('AccountApi', function (LemurRestangular) {
|
||||
return LemurRestangular.all('accounts');
|
||||
})
|
||||
.service('AccountService', function ($location, AccountApi, toaster) {
|
||||
var AccountService = this;
|
||||
AccountService.findAccountsByName = function (filterValue) {
|
||||
return AccountApi.getList({'filter[label]': filterValue})
|
||||
.then(function (accounts) {
|
||||
return accounts;
|
||||
});
|
||||
};
|
||||
|
||||
AccountService.create = function (account) {
|
||||
AccountApi.post(account).then(
|
||||
function () {
|
||||
toaster.pop({
|
||||
type: 'success',
|
||||
title: account.label,
|
||||
body: 'Successfully created!'
|
||||
});
|
||||
$location.path('accounts');
|
||||
},
|
||||
function (response) {
|
||||
toaster.pop({
|
||||
type: 'error',
|
||||
title: account.label,
|
||||
body: 'Was not created! ' + response.data.message
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
AccountService.update = function (account) {
|
||||
account.put().then(
|
||||
function () {
|
||||
toaster.pop({
|
||||
type: 'success',
|
||||
title: account.label,
|
||||
body: 'Successfully updated!'
|
||||
});
|
||||
$location.path('accounts');
|
||||
},
|
||||
function (response) {
|
||||
toaster.pop({
|
||||
type: 'error',
|
||||
title: account.label,
|
||||
body: 'Was not updated! ' + response.data.message
|
||||
});
|
||||
});
|
||||
};
|
||||
return AccountService;
|
||||
});
|
52
lemur/static/app/angular/accounts/view/view.js
vendored
52
lemur/static/app/angular/accounts/view/view.js
vendored
@ -1,52 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('lemur')
|
||||
|
||||
.config(function config($routeProvider) {
|
||||
$routeProvider.when('/accounts', {
|
||||
templateUrl: '/angular/accounts/view/view.tpl.html',
|
||||
controller: 'AccountsViewController'
|
||||
});
|
||||
})
|
||||
|
||||
.controller('AccountsViewController', function ($scope, AccountApi, AccountService, ngTableParams, toaster) {
|
||||
$scope.filter = {};
|
||||
$scope.accountsTable = new ngTableParams({
|
||||
page: 1, // show first page
|
||||
count: 10, // count per page
|
||||
sorting: {
|
||||
id: 'desc' // initial sorting
|
||||
},
|
||||
filter: $scope.filter
|
||||
}, {
|
||||
total: 0, // length of data
|
||||
getData: function ($defer, params) {
|
||||
AccountApi.getList(params.url()).then(
|
||||
function (data) {
|
||||
params.total(data.total);
|
||||
$defer.resolve(data);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$scope.remove = function (account) {
|
||||
account.remove().then(
|
||||
function () {
|
||||
$scope.accountsTable.reload();
|
||||
},
|
||||
function (response) {
|
||||
toaster.pop({
|
||||
type: 'error',
|
||||
title: 'Opps',
|
||||
body: 'I see what you did there' + response.data.message
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.toggleFilter = function (params) {
|
||||
params.settings().$scope.show_filter = !params.settings().$scope.show_filter;
|
||||
};
|
||||
|
||||
});
|
@ -1,44 +0,0 @@
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h2 class="featurette-heading">Accounts
|
||||
<span class="text-muted"><small>next in line please</small></span></h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<div class="btn-group pull-right">
|
||||
<a href="#/accounts/create" class="btn btn-primary">Create</a>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button ng-click="toggleFilter(accountsTable)" class="btn btn-default">Filter</button>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table ng-table="accountsTable" class="table table-striped" show-filter="false" template-pagination="angular/pager.html" >
|
||||
<tbody>
|
||||
<tr ng-repeat="account in $data track by $index">
|
||||
<td data-title="'Name'" sortable="'label'" filter="{ 'label': 'text' }">
|
||||
<ul class="list-unstyled">
|
||||
<li>{{ account.label }}</li>
|
||||
<li><span class="text-muted">{{ account.comments }}</span></li>
|
||||
</ul>
|
||||
</td>
|
||||
<td data-title="'Account Number'" sortable="'account_number'" filter="{ 'account_number': 'text' }">
|
||||
{{ account.accountNumber }}
|
||||
</td>
|
||||
<td data-title="''">
|
||||
<div class="btn-group-vertical pull-right">
|
||||
<a tooltip="Edit Account" href="#/accounts/{{ account.id }}/edit" class="btn btn-sm btn-info">
|
||||
Edit
|
||||
</a>
|
||||
<button tooltip="Delete Account" ng-click="remove(account)" type="button" class="btn btn-sm btn-danger pull-left">
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user