diff --git a/brewman/brewman/static/partial/cost-center-detail.html b/brewman/brewman/static/partial/cost-center-detail.html
new file mode 100644
index 00000000..a416c29a
--- /dev/null
+++ b/brewman/brewman/static/partial/cost-center-detail.html
@@ -0,0 +1,16 @@
+
diff --git a/brewman/brewman/static/partial/cost-center-list.html b/brewman/brewman/static/partial/cost-center-list.html
new file mode 100644
index 00000000..cd7d96d4
--- /dev/null
+++ b/brewman/brewman/static/partial/cost-center-list.html
@@ -0,0 +1,13 @@
+
+
diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js
index 1db9e564..2371b571 100644
--- a/brewman/brewman/static/scripts/angular_service.js
+++ b/brewman/brewman/static/scripts/angular_service.js
@@ -100,7 +100,10 @@ overlord_service.factory('Permission', ['$resource', function ($resource) {
// TODO: Replace hardcoded url with route_url
overlord_service.factory('CostCenter', ['$resource', function ($resource) {
- return $resource('/CostCenters');
+ return $resource('/CostCenter/:id',
+ {id:'@CostCenterID'}, {
+ query:{method:'GET', params:{list:true}, isArray:true}
+ });
}]);
// TODO: Replace hardcoded url with route_url
diff --git a/brewman/brewman/static/scripts/autocomplete.js b/brewman/brewman/static/scripts/autocomplete.js
index f62db7b8..53fa8412 100644
--- a/brewman/brewman/static/scripts/autocomplete.js
+++ b/brewman/brewman/static/scripts/autocomplete.js
@@ -7,6 +7,9 @@
when('/Accounts', {templateUrl: '/partial/account-list.html', controller: AccountListCtrl}).
when('/Account/:id', {templateUrl: '/partial/account-detail.html', controller: AccountCtrl}).
+ when('/CostCenters', {templateUrl: '/partial/cost-center-list.html', controller: CostCenterListCtrl}).
+ when('/CostCenter/:id', {templateUrl: '/partial/cost-center-detail.html', controller: CostCenterCtrl}).
+
when('/Users', {templateUrl: '/partial/user-list.html', controller: UserListCtrl}).
when('/User/:id', {templateUrl: '/partial/user-detail.html', controller: UserCtrl});
// .otherwise({redirectTo: '/phones'});
diff --git a/brewman/brewman/static/scripts/cost-center.js b/brewman/brewman/static/scripts/cost-center.js
new file mode 100644
index 00000000..ea3748f8
--- /dev/null
+++ b/brewman/brewman/static/scripts/cost-center.js
@@ -0,0 +1,27 @@
+function CostCenterListCtrl($scope, CostCenter) {
+ $scope.info = CostCenter.query();
+}
+
+function CostCenterCtrl($scope, $routeParams, $location, CostCenter) {
+ $scope.cost_center = CostCenter.get({id: $routeParams.id});
+
+ $scope.save = function () {
+ $scope.cost_center.$save(function (u, putResponseHeaders) {
+ $scope.toasts.push({Type:'Success', Message:u.Code});
+ $location.path('/CostCenters')
+ }, function (data, status) {
+ $scope.toasts.push({Type:'Error', Message:data.data});
+ });
+ };
+
+ $scope.delete = function () {
+ $scope.cost_center.$delete(function (u, putResponseHeaders) {
+ $scope.toasts.push({Type:'Success', Message:''});
+ $location.path('/CostCenters')
+ }, function (data, status) {
+ $scope.toasts.push({Type:'Error', Message:data.data});
+ });
+ };
+ $('#txtLedger').focus();
+
+}
diff --git a/brewman/brewman/static/scripts/journal.js b/brewman/brewman/static/scripts/journal.js
index 7b7f0666..5a3020bf 100644
--- a/brewman/brewman/static/scripts/journal.js
+++ b/brewman/brewman/static/scripts/journal.js
@@ -1,6 +1,4 @@
function JournalCtrl($scope, $routeParams, $location, Voucher) {
- console.log('loading')
-
if (typeof $routeParams.id === 'undefined'){
$scope.voucher = Voucher.get({type:'Journal'});
} else {
diff --git a/brewman/brewman/templates/accounts/account_detail.mako b/brewman/brewman/templates/accounts/account_detail.mako
deleted file mode 100644
index 7cf2915c..00000000
--- a/brewman/brewman/templates/accounts/account_detail.mako
+++ /dev/null
@@ -1,71 +0,0 @@
-# -*- coding: utf-8 -*-
-<%inherit file="../base.mako"/>
-<%block name="header">
-
- ${h.ScriptLink(request, 'account.js')}
-
-%block>
-<%block name="content">
-
-%block>
\ No newline at end of file
diff --git a/brewman/brewman/templates/accounts/account_list.mako b/brewman/brewman/templates/accounts/account_list.mako
deleted file mode 100644
index 1e9f1933..00000000
--- a/brewman/brewman/templates/accounts/account_list.mako
+++ /dev/null
@@ -1,30 +0,0 @@
-# -*- coding: utf-8 -*-
-<%inherit file="../base.mako"/>
-<%block name="header">
-
- ${h.ScriptLink(request, 'account.js')}
-%block>
-<%block name="content">
-
-
-
-
- Name |
- Type |
- Is Active? |
- Cost Center |
-
-
-
-
- {{item.Name}} |
- {{item.Type}} |
- {{item.IsActive}} |
- {{item.CostCenter}} |
-
-
-
-%block>
\ No newline at end of file
diff --git a/brewman/brewman/templates/accounts/cost_center_edit.mako b/brewman/brewman/templates/accounts/cost_center_edit.mako
deleted file mode 100644
index e82fabdf..00000000
--- a/brewman/brewman/templates/accounts/cost_center_edit.mako
+++ /dev/null
@@ -1,21 +0,0 @@
-# -*- coding: utf-8 -*-
-<%inherit file="../base.mako"/>
-<%block name="content">
-
-
-%block>
\ No newline at end of file
diff --git a/brewman/brewman/templates/accounts/cost_center_list.mako b/brewman/brewman/templates/accounts/cost_center_list.mako
deleted file mode 100644
index 4cb87247..00000000
--- a/brewman/brewman/templates/accounts/cost_center_list.mako
+++ /dev/null
@@ -1,25 +0,0 @@
-# -*- coding: utf-8 -*-
-<%inherit file="../base.mako"/>
-<%block name="content">
-
-
-
-
- Cost CenterID |
- Code |
- Name |
-
-
-
- % for item in list:
-
- ${item.id} |
- ${item.code} |
- ${item.name} |
-
- % endfor
-
-
-
-
-%block>
\ No newline at end of file
diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako
index ebfcffe3..509341ea 100644
--- a/brewman/brewman/templates/angular_base.mako
+++ b/brewman/brewman/templates/angular_base.mako
@@ -41,6 +41,7 @@
${h.ScriptLink(request, 'account.js')}
${h.ScriptLink(request, 'user.js')}
+ ${h.ScriptLink(request, 'cost-center.js')}
diff --git a/brewman/brewman/views/account.py b/brewman/brewman/views/account.py
index fd0495f0..ac998e14 100644
--- a/brewman/brewman/views/account.py
+++ b/brewman/brewman/views/account.py
@@ -1,14 +1,11 @@
-import json
import uuid
from pyramid.response import Response
from pyramid.view import view_config
import transaction
-from brewman.helpers import Literal
from brewman.models.master import CostCenter, Ledger, LedgerType
from brewman.models.validation_exception import ValidationError
-from brewman.views import DecimalEncoder
@view_config(route_name='account_list', renderer='brewman:templates/angular_base.mako')
@view_config(request_method='GET', route_name='account_id', renderer='brewman:templates/angular_base.mako',
diff --git a/brewman/brewman/views/cost_center.py b/brewman/brewman/views/cost_center.py
index a27deab0..5aa8e6e5 100644
--- a/brewman/brewman/views/cost_center.py
+++ b/brewman/brewman/views/cost_center.py
@@ -1,65 +1,77 @@
import uuid
+from pyramid.response import Response
-from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config
import transaction
-from brewman.models import DBSession
from brewman.models.master import CostCenter
from brewman.models.validation_exception import ValidationError
-@view_config(request_method='GET', route_name='cost_center_id', renderer='brewman:templates/ledgers/cost_center_edit.mako')
-@view_config(request_method='GET', route_name='cost_center', renderer='brewman:templates/ledgers/cost_center_edit.mako')
-def cost_center_edit(request):
- id = request.matchdict.get('id', None)
- if id is None:
- item = CostCenter('(Auto)','')
- else:
- item = CostCenter.by_id(uuid.UUID(id))
- return {'title':'Hops n Grains - Blog',
- 'pageclass': "page-blogpost page-sidebar-right",
- 'pagecontentclass': "page-content grid_12",
- 'page_header': '',
- 'item': item}
+@view_config(route_name='cost_center_list', renderer='brewman:templates/angular_base.mako')
+@view_config(request_method='GET', route_name='cost_center_id', renderer='brewman:templates/angular_base.mako',
+ xhr=False)
+@view_config(request_method='GET', route_name='cost_center', renderer='brewman:templates/angular_base.mako',
+ xhr=False)
+def html(request):
+ return {}
-@view_config(request_method='POST', route_name='cost_center_id')
-@view_config(request_method='POST', route_name='cost_center')
-def cost_center_submit(request):
+
+@view_config(request_method='POST', route_name='cost_center_id', renderer='json', xhr=True)
+@view_config(request_method='POST', route_name='cost_center', renderer='json', xhr=True)
+def save_update(request):
try:
-
id = request.matchdict.get('id', None)
if id is None:
- item = CostCenter(0,request.POST['name']).create()
+ CostCenter(0, request.json_body['Name']).create()
else:
item = CostCenter.by_id(uuid.UUID(id))
- item.name = request.POST['name']
+ item.name = request.json_body['Name']
transaction.commit()
- url = request.route_url('cost_center_list')
- return HTTPFound(location=url)
+ return cost_center_info(item.id)
+ # url = request.route_url('account_list')
+ # return HTTPFound(location=url)
except ValidationError as ex:
-# request.session.flash(ex)
transaction.abort()
-# request.session.flash(ex.message)
- return request
-
-@view_config(route_name='cost_center_list', renderer='brewman:templates/ledgers/cost_center_list.mako', xhr=False)
-def cost_center_list(request):
- dbsession = DBSession()
- cost_centers = dbsession.query(CostCenter).all()
-
- return {'title':'Hops n Grains - Blog',
- 'pageclass': "page-blogpost page-sidebar-right",
- 'pagecontentclass': "page-content grid_12",
- 'page_header': '',
- 'list': cost_centers}
+ response = Response("Failed validation: {0}".format(ex.message))
+ response.status_int = 500
+ return response
-@view_config(request_method='GET', route_name='cost_center_list', renderer='json', xhr=True)
-def get(request):
- cost_centers = []
- for item in CostCenter.list():
- cost_centers.append({'CostCenterID': item.id, 'Name': item.name})
- return cost_centers
+@view_config(request_method='DELETE', route_name='cost_center_id', renderer='json', xhr=True)
+def delete(request):
+ id = request.matchdict.get('id', None)
+ if id is None:
+ response = Response("Cost Center is Null")
+ response.status_int = 500
+ return response
+ else:
+ response = Response("Cost Center deletion not implemented")
+ response.status_int = 500
+ return response
+
+@view_config(request_method='GET', route_name='cost_center_id', renderer='json', xhr=True)
+@view_config(request_method='GET', route_name='cost_center', renderer='json', xhr=True)
+def show(request):
+ list = request.GET.get('list', None)
+
+ if list:
+ list = CostCenter.list()
+ cost_centers = []
+ for item in list:
+ cost_centers.append({'CostCenterID': item.id, 'Name': item.name, 'Url': request.route_url('cost_center_id', id=item.id)})
+ return cost_centers
+ else:
+ id = request.matchdict.get('id', None)
+ id = None if id is None else uuid.UUID(id)
+ return cost_center_info(id)
+
+
+def cost_center_info(id):
+ if id is None:
+ return {}
+ else:
+ cost_center = CostCenter.by_id(id)
+ return {'CostCenterID': cost_center.id, 'Name': cost_center.name}