forked from lesterchan/wp-polls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polls-admin-js.dev.js
219 lines (204 loc) · 7.75 KB
/
polls-admin-js.dev.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
var global_poll_id = 0;
var global_poll_aid = 0;
var global_poll_aid_votes = 0;
var count_poll_answer_new = 0;
var count_poll_answer = 3;
// Delete Poll
function delete_poll(poll_id, poll_confirm, nonce) {
delete_poll_confirm = confirm(poll_confirm);
if(delete_poll_confirm) {
global_poll_id = poll_id;
jQuery(document).ready(function($) {
$.ajax({type: 'POST', url: pollsAdminL10n.admin_ajax_url, data: 'do=' + pollsAdminL10n.text_delete_poll + '&pollq_id=' + poll_id + '&action=polls-admin&_ajax_nonce=' + nonce, cache: false, success: function (data) {
$('#message').html(data);
$('#message').show();
$('#poll-' + global_poll_id).remove();
}});
});
}
}
// Delete Poll Logs
function delete_poll_logs(poll_confirm, nonce) {
delete_poll_logs_confirm = confirm(poll_confirm);
if(delete_poll_logs_confirm) {
jQuery(document).ready(function($) {
if($('#delete_logs_yes').is(':checked')) {
$.ajax({type: 'POST', url: pollsAdminL10n.admin_ajax_url, data: 'do=' + pollsAdminL10n.text_delete_all_logs + '&delete_logs_yes=yes&action=polls-admin&_ajax_nonce=' + nonce, cache: false, success: function (data) {
$('#message').html(data);
$('#message').show();
$('#poll_logs').html(pollsAdminL10n.text_no_poll_logs);
}});
} else {
alert(pollsAdminL10n.text_checkbox_delete_all_logs);
}
});
}
}
// Delete Individual Poll Logs
function delete_this_poll_logs(poll_id, poll_confirm, nonce) {
delete_poll_logs_confirm = confirm(poll_confirm);
if(delete_poll_logs_confirm) {
jQuery(document).ready(function($) {
if($('#delete_logs_yes').is(':checked')) {
global_poll_id = poll_id;
$.ajax({type: 'POST', url: pollsAdminL10n.admin_ajax_url, data: 'do=' + pollsAdminL10n.text_delete_poll_logs + '&pollq_id=' + poll_id + '&delete_logs_yes=yes&action=polls-admin&_ajax_nonce=' + nonce, cache: false, success: function (data) {
$('#message').html(data);
$('#message').show();
$('#poll_logs').html(pollsAdminL10n.text_no_poll_logs);
$('#poll_logs_display').hide();
$('#poll_logs_display_none').show();
}});
} else {
alert(pollsAdminL10n.text_checkbox_delete_poll_logs);
}
});
}
}
// Delete Poll Answer
function delete_poll_ans(poll_id, poll_aid, poll_aid_vote, poll_confirm, nonce) {
delete_poll_ans_confirm = confirm(poll_confirm);
if(delete_poll_ans_confirm) {
global_poll_id = poll_id;
global_poll_aid = poll_aid;
global_poll_aid_votes = poll_aid_vote;
temp_vote_count = 0;
jQuery(document).ready(function($) {
$.ajax({type: 'POST', url: pollsAdminL10n.admin_ajax_url, data: 'do=' + pollsAdminL10n.text_delete_poll_ans + '&pollq_id=' + poll_id + '&polla_aid=' + poll_aid + '&action=polls-admin&_ajax_nonce=' + nonce, cache: false, success: function (data) {
$('#message').html(data);
$('#message').show();
$('#poll_total_votes').html((parseInt($('#poll_total_votes').html()) - parseInt(global_poll_aid_votes)));
$('#pollq_totalvotes').val(temp_vote_count);
$('#poll-answer-' + global_poll_aid).remove();
check_totalvotes();
reorder_answer_num();
}});
});
}
}
// Open Poll
function opening_poll(poll_id, poll_confirm, nonce) {
open_poll_confirm = confirm(poll_confirm);
if(open_poll_confirm) {
global_poll_id = poll_id;
jQuery(document).ready(function($) {
$.ajax({type: 'POST', url: pollsAdminL10n.admin_ajax_url, data: 'do=' + pollsAdminL10n.text_open_poll + '&pollq_id=' + poll_id + '&action=polls-admin&_ajax_nonce=' + nonce, cache: false, success: function (data) {
$('#message').html(data);
$('#message').show();
$('#open_poll').hide();
$('#close_poll').show();
}});
});
}
}
// Close Poll
function closing_poll(poll_id, poll_confirm, nonce) {
close_poll_confirm = confirm(poll_confirm);
if(close_poll_confirm) {
global_poll_id = poll_id;
jQuery(document).ready(function($) {
$.ajax({type: 'POST', url: pollsAdminL10n.admin_ajax_url, data: 'do=' + pollsAdminL10n.text_close_poll + '&pollq_id=' + poll_id + '&action=polls-admin&_ajax_nonce=' + nonce, cache: false, success: function (data) {
$('#message').html(data);
$('#message').show();
$('#open_poll').show();
$('#close_poll').hide();
}});
});
}
}
// Reoder Answer Answer
function reorder_answer_num() {
jQuery(document).ready(function($) {
var pollq_multiple = $('#pollq_multiple');
var selected = pollq_multiple.val();
var previous_size = $('> option', pollq_multiple).size();
pollq_multiple.empty();
$('#poll_answers tr > th').each(function (i) {
$(this).text(pollsAdminL10n.text_answer + ' ' + (i+1));
$(pollq_multiple).append('<option value="' + (i+1) + '">' + (i+1) + '</option>');
});
if(selected > 1)
{
var current_size = $('> option', pollq_multiple).size();
if(selected <= current_size)
$('> option', pollq_multiple).eq(selected - 1).attr('selected', 'selected');
else if(selected == previous_size)
$('> option', pollq_multiple).eq(current_size - 1).attr('selected', 'selected');
}
});
}
// Calculate Total Votes
function check_totalvotes() {
temp_vote_count = 0;
jQuery(document).ready(function($) {
$("#poll_answers tr td input[size=4]").each(function (i) {
if(isNaN($(this).val())) {
temp_vote_count += 0;
} else {
temp_vote_count += parseInt($(this).val());
}
});
$('#pollq_totalvotes').val(temp_vote_count);
});
}
// Add Poll's Answer In Add Poll Page
function add_poll_answer_add() {
jQuery(document).ready(function($) {
$('#poll_answers').append('<tr id="poll-answer-' + count_poll_answer + '"><th width="20%" scope="row" valign="top"></th><td width="80%"><input type="text" size="50" maxlength="200" name="polla_answers[]" /> <input type="button" value="' + pollsAdminL10n.text_remove_poll_answer + '" onclick="remove_poll_answer_add(' + count_poll_answer + ');" class="button" /></td></tr>');
count_poll_answer++;
reorder_answer_num();
});
}
// Remove Poll's Answer in Add Poll Page
function remove_poll_answer_add(poll_answer_id) {
jQuery(document).ready(function($) {
$('#poll-answer-' + poll_answer_id).remove();
reorder_answer_num();
});
}
// Add Poll's Answer In Edit Poll Page
function add_poll_answer_edit() {
jQuery(document).ready(function($) {
$('#poll_answers').append('<tr id="poll-answer-new-' + count_poll_answer_new + '"><th width="20%" scope="row" valign="top"></th><td width="60%"><input type="text" size="50" maxlength="200" name="polla_answers_new[]" /> <input type="button" value="' + pollsAdminL10n.text_remove_poll_answer + '" onclick="remove_poll_answer_edit(' + count_poll_answer_new + ');" class="button" /></td><td width="20%" align="' + pollsAdminL10n.text_direction + '">0 <input type="text" size="4" name="polla_answers_new_votes[]" value="0" onblur="check_totalvotes();" /></td></tr>');
count_poll_answer_new++;
reorder_answer_num();
});
}
// Remove Poll's Answer In Edit Poll Page
function remove_poll_answer_edit(poll_answer_new_id) {
jQuery(document).ready(function($) {
$('#poll-answer-new-' + poll_answer_new_id).remove();
check_totalvotes();
reorder_answer_num();
});
}
// Check Poll Whether It is Multiple Poll Answer
function check_pollq_multiple() {
jQuery(document).ready(function($) {
if(parseInt($('#pollq_multiple_yes').val()) == 1) {
$('#pollq_multiple').attr('disabled', false);
} else {
$('#pollq_multiple').val(1);
$('#pollq_multiple').attr('disabled', true);
}
});
}
// Show/Hide Poll's Timestamp
function check_polltimestamp() {
jQuery(document).ready(function($) {
if($('#edit_polltimestamp').is(':checked')) {
$('#pollq_timestamp').show();
} else {
$('#pollq_timestamp').hide();
}
});
}
// Show/Hide Poll's Expiry Date
function check_pollexpiry() {
jQuery(document).ready(function($) {
if($('#pollq_expiry_no').is(':checked')) {
$('#pollq_expiry').hide();
} else {
$('#pollq_expiry').show();
}
});
}