event-list.directive.js
1.95 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
(function() {
'use strict';
angular
.module('dialoga')
.directive('eventList', eventList);
/** @ngInject */
function eventList() {
/** @ngInject */
function EventListController(ArticleService, $scope, $rootScope, $state, $log) {
$log.debug('EventListController');
var vm = this;
vm.ArticleService = ArticleService;
vm.$scope = $scope;
vm.$rootScope = $rootScope;
vm.$state = $state;
vm.$log = $log;
vm.init();
// vm.attachListeners();
}
EventListController.prototype.init = function () {
var vm = this;
if(!vm.events){
throw { name: 'NotDefined', message: 'The attribute "events" is undefined.'};
}
if(!vm.isCollapsed){
vm.isCollapsed = true;
}
};
EventListController.prototype.toggleView = function () {
var vm = this;
vm.isCollapsed = !vm.isCollapsed;
};
EventListController.prototype.subscribe = function (event) {
var vm = this;
if(event.isOld){
vm.$log.debug('Event already happened. Abort.');
return;
}
var event_id = event.id;
vm.$log.debug('event_id', event_id);
if(!vm.$rootScope.currentUser){
vm.$log.info('User is not logged in. Redirect to Auth page.');
vm.$state.go('entrar',{
redirect_uri: 'state=inicio&task=subscribe&event_id=' + event_id
},{
location: true
});
}else{
vm.ArticleService.subscribeToEvent(event_id, {}, function(response){
vm.$log.debug('response', response);
}, function(error){
vm.$log.debug('error', error);
});
}
};
var directive = {
restrict: 'E',
templateUrl: 'app/components/event-list/event-list.html',
scope: {
events: '=',
isCollapsed: '='
},
controller: EventListController,
controllerAs: 'vm',
bindToController: true
};
return directive;
}
})();