voce/static/js/main.js

106 lines
3.5 KiB
JavaScript
Raw Normal View History

2015-09-24 18:42:56 +02:00
angular.module('voce',[
'ui.router',
'ui.bootstrap',
'angular-timeline'
])
.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider,$urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home',{
url: '/',
templateUrl: '/views/home.html',
controller: "HomeCtrl"
})
.state('revenue',{
url: '/revenue',
templateUrl: '/views/revenue.html',
controller: 'RevenueCtrl'
})
.state('expense',{
url: '/expense',
templateUrl: '/views/expense.html',
controller: 'ExpenseCtrl'
})
;
}])
.controller('HomeCtrl', ['$scope','$http','$state', function($scope,$http,$state) {
$scope.events = [];
$scope.income = {};
$scope.expense = {};
$scope.refreshValues = function () {
$http.get('/api/v1/post/')
.success(function (data) {
angular.forEach(data, function (val, key) {
if (val.amount > 0) {
$scope.events.push({
badgeClass: 'success',
badgeIconClass: 'glyphicon-plus',
title: val.amount,
content: val.note
});
} else {
$scope.events.push({
badgeClass: 'danger',
badgeIconClass: 'glyphicon-minus',
title: val.amount,
content: val.note
});
}
})
});
};
$scope.submitIncome = function () {
$scope.income.amount *= 1.0;
$http.put('/api/v1/post/', $scope.income);
$scope.income = {};
$state.go($state.current, {}, {reload: true});
};
$scope.submitExpense = function () {
$scope.expense.amount *= -1.0;
$http.put('/api/v1/post/', $scope.expense);
$scope.expense = {};
$state.go($state.current, {}, {reload: true});
};
$scope.refreshValues();
}])
.controller('RevenueCtrl',['$scope','$http', function ($scope, $http) {
$scope.revenues = [];
$scope.sum = 0.0;
$http.get('/api/v1/post/')
.success(function (data) {
angular.forEach(data, function (val, key) {
if (val.amount > 0) {
$scope.revenues.push(val);
$scope.sum += val.amount;
}
});
});
$scope.submitIncome = function () {
$scope.income.amount *= 1.0;
$http.put('/api/v1/post/', $scope.income);
$scope.income = {};
$state.go($state.current, {}, {reload: true});
};
}])
.controller('ExpenseCtrl',['$scope','$http', function ($scope, $http) {
$scope.expenses = [];
$scope.sum = 0.0;
$http.get('/api/v1/post/')
.success(function (data) {
angular.forEach(data, function (val, key) {
if (val.amount < 0) {
$scope.expenses.push(val);
$scope.sum += val.amount;
}
});
});
}])
;