From 6edf83a3827ffe76b8c0ce6d7b052876f7fc2deb Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 13 Jun 2015 19:54:17 +0200 Subject: [PATCH] Change app and controller declaration. --- accountant/frontend/static/js/accounts.js | 6 +-- accountant/frontend/static/js/app.js | 49 ++++++++++++++++++ accountant/frontend/static/js/entries.js | 6 +-- accountant/frontend/static/js/months.js | 6 +-- accountant/frontend/static/js/scheduler.js | 5 +- accountant/frontend/templates/layout.html | 59 ++-------------------- 6 files changed, 64 insertions(+), 67 deletions(-) create mode 100644 accountant/frontend/static/js/app.js diff --git a/accountant/frontend/static/js/accounts.js b/accountant/frontend/static/js/accounts.js index 62042d2..3878833 100644 --- a/accountant/frontend/static/js/accounts.js +++ b/accountant/frontend/static/js/accounts.js @@ -25,7 +25,8 @@ function account() { }; // The AccountController. -var AccountController = function($scope, $http, $rootScope, $window) { +accountantApp.controller( + "AccountController", function($scope, $http, $rootScope, $window) { // Account store and selection $scope.account = null; $scope.accounts = []; @@ -193,5 +194,4 @@ var AccountController = function($scope, $http, $rootScope, $window) { $rootScope.$on("operationRemovedEvent", $scope.loadAccounts); $scope.loadAccounts(); -}; - +}); diff --git a/accountant/frontend/static/js/app.js b/accountant/frontend/static/js/app.js new file mode 100644 index 0000000..1946be9 --- /dev/null +++ b/accountant/frontend/static/js/app.js @@ -0,0 +1,49 @@ +/* + This file is part of Accountant. + + Accountant is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Accountant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with Accountant. If not, see . + */ +var accountantApp = angular.module("accountantApp", [ + "mgcrea.ngStrap" +]) + +.config(function($interpolateProvider, $httpProvider) { + $interpolateProvider.startSymbol('[['); + $interpolateProvider.endSymbol(']]'); + + $httpProvider.interceptors.push(function($q) { + return { + "response": function(response) { + console.debug(response) + if(response.data.ok == false) { + return $q.reject(response) + } + // TODO Intercept validation error. + return response; + }, + + "responseError": function(response) { + // TODO Intercept Authentication Required error + $.pnotify({ + type: "error", + title: response.data.title, + text: response.data.text, + width: 300 + }) + + return $q.reject(response); + } + }; + }); +}); diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 317d6c9..6b3c66e 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -14,7 +14,8 @@ You should have received a copy of the GNU Affero General Public License along with Accountant. If not, see . */ -var EntryController = function($scope, $http, $rootScope, $filter) { +accountantApp.controller( + "EntryController", function($scope, $http, $rootScope, $filter) { // Entry store and selection $scope.entries = []; $scope.categories = []; @@ -463,5 +464,4 @@ var EntryController = function($scope, $http, $rootScope, $filter) { $scope.$on("entriesLoadedEvent", function(event, args) { $scope.entriesLoaded(args.entries); }); -}; - +}); diff --git a/accountant/frontend/static/js/months.js b/accountant/frontend/static/js/months.js index 47824b7..93b0e83 100644 --- a/accountant/frontend/static/js/months.js +++ b/accountant/frontend/static/js/months.js @@ -21,7 +21,8 @@ function month() { } -var MonthController = function($scope, $http, $rootScope) { +accountantApp.controller( + "MonthController", function($scope, $http, $rootScope) { // Month store and selection $scope.months = null; $scope.month = null; @@ -112,5 +113,4 @@ var MonthController = function($scope, $http, $rootScope) { $rootScope.$on("accountsLoadedEvent", function(event, args) { $scope.loadMonths(args.account); }); -}; - +}); diff --git a/accountant/frontend/static/js/scheduler.js b/accountant/frontend/static/js/scheduler.js index 606375a..8deaf08 100644 --- a/accountant/frontend/static/js/scheduler.js +++ b/accountant/frontend/static/js/scheduler.js @@ -14,7 +14,8 @@ You should have received a copy of the GNU Affero General Public License along with Accountant. If not, see . */ -var SchedulerController = function($scope, $http, $rootScope, $filter) { +accountantApp.controller( + "SchedulerController", function($scope, $http, $rootScope, $filter) { // Operations store and selection $scope.operations = []; $scope.selectedOperation = null; @@ -194,4 +195,4 @@ var SchedulerController = function($scope, $http, $rootScope, $filter) { $rootScope.$on("accountsLoadedEvent", function(event, args){ $scope.loadOperations(args.account); }); -} +}); diff --git a/accountant/frontend/templates/layout.html b/accountant/frontend/templates/layout.html index 17f0b28..f438206 100644 --- a/accountant/frontend/templates/layout.html +++ b/accountant/frontend/templates/layout.html @@ -15,7 +15,7 @@ along with Accountant. If not, see . #} - + Entries @@ -83,65 +83,12 @@ {% block footer %}{% endblock %} - - - - - - - - - - - - - - - - - - - - - - - + - {% block js %}{% endblock %} +