-
Notifications
You must be signed in to change notification settings - Fork 0
/
vote.js
51 lines (47 loc) · 2.04 KB
/
vote.js
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
$(function() {
$('.candidates_unselected').each(function() {
$(this).sortable({
connectWith: '#s' + $(this).attr('id').slice(1),
placeholder: "ui-state-highlight",
dropOnEmpty: true
});
});
$('.candidates_selected').each(function() {
$(this).sortable({
connectWith: '#u' + $(this).attr('id').slice(1),
placeholder: "ui-state-highlight",
dropOnEmpty: true
});
});
});
function submit_vote() {
var post_data = {};
var do_submit = true;
$('.candidates_selected').each(function() {
post_data[Number($(this).attr('id').slice(1))] = new Array();
var pref = 0;
$('li', this).each(function() {
post_data[Number($(this).parent().attr('id').slice(1))][pref] = Number($(this).attr('id').slice(1));
//alert('Election ' + $(this).parents('.election').attr('id').slice(1) + ' - Preference ' + pref + ' - ' + $(this).text());
pref++;
});
var required_preferences = $(this).parent().parent().children('.election_num_pos_hidden').text();
var actual_preferences = post_data[Number($(this).parent().parent().attr('id').slice(1))].length;
var election_title = $(this).parent().parent().children('.election_title_hidden').text();
if (actual_preferences < required_preferences) {
if (!confirm('You have only provided ' +
actual_preferences + ' preferences for ' + election_title +
'.\n\nYou must provide at least ' + required_preferences +
' preferences for your vote to count.\n\nClick Cancel to return to the voting screen, or click OK if you wish to cast an informal vote.')) {
do_submit = false;
return false;
}
}
});
//alert(JSON.stringify(post_data));
if (do_submit) {
$('#votestring').val(JSON.stringify(post_data));
$('#voteform').submit();
}
return false;
}