programa-content.controller.js
2.71 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
105
106
107
108
109
(function() {
'use strict';
angular
.module('dialoga')
.controller('ProgramaContentPageController', ProgramaContentPageController);
/** @ngInject */
function ProgramaContentPageController(DialogaService, $state, $scope, $rootScope, $element, $log) {
$log.debug('ProgramaContentPageController');
var vm = this;
vm.DialogaService = DialogaService;
vm.$state = $state;
vm.$scope = $scope;
vm.$rootScope = $rootScope;
vm.$element = $element;
vm.$log = $log;
vm.init();
vm.loadData();
vm.attachListeners();
}
ProgramaContentPageController.prototype.init = function() {
var vm = this;
vm.article = null;
vm.category = null;
vm.error = false;
};
ProgramaContentPageController.prototype.loadData = function() {
var vm = this;
vm.loading = true;
// Get program by slug
var slug = vm.$state.params.slug;
if(!slug){
vm.$log.error('slug not defined.');
vm.$log.info('Rollback to home page.');
vm.$state.go('inicio', {}, {location: true});
}
vm.DialogaService.getProgramBySlug(slug, function(article) {
vm.article = article;
vm.category = vm.article.categories[0];
// update the breadcrumb
vm.$rootScope.contentTitle = vm.article.title;
// set the banner image with full image path
if (!vm.banner) {
vm.banner = {
src: vm.$rootScope.basePath + vm.article.image.url,
alt: 'Imagem de destaque do conteúdo'
};
}
vm.DialogaService.getProposalsByTopicId(vm.article.id, {}, function(data){
vm.proposals = data.articles;
vm.proposalsTopRated = vm.proposals.slice(0, 3);
}, function (error) {
vm.$log.error(error);
});
// get random proposal
vm.DialogaService.getProposalsByTopicId(vm.article.id, {
'order': 'random()',
'limit': '1'
}, function(data){
vm.randomProposal = data.articles[0];
}, function (error) {
vm.$log.error(error);
});
vm.loading = false;
}, function(error) {
vm.$log.error(error);
vm.error = error;
vm.loading = false;
// vm.$log.info('Rollback to home page.');
// vm.$state.go('inicio', {}, {location: true});
});
};
ProgramaContentPageController.prototype.attachListeners = function() {
var vm = this;
vm.$scope.$on('proposal-carousel:toProposals', function() {
if(!vm._proposal_list){
vm._proposal_list = vm.$element.find('.proposal-ranking-section');
}
vm._proposal_list.slideToggle();
});
};
ProgramaContentPageController.prototype.makeProposal = function() {
var vm = this;
vm.$log.warn('Not implemented yet: "makeProposal"');
};
})();