proposal-carousel.directive.js
2.31 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
(function() {
'use strict';
angular
.module('dialoga')
.directive('proposalCarousel', proposalCarousel);
/** @ngInject */
function proposalCarousel() {
/** @ngInject */
function ProposalCarouselController($scope, $state, $element, $timeout, $log) {
$log.debug('ProposalCarouselController');
var vm = this;
vm.$scope = $scope;
vm.$state = $state;
vm.$element = $element;
vm.$timeout = $timeout;
vm.$log = $log;
vm.init();
}
ProposalCarouselController.prototype.init = function () {
// initial values
var vm = this;
if(!vm.proposals){
throw { name: 'NotDefined', message: 'The attribute "proposals" is undefined.'};
}
vm.activeIndex = 0;
vm.archived = vm.archived || false;
vm.loading = false;
vm.proposalsLength = vm.proposals.length;
};
ProposalCarouselController.prototype.swipeLeft = function () {
var vm = this;
vm.activeIndex = (vm.activeIndex < vm.proposalsLength - 1) ? ++vm.activeIndex : 0;
};
ProposalCarouselController.prototype.swipeRight = function () {
var vm = this;
vm.activeIndex = (vm.activeIndex > 0) ? --vm.activeIndex : vm.proposalsLength - 1;
};
ProposalCarouselController.prototype.switchProposal = function (index) {
var vm = this;
if(index >= 0 && index < vm.proposalsLength) {
vm.activeIndex = index;
}else{
vm.$log.warn('[switchProposal] "index" not handled:', index);
}
};
ProposalCarouselController.prototype.showProposalsList = function () {
var vm = this;
// notify parents - handled by parents
vm.$scope.$emit('proposal-carousel:showProposalsList');
};
ProposalCarouselController.prototype.showContent = function (proposal) {
var vm = this;
vm.$state.go('programa', {
slug: proposal.parent.slug,
proposal_id: proposal.id
}, {
location: true,
reload: true
});
};
var directive = {
restrict: 'E',
templateUrl: 'app/components/proposal-carousel/proposal-carousel.html',
scope: {
archived: '=',
proposals: '='
},
controller: ProposalCarouselController,
controllerAs: 'vm',
bindToController: true
};
return directive;
}
})();