diff --git a/accountant/frontend/static/js/months.js b/accountant/frontend/static/js/months.js deleted file mode 100644 index 93b0e83..0000000 --- a/accountant/frontend/static/js/months.js +++ /dev/null @@ -1,116 +0,0 @@ -/* - 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 . - */ -// Month object -function month() { - this.year = null; - this.month = null; -} - - -accountantApp.controller( - "MonthController", function($scope, $http, $rootScope) { - // Month store and selection - $scope.months = null; - $scope.month = null; - $scope.account = null; - - $scope.monthClass = function(month) { - if(month == $scope.month) { - return "active"; - } - }; - - // Function to load months - $scope.loadMonths = function(account) { - if(account) { - $scope.account = account; - } - - if($scope.account) { - $http.get("/api/accounts/" + $scope.account.id + "/months").success($scope.loadMonths_success); - } else { - $scope.$emit("monthsLoadedEvent", {account: null, month: null}); - } - }; - - $scope.loadMonths_success = function (data) { - // Update months - $scope.months = angular.fromJson(data); - - var monthToSelect = null; - - var today = new Date(); - var currentYear = today.getFullYear().toString(); - var currentMonth = (today.getMonth() + 1 < 10 ? "0" : "") + (today.getMonth() + 1); - var found = false; - - var lastIndex = 0; - - // Add current month if not present. - angular.forEach($scope.months, function(month) { - if(!found) { - if (month.year == currentYear && month.month == currentMonth) { - found = true; - } - - if (parseInt(month.year) < parseInt(currentYear) || (month.year == currentYear && parseInt(month.month) < parseInt(currentMonth))) { - lastIndex++; - } - } - }); - - if(!found) { - $scope.months.splice(lastIndex, 0, {year: currentYear, month: currentMonth}); - } - - // Find the new instance of the previously selected month. - angular.forEach($scope.months, function(month) { - // Reset selected month to the new instance corresponding to the old one - if($scope.month) { - if(month.year == $scope.month.year && month.month == $scope.month.month) { - monthToSelect = month; - } - } - - if(!monthToSelect && month.year == currentYear && month.month == currentMonth) { - monthToSelect = month; - } - }); - - // Set selected month to the last one if not yet selected. - if(!monthToSelect && $scope.months.length > 0) { - monthToSelect = $scope.months[$scope.months.length - 1]; - } - - // Reset to month to select - $scope.month = monthToSelect; - - $scope.$emit("monthsLoadedEvent", {account: $scope.account, month: $scope.month}); - }; - - // Callback function to select a new month. - $scope.selectMonth = function(month) { - if(month) { - $scope.month = month; - $scope.$emit("monthsLoadedEvent", {account: $scope.account, month: month}); - } - }; - - $rootScope.$on("accountsLoadedEvent", function(event, args) { - $scope.loadMonths(args.account); - }); -});