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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
var newUserDates = [];
var newUserTypes = [];
var max_votes = 0;
var values_changed = false;
$(document).ready(function () {
var cells = [];
cells = document.getElementsByClassName('cl_click');
// loop over 'user' cells
for (var i = 0; i < cells.length; i++){
// fill arrays (if this is edit)
if (cells[i].className.indexOf('poll-cell-active-not') >= 0){
newUserTypes.push(0);
newUserDates.push(cells[i].id);
} else if (cells[i].className.indexOf('poll-cell-active-is') >= 0){
newUserTypes.push(1);
newUserDates.push(cells[i].id);
} else if(cells[i].className.indexOf('poll-cell-active-maybe') >= 0){
newUserTypes.push(2);
newUserDates.push(cells[i].id);
} else {
newUserTypes.push(-1);
newUserDates.push(cells[i].id);
}
}
$('#submit_finish_vote').click(function() {
var form = document.finish_vote;
var ac = document.getElementById('user_name');
if (ac != null) {
if(ac.value.length >= 3){
form.elements['userId'].value = ac.value;
} else {
alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).'));
return;
}
}
check_notif = document.getElementById('check_notif');
form.elements['dates'].value = JSON.stringify(newUserDates);
form.elements['types'].value = JSON.stringify(newUserTypes);
form.elements['notif'].value = (check_notif && check_notif.checked) ? 'true' : 'false';
form.elements['changed'].value = values_changed ? 'true' : 'false';
form.submit();
});
$('#submit_send_comment').click(function() {
var form = document.send_comment;
var comm = document.getElementById('commentBox');
if(comm.value.length <= 0) {
alert(t('polls', 'Please add some text to your comment before submitting it.'));
return;
}
form.submit();
});
});
$(document).on('click', '.poll-cell-active-un', function(e) {
values_changed = true;
var ts = $(this).attr('id');
var index = newUserDates.indexOf(ts);
if(index > -1) {
newUserDates.splice(index, 1);
newUserTypes.splice(index, 1);
}
newUserDates.push(ts);
newUserTypes.push(2);
$(this).switchClass('poll-cell-active-un', 'poll-cell-active-maybe');
$(this).switchClass('icon-info', 'icon-more');
});
$(document).on('click', '.poll-cell-active-not', function(e) {
values_changed = true;
var ts = $(this).attr('id');
var index = newUserDates.indexOf(ts);
if(index > -1) {
newUserDates.splice(index, 1);
newUserTypes.splice(index, 1);
}
newUserDates.push(ts);
newUserTypes.push(2);
var total_no = document.getElementById('id_n_' + ts);
total_no.innerHTML = parseInt(total_no.innerHTML) - 1;
$(this).switchClass('poll-cell-active-not', 'poll-cell-active-maybe');
$(this).switchClass('icon-close', 'icon-more');
findNewMaxCount();
updateStrongCounts();
});
$(document).on('click', '.poll-cell-active-maybe', function(e) {
values_changed = true;
var ts = $(this).attr('id');
var index = newUserDates.indexOf(ts);
if(index > -1) {
newUserDates.splice(index, 1);
newUserTypes.splice(index, 1);
}
newUserDates.push(ts);
newUserTypes.push(1);
var total_yes = document.getElementById('id_y_' + ts);
total_yes.innerHTML = parseInt(total_yes.innerHTML) + 1;
$(this).switchClass('poll-cell-active-maybe', 'poll-cell-active-is');
$(this).switchClass('icon-more', 'icon-checkmark');
findNewMaxCount();
updateStrongCounts();
});
$(document).on('click', '.poll-cell-active-is', function(e) {
values_changed = true;
var ts = $(this).attr('id');
var index = newUserDates.indexOf(ts);
if(index > -1) {
newUserDates.splice(index, 1);
newUserTypes.splice(index, 1);
}
newUserDates.push(ts);
newUserTypes.push(0);
var total_yes = document.getElementById('id_y_' + ts);
var total_no = document.getElementById('id_n_' + ts);
total_yes.innerHTML = parseInt(total_yes.innerHTML) - 1;
total_no.innerHTML = parseInt(total_no.innerHTML) + 1;
$(this).switchClass('poll-cell-active-is', 'poll-cell-active-not');
$(this).switchClass('icon-checkmark', 'icon-close');
findNewMaxCount();
updateStrongCounts();
});
function findNewMaxCount(){
var cell_tot_y = document.getElementsByClassName('cl_total_y');
var cell_tot_n = document.getElementsByClassName('cl_total_n');
max_votes = 0;
for(var i=0; i<cell_tot_y.length; i++) {
var currYes = parseInt(cell_tot_y[i].innerHTML);
var currNo = parseInt(cell_tot_n[i].innerHTML);
var curr = currYes - currNo;
if(curr > max_votes) max_votes = curr;
}
}
function updateStrongCounts(){
var cell_tot_y = document.getElementsByClassName('cl_total_y');
var cell_tot_n = document.getElementsByClassName('cl_total_n');
for(var i=0; i<cell_tot_y.length; i++) {
var cell_win = document.getElementById('id_total_' + i);
var curr = parseInt(cell_tot_y[i].innerHTML) - parseInt(cell_tot_n[i].innerHTML);
if(curr < max_votes) {
cell_win.className = 'win_row';
cell_tot_y[i].style.fontWeight = 'normal';
}
else {
cell_tot_y[i].style.fontWeight = 'bold';
cell_win.className = 'win_row icon-checkmark';
}
}
}
|