motmPoll.js
2.29 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
import '../../vendor/jquery.scrollTo-min';
angular.module('footyroom')
.directive('motmPoll', function () {
return {
templateUrl: '/views/ng/motm/poll.html?1',
scope: {
matchId: '=',
},
controllerAs: 'ctrl',
bindToController: true,
controller: ['$http', function ($http) {
var formationsEl = $('[motm-poll-formations]');
var ctrl = formationsEl.controller('formations').motm = this;
ctrl.poll = DataStore.manOfTheMatchPoll || {};
ctrl.hasVotes = function () {
return ctrl.poll.totalVotes > 0;
};
ctrl.vote = function () {
$('body').scrollTo(formationsEl, 300);
ctrl.voting = true;
};
ctrl.close = function () {
ctrl.voting = false;
};
ctrl.clickPlayer = function (player) {
$http.post('/vote', {
results: true,
limit: 5,
pollRef: 'motm-' + ctrl.matchId,
choices: [{
value: player.participant.name,
valueType: 'participant',
valueRef: player.participant.enetId,
}],
})
.success(function (response) {
ctrl.poll = response;
});
ctrl.close();
};
}],
};
})
.directive('motmPollFormations', function () {
return {
compile: function (tElement) {
var el = tElement.find('.formations');
el.attr(
'ng-class',
'[{"formations-motm": ctrl.motm.voting},' + el.attr('ng-class') + ']'
);
el.prepend(
'<div class="motm-formations-header" ng-if="ctrl.motm.voting">' +
'<span class="icn-close pointer" ng-click="ctrl.motm.close()"></span>' +
'<div>' +
'Cast your vote for Man of The Match by choosing any player below.' +
'</div>' +
'</div>'
);
el.find('.player--field, .substitute, .squad-player')
.attr('ng-click', 'ctrl.motm.voting && ctrl.motm.clickPlayer(player)')
.addClass('motm-eligible');
},
};
});