PluginProbe
Survey Maker by AYS / 5.2.2.5
Survey Maker by AYS v5.2.2.5
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / admin / js / survey-maker-admin-ajax.js

survey-maker-admin-ajax.js in Survey Maker by AYS 5.2.2.5, at admin/js/survey-maker-admin-ajax.js

296 lines 12.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2 'use strict';
3 $.fn.serializeFormJSON = function () {
4 let o = {},
5 a = this.serializeArray();
6 $.each(a, function () {
7 if (o[this.name]) {
8 if (!o[this.name].push) {
9 o[this.name] = [o[this.name]];
10 }
11 o[this.name].push(this.value || '');
12 } else {
13 o[this.name] = this.value || '';
14 }
15 });
16 return o;
17 };
18
19 $.fn.aysModal = function(action){
20 let $this = $(this);
21
22 var current_popup_id_attr = $this.attr('id');
23 var current_popup_id = "";
24 var current_popup_class = "";
25
26 if (current_popup_id_attr && current_popup_id_attr != "") {
27 current_popup_id = "overlay-" + current_popup_id_attr;
28 current_popup_class = "." + current_popup_id;
29 }
30
31 switch(action){
32 case 'hide':
33 $(this).find('.ays-modal-content').css('animation-name', 'zoomOut');
34 var removeIframe = $this.find('.ays-modal-body iframe');
35 if ( removeIframe.length > 0 ) {
36 $this.find('.ays-modal-body iframe').remove();
37 }
38 setTimeout(function(){
39 $(document.body).removeClass('modal-open');
40 $(document).find('.ays-modal-backdrop').remove();
41 $this.hide();
42 }, 250);
43 break;
44 case 'hide_remove_video':
45 $(this).find('.ays-modal-content').css('animation-name', 'zoomOut');
46 $this.find('.ays-modal-body iframe').remove();
47 setTimeout(function(){
48 $(document.body).removeClass('modal-open');
49 $(document).find('.ays-modal-backdrop'+ current_popup_class).remove();
50 $this.hide();
51 }, 250);
52 break;
53 case 'show_flex':
54 $this.css('display', 'flex');
55 $(this).find('.ays-modal-content').css('animation-name', 'zoomIn');
56 $(document).find('.modal-backdrop').remove();
57 $(document.body).append('<div class="ays-modal-backdrop '+ current_popup_id +'"></div>');
58 $(document.body).addClass('modal-open');
59 break;
60 case 'show':
61 default:
62 $this.show();
63 $(this).find('.ays-modal-content').css('animation-name', 'zoomIn');
64 $(document).find('.modal-backdrop').remove();
65 $(document.body).append('<div class="ays-modal-backdrop"></div>');
66 $(document.body).addClass('modal-open');
67 break;
68 }
69 };
70
71 $(document).on('click', '.ays-survey-apply-question-changes', function(e){
72 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
73 var editorPopup = $(document).find('#ays-edit-question-content');
74 var questionId = $(this).attr('data-question-id');
75 var questionName = $(this).attr('data-question-name');
76 var sectionId = $(this).attr('data-section-id');
77 var sectionName = $(this).attr('data-section-name');
78 var question = sectionCont.find('.ays-survey-section-box[data-id="'+sectionId+'"][data-name="'+sectionName+'"] .ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionName+'"]');
79
80 var editor = window.tinyMCE.get('ays_survey_question_editor');
81 var questionContent = '';
82
83 question.find('.ays-survey-open-question-editor-flag').val('on');
84
85 editorPopup.find('.ays-survey-preloader').css('display', 'flex');
86
87 if ( editorPopup.find("#wp-ays_survey_question_editor-wrap").hasClass("tmce-active")){
88 questionContent = editor.getContent();
89 }else{
90 questionContent = editorPopup.find('#ays_survey_question_editor').val();
91 }
92 var action = 'ays_survey_maker_live_preview_content';
93 var data = {};
94 data.action = action;
95 data.content = questionContent;
96 $.ajax({
97 url: ajaxurl,
98 method: 'post',
99 dataType: 'json',
100 data: data,
101 success: function(response) {
102 if (response.status) {
103 editorPopup.find('.ays-survey-preloader').css('display', 'none');
104 question.find('textarea.ays-survey-question-input-textarea').val( questionContent );
105 question.find('.ays-survey-question-preview-box').html( response.content );
106
107 question.find('.ays-survey-question-input-box').addClass('display_none');
108 question.find('.ays-survey-question-preview-box').removeClass('display_none');
109
110 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-id', '' );
111 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-name', '' );
112 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', '' );
113 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', '' );
114 var SurveyTinyMCE = window.tinyMCE.get('ays_survey_question_editor');
115 if(SurveyTinyMCE != null){
116 SurveyTinyMCE.setContent( '' );
117 }
118 else{
119 $(document).find('#ays_survey_question_editor').val(" ");
120 }
121
122 editorPopup.aysEditorModal('hide');
123 }
124 }
125 });
126 });
127
128 // Open results more information popup window
129 $(document).on('click', '.ays_survey_results', function(e){
130
131 if(!($(e.target).hasClass('ays_confirm_del') || $(e.target).hasClass('ays_result_delete'))){
132
133 e.preventDefault();
134
135 var this_element = $(this);
136
137 $(document).find('div.ays-survey-preloader').css('display', 'flex');
138 $(document).find('#ays-results-modal').aysModal('show');
139 var submission_id = $(this).find('.ays-show-results').data('result');
140 var surveyId = $(document).find('.ays_number_of_result').attr('data-id');
141 var wp_nonce = $(document).find('#ays_survey_ajax_results_nonce').val();
142 $.ajax({
143 url: ajaxurl,
144 method: 'post',
145 dataType: 'json',
146 data: {
147 action: 'ays_survey_show_results',
148 survey_id: surveyId,
149 submission_id: submission_id,
150 _ajax_nonce: wp_nonce,
151 },
152 success: function(response){
153 if(response.status === true){
154 $('div#ays-results-body').html(response.rows);
155 $(document).find('div.ays-survey-preloader').css('display', 'none');
156 if($(this_element).hasClass('ays_read_result')){
157 $(this_element).removeClass('ays_read_result');
158
159 var count = parseInt($(document).find('.ays-survey-results-bage').eq(0).text()) -1;
160 if(count == 0){
161 $(document).find('.ays-survey-results-bage').remove();
162 } else {
163 $(document).find('.ays-survey-results-bage').text(count);
164 }
165 }
166
167 }else{
168 swal.fire({
169 type: 'info',
170 html: "<h2>"+ SurveyMakerAdmin.loadResource +"</h2><br><h6>"+ SurveyMakerAdmin.dataDeleted +"</h6>",
171 confirmButtonText: SurveyMakerAdmin.okSurvey,
172
173 }).then(function(res) {
174 $(document).find('div.ays-survey-preloader').css('display', 'none');
175 if($(this_element).hasClass('ays_read_result')){
176 $(this_element).removeClass('ays_read_result');
177 var count = parseInt($(document).find('.ays-survey-results-bage').eq(0).text()) -1;
178 if(count == 0){
179 $(document).find('.ays-survey-results-bage').remove();
180 } else {
181 $(document).find('.ays-survey-results-bage').text(count);
182 }
183 }
184
185 $(document).find('.ays-modal').aysModal('hide');
186 });
187 }
188 },
189 error: function(){
190 swal.fire({
191 type: 'info',
192 html: "<h2>"+ SurveyMakerAdmin.loadResource +"</h2><br><h6>"+ SurveyMakerAdmin.dataDeleted +"</h6>",
193 confirmButtonText: SurveyMakerAdmin.okSurvey,
194 }).then(function(res) {
195 $(document).find('div.ays-survey-preloader').css('display', 'none');
196 if($(this_element).hasClass('ays_read_result')){
197 $(this_element).removeClass('ays_read_result');
198 var count = parseInt($(document).find('.ays-survey-results-bage').eq(0).text()) -1;
199 if(count == 0){
200 $(document).find('.ays-survey-results-bage').remove();
201 } else {
202 $(document).find('.ays-survey-results-bage').text(count);
203 }
204 }
205
206 $(document).find('.ays-modal').aysModal('hide');
207 });
208 }
209 });
210 }
211
212 })
213
214 $(document).on('click', '.ays-survey-plugin-btn', function(e) {
215 e.preventDefault();
216
217 var $button = $(this);
218 var action = $button.data('action');
219 var plugin = $button.data('plugin');
220
221 if (!action || !plugin || $button.prop('disabled')) {
222 return;
223 }
224
225 // Disable button and show loading
226 $button.prop('disabled', true);
227 var originalText = $button.text();
228 $button.html('<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
229
230 var ajaxAction = action === 'install' ? 'ays_survey_install_plugin' : 'ays_survey_activate_plugin';
231
232 $.ajax({
233 url: ajaxurl,
234 type: 'POST',
235 data: {
236 action: ajaxAction,
237 plugin_slug: plugin,
238 nonce: SurveyMakerAdmin.nonce
239 },
240 success: function(response) {
241 try {
242 var result = typeof response === 'string' ? JSON.parse(response) : response;
243
244 if (result.success) {
245 // Mark as activated immediately for both install and activate actions
246 $button.html(SurveyMakerAdmin.activated);
247 $button.removeClass('ays-survey-plugin-btn');
248 $button.prop('disabled', true);
249 $button.addClass('disabled');
250 } else {
251 $button.html(originalText);
252 $button.prop('disabled', false);
253 }
254 } catch (e) {
255 $button.html(originalText);
256 $button.prop('disabled', false);
257 }
258 },
259 error: function() {
260 $button.text(originalText);
261 $button.prop('disabled', false);
262 }
263 });
264 });
265
266 $(document).find('#ays_survey_change_create_author').select2({
267 placeholder: survey_maker_ajax.selectUser,
268 minimumInputLength: 1,
269 allowClear: true,
270 language: {
271 // You can find all of the options in the language files provided in the
272 // build. They all must be functions that return the string that should be
273 // displayed.
274 searching: function() {
275 return survey_maker_ajax.searching;
276 },
277 inputTooShort: function () {
278 return survey_maker_ajax.pleaseEnterMore;
279 }
280 },
281 ajax: {
282 url: survey_maker_ajax.ajax_url,
283 dataType: 'json',
284 data: function (response) {
285 var checkedUsers = $(document).find('#ays_survey_change_create_author').val();
286 return {
287 action: 'ays_survey_author_user_search',
288 search: response.term,
289 val: checkedUsers,
290 };
291 },
292 }
293 });
294
295 })( jQuery );
296