propostas.controller.js
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Controlador das páginas:
* - Propostas
* - Ranking
*/
(function() {
'use strict';
angular
.module('dialoga')
.controller('PropostasPageController', PropostasPageController);
/** @ngInject */
function PropostasPageController(DialogaService, $scope, $location, $filter, $log) {
var vm = this;
vm.DialogaService = DialogaService;
vm.$scope = $scope;
vm.$location = $location;
vm.$filter = $filter;
vm.$log = $log;
vm.init();
vm.loadData();
vm.attachListeners();
$log.debug('PropostasPageController');
}
PropostasPageController.prototype.init = function () {
var vm = this;
vm.themes = null;
vm.selectedTheme = null;
vm.proposals = null;
vm.filtredProposals = null;
vm.query = null;
vm.search = vm.$location.search();
vm.loading = null;
vm.error = null;
};
PropostasPageController.prototype.loadData = function () {
var vm = this;
vm.loading = true;
// load Proposals
vm.loadingProposals = true;
vm.DialogaService.getProposals({}, function(data){
vm.proposals = data.articles;
vm.filtredProposals = vm.proposals;
vm.loadingProposals = false;
vm.loading = false;
}, function (error) {
vm.error = error;
vm.$log.error(error);
vm.loadingProposals = false;
vm.loading = false;
});
// load themes
vm.loadingThemes = true;
vm.DialogaService.getThemes(function(themes){
vm.themes = themes;
vm.loadingThemes = false;
vm.loading = false;
}, function (error) {
vm.error = error;
vm.$log.error(error);
vm.loadingThemes = false;
vm.loading = false;
});
};
PropostasPageController.prototype.attachListeners = function() {
var vm = this;
vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) {
vm.selectedTheme = selectedCategory;
vm.$log.debug('vm.selectedTheme', vm.selectedTheme);
});
vm.$scope.$watch('pagePropostas.selectedTheme', function(newValue/*, oldValue*/) {
vm.search.tema = newValue ? newValue.slug : null;
vm.$location.search('tema', vm.search.tema);
vm.filtredProposals = vm.getFiltredProposals();
});
vm.$scope.$watch('pagePropostas.query', function(newValue/*, oldValue*/) {
vm.search.filtro = newValue ? newValue : null;
vm.$location.search('filtro', vm.search.filtro);
vm.filtredProposals = vm.getFiltredProposals();
});
};
PropostasPageController.prototype.getFiltredProposals = function() {
var vm = this;
return vm.proposals;
};
})();