diff --git a/brewman/brewman/static/scripts/angular_directive.js b/brewman/brewman/static/scripts/angular_directive.js
new file mode 100644
index 00000000..6376a691
--- /dev/null
+++ b/brewman/brewman/static/scripts/angular_directive.js
@@ -0,0 +1,55 @@
+var overlord_directive = angular.module('overlord.directive', []);
+overlord_directive.directive('autocomplete', function () {
+ var directiveDefinitionObject = {
+ restrict:'E',
+ replace:true,
+ transclude:true,
+ template:'',
+ link:function (scope, element, attrs) {
+ element.autocomplete({
+ source:function (request, response) {
+ $.ajax({
+ type:"POST",
+ url:attrs.url,
+ contentType:"application/json; charset=utf-8",
+ dataType:"json",
+ data:JSON.stringify({prefixText:request.term, count:20}),
+ success:function (data) {
+ response(data);
+ },
+ error:function (XMLHttpRequest, textStatus, errorThrown) {
+ showError(textStatus.responseText);
+ }
+ });
+ },
+ minLength:1,
+ autoFocus:true,
+ select:function (event, ui) {
+ scope[attrs.selname] = ui.item.label;
+ scope[attrs.selid] = ui.item.id;
+ scope.$apply();
+ }
+ });
+ }
+ };
+ return directiveDefinitionObject;
+});
+
+overlord_directive.directive('datepicker', function () {
+ var directiveDefinitionObject = {
+ restrict:'E',
+ replace:true,
+ transclude:true,
+ template:'',
+ link:function (scope, element, attrs) {
+ element.datepicker({
+ dateFormat:'dd-M-yy',
+ onSelect:function (dateText, inst) {
+ scope[attrs.model][attrs.prop] = dateText;
+ scope.$apply();
+ }
+ });
+ }
+ };
+ return directiveDefinitionObject;
+});
diff --git a/brewman/brewman/static/scripts/angular_filter.js b/brewman/brewman/static/scripts/angular_filter.js
new file mode 100644
index 00000000..9d534ec6
--- /dev/null
+++ b/brewman/brewman/static/scripts/angular_filter.js
@@ -0,0 +1,19 @@
+var overlord_filter = angular.module('overlord.filter', []);
+overlord_filter.filter('debit', function () {
+ return function (input) {
+ if (input == -1) {
+ return 'Cr';
+ } else if (input == 1) {
+ return 'Dr';
+ } else {
+ return '';
+ }
+ ;
+ };
+});
+
+overlord_filter.filter('posted', function () {
+ return function (input) {
+ return input == true ? 'Posted' : 'Post';
+ };
+});
diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js
new file mode 100644
index 00000000..f3809012
--- /dev/null
+++ b/brewman/brewman/static/scripts/angular_service.js
@@ -0,0 +1,41 @@
+var overlord_service = angular.module('overlord.service', []);
+
+overlord_service.factory('save_voucher', ['$http', function ($http) {
+ return function (scope) {
+ $http.post('', scope.voucher).
+ success(function (data, status) {
+ scope.voucher = data;
+ scope.toasts.push({Type:'Success', Message:data.Code});
+ }).
+ error(function (data, status) {
+ scope.toasts.push({Type:'Error', Message:data});
+ });
+ };
+}]);
+
+overlord_service.factory('delete_voucher', ['$http', function ($http) {
+ return function (scope) {
+ $http.post(delete_url, {}).
+ success(function (data, status) {
+ scope.voucher = {};
+ scope.toasts.push({Type:'Success', Message:data.Code});
+ }).
+ error(function (data, status) {
+ scope.toasts.push({Type:'Error', Message:data});
+ });
+ };
+}]);
+
+overlord_service.factory('post_voucher', ['$http', function ($http) {
+ return function (scope) {
+ $http.post(post_url, {}).
+ success(function (data, status) {
+ scope.voucher.Posted = true;
+ scope.voucher.Poster = data.name;
+ scope.toasts.push({Type:'Success', Message:data.Code});
+ }).
+ error(function (data, status) {
+ scope.toasts.push({Type:'Error', Message:data});
+ });
+ };
+}]);
diff --git a/brewman/brewman/static/scripts/autocomplete.js b/brewman/brewman/static/scripts/autocomplete.js
index 10506d46..02d809cf 100644
--- a/brewman/brewman/static/scripts/autocomplete.js
+++ b/brewman/brewman/static/scripts/autocomplete.js
@@ -1,73 +1,6 @@
-var myApp = angular.module('myApp', ['journalFilters']);
-myApp.directive('autocomplete', function () {
- var directiveDefinitionObject = {
- restrict:'E',
- replace:true,
- transclude:true,
- template:'',
- link:function (scope, element, attrs) {
- element.autocomplete({
- source:function (request, response) {
- $.ajax({
- type:"POST",
- url:attrs.url,
- contentType:"application/json; charset=utf-8",
- dataType:"json",
- data:JSON.stringify({prefixText:request.term, count:20}),
- success:function (data) {
- response(data);
- },
- error:function (XMLHttpRequest, textStatus, errorThrown) {
- alert("Due to unexpected errors we were unable to load data\n\r" + textStatus);
- }
- });
- },
- minLength:1,
- autoFocus:true,
- select:function (event, ui) {
- scope[attrs.selname] = ui.item.label;
- scope[attrs.selid] = ui.item.id;
- scope.$apply();
- }
- });
- }
- };
- return directiveDefinitionObject;
-});
+var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filter', 'overlord.service']);
-myApp.directive('datepicker', function () {
- var directiveDefinitionObject = {
- restrict:'E',
- replace:true,
- transclude:true,
- template:'',
- link:function (scope, element, attrs) {
- element.datepicker({
- dateFormat:'dd-M-yy',
- onSelect:function (dateText, inst) {
- scope[attrs.model][attrs.prop] = dateText;
- scope.$apply();
- }
- });
- }
- };
- return directiveDefinitionObject;
-});
-
-
-angular.module('journalFilters', []).filter('debit', function() {
- return function(input) {
- if (input == -1) {
- return 'Cr';
- } else if (input == 1) {
- return 'Dr';
- } else {
- return '';
- };
- };
-});
-
function AutoComplete(matchFieldName, lookupURL) {
$(matchFieldName).autocomplete({
source:function (request, response) {
@@ -82,11 +15,62 @@ function AutoComplete(matchFieldName, lookupURL) {
response(data);
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
- alert("Due to unexpected errors we were unable to load data\n\r" + textStatus);
+ showError(textStatus.responseText);
}
});
},
minLength:1,
- autoFocus:true
+ autoFocus:true
});
-}
\ No newline at end of file
+}
+
+
+//http://jsfiddle.net/tadchristiansen/gt92r/
+
+//