| 1 |
(function ($) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
// Quick poll submit function |
| 5 |
$(document).find('#ays-save-quick-poll').on('click', function (e) { |
| 6 |
var $this = $(this); |
| 7 |
var title = $(document).find('#ays-quick-poll-title').val(); |
| 8 |
|
| 9 |
$this.attr('disabled', true); |
| 10 |
$this.addClass('quick-poll-save-disabled'); |
| 11 |
if (title == '') { |
| 12 |
swal.fire({ |
| 13 |
type: 'error', |
| 14 |
html: "<h2>Poll title can't be empty.</h2>", |
| 15 |
onAfterClose: function() { |
| 16 |
$this.removeClass('quick-poll-save-disabled'); |
| 17 |
$this.attr('disabled', false); |
| 18 |
} |
| 19 |
}); |
| 20 |
|
| 21 |
return false; |
| 22 |
} |
| 23 |
|
| 24 |
var questions = $(document).find('#ays-quick-poll-question').val(); |
| 25 |
var answersArr = $(document).find('.quick_poll_answer'); |
| 26 |
|
| 27 |
for (var i = 0; i < answersArr.length; i++) { |
| 28 |
if (answersArr.eq(i).val() == '') { |
| 29 |
swal.fire({ |
| 30 |
type: 'error', |
| 31 |
html: '<h2>You must fill all answers</h2>', |
| 32 |
onAfterClose: function() { |
| 33 |
$this.removeClass('quick-poll-save-disabled'); |
| 34 |
$this.attr('disabled', false); |
| 35 |
} |
| 36 |
}); |
| 37 |
return false; |
| 38 |
} else { |
| 39 |
answersArr[i] = answersArr.eq(i).val(); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
// var allowAnonimity = $(document).find('#allow_anonimity_switch').is(':checked') ? 1 : 0; |
| 44 |
var allowMultivote = $(document).find('#allow_multivote_switch').is(':checked') ? 'on' : 'off'; |
| 45 |
|
| 46 |
if (allowMultivote == 'on') { |
| 47 |
var multivote_min_count = $(document).find('#quick-poll-multivote-min-count').val(); |
| 48 |
var multivote_max_count = $(document).find('#quick-poll-multivote-max-count').val(); |
| 49 |
} else { |
| 50 |
var multivote_min_count = 1; |
| 51 |
var multivote_max_count = 1; |
| 52 |
} |
| 53 |
|
| 54 |
var wp_nonce = $(document).find('#ays_poll_ajax_quick_poll_nonce').val(); |
| 55 |
|
| 56 |
var showTitle = $(document).find('#quick-poll-show-title').is(':checked') ? 'on' : 'off'; |
| 57 |
|
| 58 |
var quickPollFormData = $('#ays-quick-poll-form').serializeFormJSON(); |
| 59 |
quickPollFormData.action = 'ays_poll_maker_quick_start'; |
| 60 |
quickPollFormData['quick-poll-show-title'] = showTitle; |
| 61 |
quickPollFormData._ajax_nonce = wp_nonce; |
| 62 |
|
| 63 |
$.ajax({ |
| 64 |
url: apm_ajax_obj.ajaxUrl, |
| 65 |
method: 'post', |
| 66 |
dataType: 'json', |
| 67 |
data: quickPollFormData, |
| 68 |
success: function (response) { |
| 69 |
$(document).find('div.ays-poll-preloader').css('display', 'none'); |
| 70 |
|
| 71 |
if (response.status == true) { |
| 72 |
$(document).find('#ays-quick-poll-form')[0].reset(); |
| 73 |
$(document).find('#ays-poll-quick-create .ays-modal-content').addClass('animated bounceOutRight'); |
| 74 |
$(document).find('#ays-poll-quick-create').modal('hide'); |
| 75 |
swal({ |
| 76 |
title: '<strong>Great job</strong>', |
| 77 |
type: 'success', |
| 78 |
html: '<p>Your Poll is Created!<br>Copy the generated shortcode and paste it into any post or page to display Poll.</p><input type="text" id="quick_poll_shortcode" onClick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_poll id="' + response.poll_id + '"]" /><p style="margin-top:1rem;">For more detailed configuration visit <a href="admin.php?page=poll-maker-ays&action=edit&poll=' + response.poll_id + '">edit poll page.</a></p>', |
| 79 |
showCloseButton: true, |
| 80 |
focusConfirm: false, |
| 81 |
confirmButtonText: '<i class="ays_poll_fas ays_poll_fa_thumbs_up "></i> Done', |
| 82 |
confirmButtonAriaLabel: 'Thumbs up, Done', |
| 83 |
onAfterClose: function() { |
| 84 |
$(document).find('#ays-poll-quick-create').removeClass('animated bounceOutRight'); |
| 85 |
$(document).find('#ays-poll-quick-create').css('display', 'none'); |
| 86 |
window.location.href = "admin.php?page=poll-maker-ays"; |
| 87 |
location.reload(); |
| 88 |
} |
| 89 |
}) |
| 90 |
} |
| 91 |
} |
| 92 |
}) |
| 93 |
|
| 94 |
}) |
| 95 |
|
| 96 |
})(jQuery) |
| 97 |
|