PluginProbe
Survey Maker by AYS / 5.2.2.0
Survey Maker by AYS v5.2.2.0
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.js

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

3,922 lines 221.6 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.goToTop = function() {
20 this.get(0).scrollIntoView({
21 block: "center",
22 behavior: "smooth"
23 });
24 }
25
26 $.fn.goTo = function() {
27 $('html, body').animate({
28 scrollTop: this.offset().top - 200 + 'px'
29 }, 'fast');
30 return this; // for chaining...
31 }
32
33 $.fn.goToNormal = function() {
34 $('html, body').animate({
35 scrollTop: this.offset().top - 200 + 'px'
36 }, 'normal');
37 return this; // for chaining...
38 }
39
40 $(document).ready(function () {
41
42 var maxInputVarsPannelBox = $(document).find('.ays-survey-general-action-max-inps-vars');
43 var maxInputVarsTabsBox = $(document).find('.ays-survey-max-inp-vars-tabs-box');
44 var maxInputVars = +maxInputVarsPannelBox.attr('data-max-inp-vars');
45 if(typeof maxInputVars != 'undefined' && maxInputVars){
46 var filledInputs = +$(':input').filter(function() {return this.value;}).length;
47
48 var calcVarsDiff = maxInputVars - filledInputs;
49 if(calcVarsDiff <= 200){
50 if(calcVarsDiff <= 0){
51 filledInputs = maxInputVars
52 }
53 maxInputVarsPannelBox.removeClass('display_none');
54 maxInputVarsTabsBox.removeClass('display_none');
55 var varsMessageText = SurveyMakerAdmin.maxInputVarsWarningMessage;
56 varsMessageText = varsMessageText.replace(/%f/g, maxInputVars);
57 varsMessageText = varsMessageText.replace(/%t/g, filledInputs);
58 maxInputVarsPannelBox.attr('data-content' , varsMessageText);
59 maxInputVarsTabsBox.find('.ays-survey-max-inp-vars-texts-content').text(varsMessageText);
60 }
61 }
62
63
64 setInterval(function () {
65 $('div.ays-quiz-maker-wrapper h1 i.ays_fa').toggleClass('pulse');
66 $(document).find('.ays_heart_beat i.ays_fa').toggleClass('ays_pulse');
67 }, 1000);
68
69
70 // Disabling submit when press enter button on inputing
71 $(document).on("input", 'input', function(e){
72 if(e.keyCode == 13){
73 if($(document).find("#ays-survey-form").length !== 0 ||
74 $(document).find("#ays-survey-category-form").length !== 0 ||
75 $(document).find("#ays-survey-settings-form").length !== 0){
76 return false;
77 }
78 }
79 });
80
81 $(document).on("keydown", function(e){
82 if(e.target.nodeName == "TEXTAREA"){
83 return true;
84 }
85 if(e.keyCode == 13){
86 if($(document).find("#ays-survey-form").length !== 0 ||
87 $(document).find("#ays-survey-category-form").length !== 0 ||
88 $(document).find("#ays-survey-settings-form").length !== 0){
89 return false;
90 }
91 }
92
93 if ( ( e.ctrlKey && e.which == 83 ) && !( e.which == 19 ) ){
94 var saveButton = $(document).find("input#ays-button-apply, input.ays-survey-gen-settings-save");
95 if( saveButton.length > 0 ){
96 e.preventDefault();
97 saveButton.trigger("click");
98 }
99 return false;
100 }
101
102 if(e.keyCode === 27){
103 $(document).find('.ays-modal').aysModal('hide');
104 return false;
105 }
106 });
107
108 var answerAddedByEnter = false;
109 $(document).on("keyup", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
110 answerAddedByEnter = false;
111 });
112
113 $(document).on("focus", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
114 var _this = $(this);
115 setTimeout(function(){
116 _this.get(0).setSelectionRange(0, _this.get(0).value.length);
117 // _this.select();
118 }, 1);
119 });
120
121 $(document).on("keydown", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
122 if( answerAddedByEnter === false ) {
123 answerAddedByEnter = true;
124
125 if(e.keyCode === 13){
126 aysSurveyAddAnswer( $(this), true );
127 }
128
129 if(e.keyCode == 38 && !e.ctrlKey && !e.shiftKey ){
130 var ansCont = $(this).parents('.ays-survey-answer-row');
131 if( ansCont.prev().length > 0 ){
132 ansCont.prev().find(".ays-survey-answer-box input.ays-survey-input").trigger('focus');
133 }else{
134 return false;
135 }
136 }
137
138 if(e.keyCode === 40 && !e.ctrlKey && !e.shiftKey ){
139 var ansCont = $(this).parents('.ays-survey-answer-row');
140 if( ansCont.next().length > 0 ){
141 ansCont.next().find(".ays-survey-answer-box input.ays-survey-input").trigger('focus');
142 }else{
143 var questCont = $(this).parents('.ays-survey-question-answer-conteiner');
144 questCont.find('.ays-survey-action-add-answer').trigger('click');
145 }
146 }
147
148 if(e.keyCode === 8){
149 if( $(this).val() == '' ){
150 var thatNext = $(this).parents('.ays-survey-answer-row').next().find('input.ays-survey-input');
151 var thatPrev = $(this).parents('.ays-survey-answer-row').prev().find('input.ays-survey-input');
152 if( thatPrev.length > 0 ){
153 thatPrev.trigger('focus');
154 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
155 }else if( thatNext.length > 0 ){
156 thatNext.trigger('focus');
157 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
158 }
159 return false;
160 }
161 }
162
163 if(e.keyCode === 46){
164 if( $(this).val() == '' ){
165 var thatNext = $(this).parents('.ays-survey-answer-row').next().find('input.ays-survey-input');
166 var thatPrev = $(this).parents('.ays-survey-answer-row').prev().find('input.ays-survey-input');
167 if( thatNext.length > 0 ){
168 thatNext.trigger('focus');
169 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
170 }else if( thatPrev.length > 0 ){
171 thatPrev.trigger('focus');
172 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
173 }
174 return false;
175 }
176 }
177 }
178 });
179
180 // Notifications dismiss button
181 var $html_name_prefix = 'ays_';
182 $(document).on('click', '.notice-dismiss', function (e) {
183 changeCurrentUrl('status');
184 });
185
186 if(location.href.indexOf('del_stat')){
187 setTimeout(function(){
188 changeCurrentUrl('del_stat');
189 changeCurrentUrl('mcount');
190 }, 500);
191 }
192
193 var aysSurveyTextArea = $(document).find('textarea.ays-survey-question-input-textarea');
194 autosize(aysSurveyTextArea);
195 var aysSurveyDescriptionTextArea = $(document).find('textarea.ays-survey-section-description');
196 autosize(aysSurveyDescriptionTextArea);
197
198
199 function changeCurrentUrl(key){
200 var linkModified = location.href.split('?')[1].split('&');
201 for(var i = 0; i < linkModified.length; i++){
202 if(linkModified[i].split("=")[0] == key){
203 linkModified.splice(i, 1);
204 }
205 }
206 linkModified = linkModified.join('&');
207 window.history.replaceState({}, document.title, '?'+linkModified);
208 }
209
210 // Quiz toast close button
211 jQuery('.quiz_toast__close').click(function(e){
212 e.preventDefault();
213 var parent = $(this).parent('.quiz_toast');
214 parent.fadeOut("slow", function() { $(this).remove(); } );
215 });
216
217 var toggle_ddmenu = $(document).find('.toggle_ddmenu');
218 toggle_ddmenu.on('click', function () {
219 var ddmenu = $(this).next();
220 var state = ddmenu.attr('data-expanded');
221 switch (state) {
222 case 'true':
223 $(this).find('.ays_fa').css({
224 transform: 'rotate(0deg)'
225 });
226 ddmenu.attr('data-expanded', 'false');
227 break;
228 case 'false':
229 $(this).find('.ays_fa').css({
230 transform: 'rotate(90deg)'
231 });
232 ddmenu.attr('data-expanded', 'true');
233 break;
234 }
235 });
236
237 var ays_results = $(document).find('.ays_result_read');
238 for (var i in ays_results) {
239 if (typeof ays_results.eq(i).val() != 'undefined') {
240 if ( ays_results.eq(i).val() == 0 || ays_results.eq(i).val() == 2 ) {
241 ays_results.eq(i).parents('tr').addClass('ays_read_result');
242 }
243 }
244 }
245
246 // Check if save button closed for unsaved changes confirmation box
247 var subButtons = '#ays_apply_top.button, #ays_apply.button, #ays_submit_top.button, #ays_submit.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-apply-top.button, #ays-button-apply.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-save.button, #ays-button-save-top.button, #ays-button.button';
248 $(document).on('click', subButtons ,function () {
249 var $this = $(this);
250 if(!$this.hasClass('ays-save-button-clicked')){
251 $this.addClass('ays-save-button-clicked');
252 }
253 });
254
255 setTimeout(function() {
256 var aysUnsavedChanges = false;
257
258 var selectorsArr = [
259 '#ays-survey-form .ays-survey-tab-content input',
260 '#ays-survey-form .ays-survey-tab-content select',
261 '#ays-survey-form .ays-survey-tab-content textarea',
262 '#ays-survey-category-form .ays-survey-tab-content input',
263 '#ays-survey-category-form .ays-survey-tab-content select',
264 '#ays-survey-category-form .ays-survey-tab-content textarea',
265 '#ays-survey-popup-surveys-form .ays-survey-tab-content input',
266 '#ays-survey-popup-surveys-form .ays-survey-tab-content select',
267 '#ays-survey-popup-surveys-form .ays-survey-tab-content textarea',
268 '#ays-survey-settings-form input',
269 '#ays-survey-settings-form select',
270 '#ays-survey-settings-form textarea',
271 ];
272
273 var formInputs = selectorsArr.join(',');
274
275 $(document).on('change input', formInputs, function() {
276 aysUnsavedChanges = true;
277 });
278
279 $(window).on('beforeunload', function(event) {
280 var saveButtons = $(document).find('#ays_apply_top.button, #ays_apply.button, #ays_submit_top.button, #ays_submit.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-apply-top.button, #ays-button-apply.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-save.button, #ays-button-save-top.button, #ays-button.button');
281 var savingButtonsClicked = saveButtons.filter('.ays-save-button-clicked').length > 0;
282
283 if (aysUnsavedChanges && !savingButtonsClicked) {
284 event.preventDefault();
285 event.returnValue = true;
286 }
287 });
288 }, 1000);
289
290
291 // $('[data-toggle="popover"]').popover();
292
293 $(document).find('.ays-survey-sections-conteiner [data-toggle="popover"]').popover();
294 $(document).find('.aysFormeditorViewFatRoot [data-toggle="popover"]').popover();
295 $(document).find('.ays_survey_previous_next [data-toggle="popover"]').popover();
296 $('[data-toggle="tooltip"]').tooltip();
297
298 $(document).find('.ays_survey_aysDropdown').aysDropdown();
299 $(document).find('[data-toggle="dropdown"]').dropdown();
300 // $('.dropdown-toggle').dropdown()
301
302 // Disabling submit when press enter button on inputing
303 $(document).on("input", 'input', function(e){
304 if(e.keyCode == 13){
305 if($(document).find("#ays-question-form").length !== 0 ||
306 $(document).find("#ays-survey-category-form").length !== 0 ||
307 $(document).find("#ays-survey-settings-form").length !== 0){
308 return false;
309 }
310 }
311 });
312
313 $(document).find('strong.ays-survey-shortcode-box.ays_survey_each_sub_user_info_header_button button').on('mouseleave', function(){
314 var _this = $(this);
315
316 _this.attr( 'data-original-title', SurveyMakerAdmin.clickForCopy );
317 _this.attr( 'title', SurveyMakerAdmin.clickForCopy );
318 });
319
320 // Modal close
321
322 $(document).find('.ays-close').on('click', function () {
323 $(document).find('.ays-modal').aysModal('hide');
324 });
325
326 $(document).find('.ays-close-editor-popup').on('click', function () {
327 $(document).find('.ays-modal').aysEditorModal('hide');
328 });
329
330 $(document).find('.ays-close-templates-popup').on('click', function (e) {
331 var $this = $(this);
332 var dataAction = $this.attr('data-action');
333 if(dataAction && dataAction !== 'ays-close-templates'){
334 e.preventDefault();
335 $(document).find('#ays-survey-templates-modal').aysModal('hide');
336 }
337
338 });
339
340 $(document).find('.ays-close-pro-popup').on('click', function () {
341 $(this).parents('.ays-modal').aysModal('hide_remove_video');
342 });
343
344
345 $(document).on('change', '.ays_toggle_checkbox', function (e) {
346 var state = $(this).prop('checked');
347 var parent = $(this).parents('.ays_toggle_parent');
348
349 if($(this).hasClass('ays_toggle_slide')){
350 switch (state) {
351 case true:
352 parent.find('.ays_toggle_target').slideDown(250);
353 break;
354 case false:
355 parent.find('.ays_toggle_target').slideUp(250);
356 break;
357 }
358 }else{
359 switch (state) {
360 case true:
361 parent.find('.ays_toggle_target').show(250);
362 break;
363 case false:
364 parent.find('.ays_toggle_target').hide(250);
365 break;
366 }
367 }
368 });
369
370 $(document).on('change', '.ays_toggle_select', function (e) {
371 var state = $(this).val();
372 var toggle = $(this).data('hide');
373 var parent = $(this).parents('.ays_toggle_parent');
374
375 if($(this).hasClass('ays_toggle_slide')){
376 if (toggle == state) {
377 parent.find('.ays_toggle_target').slideUp(250);
378 parent.find('.ays_toggle_target_inverse').slideDown(150);
379 }else{
380 parent.find('.ays_toggle_target').slideDown(150);
381 parent.find('.ays_toggle_target_inverse').slideUp(250);
382 }
383 }else{
384 if (toggle == state) {
385 parent.find('.ays_toggle_target').hide(150);
386 parent.find('.ays_toggle_target_inverse').show(250);
387 }else{
388 parent.find('.ays_toggle_target').show(250);
389 parent.find('.ays_toggle_target_inverse').hide(150);
390 }
391 }
392 });
393
394
395 $(document).find('#ays-category').select2({
396 placeholder: 'Select category'
397 });
398
399 $(document).find('#ays-status').select2({
400 placeholder: 'Select status'
401 });
402
403
404 // Tabulation
405 $(document).find('.nav-tab-wrapper a.nav-tab').on('click', function (e) {
406 if(! $(this).hasClass('no-js')){
407 var elemenetID = $(this).attr('href');
408 var active_tab = $(this).attr('data-tab');
409 $(document).find('.nav-tab-wrapper a.nav-tab').each(function () {
410 if ($(this).hasClass('nav-tab-active')) {
411 $(this).removeClass('nav-tab-active');
412 }
413 });
414 $(this).addClass('nav-tab-active');
415 $(document).find('.ays-survey-tab-content').each(function () {
416 $(this).css('display', 'none');
417 });
418 $(document).find("[name='ays_survey_tab']").val(active_tab);
419 $('.ays-survey-tab-content' + elemenetID).css('display', 'block');
420 e.preventDefault();
421 }
422 });
423
424
425 // Survey category form submit
426 // Checking the issues
427 $(document).find('#ays-survey-category-form').on('submit', function(e){
428 var submitFlag = true;
429 if($(document).find('#ays-title').val() == ''){
430 $(document).find('#ays-title').val('Survey category').trigger('input');
431 submitFlag = false;
432 }
433
434 var $this = $(this)[0];
435 if( submitFlag ){
436 $this.submit();
437 }else{
438 // e.preventDefault();
439 // $this.submit();
440 }
441 });
442
443 // Survey form submit
444 // Checking the issues
445 $(document).find('#ays-survey-form').on('submit', function(e){
446 var $this = $(this)[0];
447 var submitFlag = true;
448 if($(document).find('#ays-survey-title').val() == ''){
449 $(document).find('#ays-survey-title').val('Survey').trigger('input');
450 // submitFlag = false;
451 }
452
453 // $(document).find('.ays-survey-section-title').each(function(){
454 // if( $(this).val() == ''){
455 // $(this).val('Untitled section').trigger('input');
456 // // submitFlag = false;
457 // }
458 // });
459
460 if( submitFlag ){
461 $this.submit();
462 }else{
463 // e.preventDefault();
464 // $this.submit();
465 }
466 });
467
468 $(document).find('.ays-survey-copy-image').on('click', function(){
469 var _this = this;
470 var input = $(_this).parent().find('input.ays-survey-shortcode-input');
471 var length = input.val().length;
472
473 input[0].focus();
474 input[0].setSelectionRange(0, length);
475 document.execCommand('copy');
476 // document.getSelection().removeAllRanges();
477
478 $(_this).attr('data-original-title', SurveyMakerAdmin.copied);
479 $(_this).attr("data-bs-original-title", SurveyMakerAdmin.copied);
480 $(_this).attr("title", SurveyMakerAdmin.copied);
481 $(_this).tooltip('show');
482 });
483
484 $(document).find('.ays-survey-copy-image').on('mouseleave', function(){
485 var _this = this;
486
487 $(_this).attr('data-original-title', SurveyMakerAdmin.clickForCopy);
488 $(_this).attr("data-bs-original-title", SurveyMakerAdmin.clickForCopy);
489 $(_this).attr("title", SurveyMakerAdmin.clickForCopy);
490 });
491
492 // Submit buttons disableing with loader
493 $(document).find('.ays-survey-loader-banner').on('click', function () {
494 var $this = $(this);
495 submitOnce($this);
496 });
497
498 function submitOnce(subButton){
499 var subLoader = subButton.parents('div').find('.ays_survey_loader_box');
500 if ( subLoader.hasClass("display_none") ) {
501 subLoader.removeClass("display_none");
502 }
503 subLoader.css({
504 "padding-left": "8px",
505 "display": "inline-block"
506 });
507
508 setTimeout(function() {
509 $(document).find('.ays-survey-loader-banner').attr('disabled', true);
510 }, 10);
511
512 setTimeout(function() {
513 $(document).find('.ays-survey-loader-banner').attr('disabled', false);
514 subButton.parents('div').find('.ays_survey_loader_box').css('display', 'none');
515 }, 5000);
516
517 }
518
519 // Delete confirmation
520 $(document).on('click', '.ays_confirm_del', function(e){
521 e.preventDefault();
522 var message = $(this).data('message');
523 var confirm = window.confirm('Are you sure you want to delete '+message+'?');
524 if(confirm === true){
525 window.location.replace($(this).attr('href'));
526 }
527 });
528
529 // FILTERS FOR LIST TABEL
530 $(document).find('.ays-survey-question-tab-all-filter-button-top, .ays-survey-question-tab-all-filter-button-bottom').on('click', function(e){
531 e.preventDefault();
532 var $this = $(this);
533 var parent = $this.parents('.tablenav');
534 var link = location.href;
535
536 var html_name = '';
537 var top_or_bottom = 'top';
538
539 if ( parent.hasClass('bottom') ) {
540 top_or_bottom = 'bottom';
541 }
542
543 var catFilter = $(document).find('select[name="filterby-'+ top_or_bottom +'"]').val();
544 var userFilter = $(document).find('select[name="filterbyuser-'+ top_or_bottom +'"]').val();
545 var filterbyDescriptionFilter = $(document).find('select[name="filterbyDescription-'+ top_or_bottom +'"]').val();
546
547 if(typeof catFilter != "undefined"){
548 link = catFilterForListTable(link, {
549 what: 'filterby',
550 value: catFilter
551 });
552 }
553 if(typeof userFilter != "undefined"){
554 link = catFilterForListTable(link, {
555 what: 'filterbyuser',
556 value: userFilter
557 });
558 }
559 if(typeof filterbyDescriptionFilter != "undefined"){
560 link = catFilterForListTable(link, {
561 what: 'filterbyDescription',
562 value: filterbyDescriptionFilter
563 });
564 }
565 if($(this).hasClass('ays-survey-question-filter-each-submission')){
566 link = catFilterForListTable(link, {
567 what: 'ays_survey_tab',
568 value: 'poststuff'
569 });
570 }
571 document.location.href = link;
572 });
573
574 function catFilterForListTable(link, options){
575 if( options.value != '' ){
576 options.value = "&" + options.what + "=" + options.value;
577 var linkModifiedStart = link.split('?')[0];
578 var linkModified = link.split('?')[1].split('&');
579 for(var i = 0; i < linkModified.length; i++){
580 if(linkModified[i].split("=")[0] == options.what){
581 linkModified.splice(i, 1);
582 }
583 }
584 linkModified = linkModified.join('&');
585 return linkModifiedStart + "?" + linkModified + options.value;
586 }else{
587 var linkModifiedStart = link.split('?')[0];
588 var linkModified = link.split('?')[1].split('&');
589 for(var i = 0; i < linkModified.length; i++){
590 if(linkModified[i].split("=")[0] == options.what){
591 linkModified.splice(i, 1);
592 }
593 }
594 linkModified = linkModified.join('&');
595 return linkModifiedStart + "?" + linkModified;
596 }
597 }
598
599 $(document).on('change', '#import_file', function(e){
600 var pattern = /(.csv|.xlsx|.json)$/g;
601 if(pattern.test($(this).val())){
602 $(this).parents('form').find('input[name="ays_survey_import"]').removeAttr('disabled')
603 }
604 });
605
606
607 // Add Image
608 $(document).on('click', '.ays-survey-add-image', function (e) {
609 openMediaUploaderForImage(e, $(this));
610 });
611
612 // Remove Image
613 $(document).on('click', '.removeImage', function (e) {
614 var $this = $(this);
615 $this.parents('.ays-survey-image-container').find('.ays-survey-image-body').fadeOut(500);
616 $this.parents('.ays-survey-image-container').find('.ays-survey-add-image').text( SurveyMakerAdmin.addImage );
617 setTimeout(function(){
618 $(document).find("#ays_survey_logo_enable_image_url").prop("checked" , false);
619 $this.parents('.ays-survey-image-container').parent().find('.ays-survey-logo-open-close').hide();
620 $this.parents('.ays-survey-image-container').parent().find('.ays-survey-logo-open').hide();
621 $this.parents('.ays-survey-image-container').find('.ays-survey-img').removeAttr('src');
622 $this.parents('.ays-survey-image-container').find('.ays-survey-img-src').val('');
623 $(document).find('.ays-survey-logo-url-box').addClass('display_none_not_important');
624 }, 500);
625 });
626
627 /////////////////////////////////////////////////////////////////////////////////////////////
628 /////////////////////////////////////ARO START///////////////////////////////////////////////
629 /////////////////////////////////////////////////////////////////////////////////////////////
630 /////////////////////////////////////////////////////////////////////////////////////////////
631
632 function aysSurveyQuestionSortableHelper( event ) {
633 var clone = $(event.target).parents('.ays-survey-question-answer-conteiner').clone(true, true);
634 clone.find('.ays-survey-question-image-container').remove();
635 clone.find('.ays-survey-other-answer-and-actions-row').remove();
636 clone.find('.ays-survey-answers-conteiner').html('<div class="ays-survey-sortable-ect">…</div>');
637 return clone;
638 }
639
640 // Auto-scroll functionality for drag and drop
641 var autoScrollTimer = null;
642 var autoScrollSpeed = 10; // pixels per scroll
643 var autoScrollZone = 50; // pixels from edge to trigger scroll
644
645 function startAutoScroll(direction) {
646 if (autoScrollTimer) return; // Already scrolling
647
648 autoScrollTimer = setInterval(function() {
649 var currentScroll = $(window).scrollTop();
650 var newScroll = currentScroll + (direction * autoScrollSpeed);
651
652 // Ensure we don't scroll beyond document bounds
653 var maxScroll = $(document).height() - $(window).height();
654 newScroll = Math.max(0, Math.min(newScroll, maxScroll));
655
656 $(window).scrollTop(newScroll);
657 }, 16); // ~60fps
658 }
659
660 function stopAutoScroll() {
661 if (autoScrollTimer) {
662 clearInterval(autoScrollTimer);
663 autoScrollTimer = null;
664 }
665 }
666
667 function handleAutoScroll(event, ui) {
668 var mouseY = event.clientY || (event.originalEvent && event.originalEvent.clientY);
669 var windowHeight = $(window).height();
670
671 if (!mouseY) return;
672
673 // Check if mouse is near top or bottom of viewport
674 if (mouseY < autoScrollZone) {
675 // Near top - scroll up
676 startAutoScroll(-1);
677 } else if (mouseY > windowHeight - autoScrollZone) {
678 // Near bottom - scroll down
679 startAutoScroll(1);
680 } else {
681 // In middle zone - stop scrolling
682 stopAutoScroll();
683 }
684 }
685
686 var sectionDragHandle = {
687 handle: '.ays-survey-section-dlg-dragHandle',
688 appendTo: "parent",
689 cursor: 'move',
690 opacity: 0.8,
691 axis: 'y',
692 placeholder: 'ays-survey-sortable-placeholder',
693 tolerance: "pointer",
694 revert: true,
695 forcePlaceholderSize: true,
696 forceHelperSize: true,
697 // helper: aysSurveyQuestionSortableHelper,
698 sort: function(e, ui){
699 ui.placeholder.css('height', ui.helper.height());
700 handleAutoScroll(e, ui); // Add auto-scroll functionality
701 },
702 update: function( event, ui ){
703 var sortableContainer = $(event.target);
704 var sections = sortableContainer.find('.ays-survey-section-box');
705 sections.each(function(i){
706 $(this).find('.ays-survey-section-ordering').val(i+1);
707 $(this).find('.ays-survey-section-number').text(i+1);
708 });
709 },
710 stop: function(e, ui) {
711 stopAutoScroll(); // Stop auto-scroll when dragging ends
712 }
713 };
714
715 var questionDragHandle = {
716 handle: '.ays-survey-question-dlg-dragHandle',
717 appendTo: "parent",
718 cursor: 'move',
719 opacity: 0.8,
720 axis: 'y',
721 placeholder: 'ays-survey-sortable-placeholder',
722 tolerance: "pointer",
723 revert: true,
724 forcePlaceholderSize: true,
725 forceHelperSize: true,
726 helper: aysSurveyQuestionSortableHelper,
727 connectWith: '.ays-survey-sections-conteiner .ays-survey-section-questions',
728 sort: function(e, ui){
729 ui.placeholder.css('height', ui.helper.height());
730 handleAutoScroll(e, ui); // Add auto-scroll functionality
731 },
732 receive: function( event, ui ){
733 var section = $(event.target).parents('.ays-survey-section-box');
734 var oldSection = ui.sender.parents('.ays-survey-section-box');
735 draggedQuestionUpdate( ui.item, section, oldSection);
736 },
737 update: function( event, ui ){
738 var sortableContainer = $(event.target);
739 var oldSection = false;
740 if(ui.sender != null){
741 oldSection = ui.sender.parents('.ays-survey-section-box');
742 }
743 var questions = sortableContainer.find('.ays-survey-question-answer-conteiner');
744 if( questions.length == 0 ){
745 swal.fire({
746 type: 'warning',
747 text: SurveyMakerAdmin.minimumCountOfQuestions
748 });
749 setTimeout(function(){
750 draggedQuestionUpdate( ui.item, sortableContainer.parents('.ays-survey-section-box'), oldSection );
751 }, 1);
752 return false;
753 }
754 questions.each(function(i){
755 $(this).find('.ays-survey-question-ordering').val(i+1);
756 });
757 },
758 stop: function(e, ui) {
759 stopAutoScroll(); // Stop auto-scroll when dragging ends
760 }
761 };
762
763 var answerDragHandle = {
764 handle: '.ays-survey-answer-dlg-dragHandle',
765 cursor: 'move',
766 opacity: 0.8,
767 axis: 'y',
768 placeholder: 'clone',
769 tolerance: "pointer",
770 helper: "clone",
771 revert: true,
772 forcePlaceholderSize: true,
773 forceHelperSize: true,
774 sort: function(e, ui){
775 handleAutoScroll(e, ui); // Add auto-scroll functionality
776 },
777 update: function( event, ui ){
778 var sortableContainer = $(event.target);
779 var answers = sortableContainer.find('.ays-survey-answer-row');
780 answers.each(function(i){
781 $(this).find('.ays-survey-answer-ordering').val(i+1);
782 });
783 },
784 stop: function(e, ui) {
785 stopAutoScroll(); // Stop auto-scroll when dragging ends
786 }
787 }
788 // Answers ordering jQuery UI
789 $(document).find('.ays-survey-sections-conteiner .ays-survey-answers-conteiner').sortable(answerDragHandle);
790 // Question ordering jQuery UI
791 $(document).find('.ays-survey-sections-conteiner .ays-survey-section-questions').sortable(questionDragHandle);
792 // Question ordering jQuery UI
793 $(document).find('.ays-survey-sections-conteiner').sortable(sectionDragHandle);
794
795 // Collapse All
796 $(document).on('click', '.ays-survey-collapse-all', function (e) {
797 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
798 var sections = sectionCont.find('.ays-survey-section-box');
799 sections.each(function(){
800 var section = $(this);
801 section.find('.ays-survey-action-collapse-question').each(function(){
802 collapseQuestion( $(this) );
803 });
804 collapseSection( section.find('.ays-survey-action-collapse-section') );
805 });
806 });
807
808 // Expand All
809 $(document).on('click', '.ays-survey-expand-all', function (e) {
810 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
811 var sections = sectionCont.find('.ays-survey-section-box');
812 sections.each(function(){
813 var section = $(this);
814 section.find('.ays-survey-action-collapse-question').each(function(){
815 expandQuestion( $(this) );
816 });
817 expandSection( section.find('.ays-survey-action-expand-section') );
818 });
819 });
820
821 // Collapse Section Questions
822 $(document).on('click', '.ays-survey-collapse-sec-quests', function (e) {
823 var $this = $(this);
824 var section = $this.parents('.ays-survey-section-box');
825 section.find('.ays-survey-action-collapse-question').each(function(){
826 collapseQuestion( $(this) );
827 });
828 });
829
830 // Collapse Section Questions
831 $(document).on('click', '.ays-survey-section-questions-required', function (e) {
832 makeAllQuestionsRequired($(this) , true);
833 });
834
835 // Expand Section Questions
836 $(document).on('click', '.ays-survey-expand-sec-quests', function (e) {
837 var $this = $(this);
838 var section = $this.parents('.ays-survey-section-box');
839 section.find('.ays-survey-action-collapse-question').each(function(){
840 expandQuestion( $(this) );
841 });
842 });
843
844 // Collapse Question
845 $(document).on('click', '.ays-survey-action-collapse-question', function (e) {
846 var $this = $(this);
847 collapseQuestion( $this );
848 });
849
850 // Expand Question
851 $(document).on('click', '.ays-survey-action-expand-question, .ays-survey-question-wrap-collapsed-contnet', function (e) {
852 var $this = $(this);
853
854 if(!$(e.target).hasClass('dropdown-item')){
855 expandQuestion( $this );
856 }
857 });
858
859 // Collapse Section
860 $(document).on('click', '.ays-survey-action-collapse-section', function (e) {
861 var $this = $(this);
862 collapseSection( $this );
863 });
864
865 // Expand Section
866 $(document).on('click', '.ays-survey-action-expand-section', function (e) {
867 var $this = $(this);
868 expandSection( $this );
869 });
870
871
872 function collapseQuestion( _this ){
873 var questsCont = _this.parents('.ays-survey-question-answer-conteiner');
874 var questsText = questsCont.find('.ays-survey-question-input-textarea').val();
875 questsCont.find('.ays-survey-question-wrap-collapsed-contnet-text').text( questsText );
876 questsCont.find('.ays-survey-question-wrap-collapsed').removeClass('display_none');
877 questsCont.find('.ays-survey-question-wrap-expanded').addClass('display_none');
878 questsCont.find('.ays-survey-question-collapsed-input').val('collapsed');
879 aysSurveySectionsInitQuestionsCollapse();
880 }
881
882 function expandQuestion( _this ){
883 var questsCont = _this.parents('.ays-survey-question-answer-conteiner');
884 questsCont.find('.ays-survey-question-wrap-collapsed').addClass('display_none');
885 questsCont.find('.ays-survey-question-wrap-expanded').removeClass('display_none');
886 questsCont.find('.ays-survey-question-collapsed-input').val('expanded');
887 aysSurveySectionsInitQuestionsCollapse();
888 aysAutosizeUpdate();
889 }
890
891 function collapseSection( _this ){
892 var sectionCont = _this.parents('.ays-survey-section-box');
893 var sectionText = sectionCont.find('.ays-survey-section-title').val();
894 sectionCont.find('.ays-survey-section-wrap-collapsed-contnet-text').text( sectionText );
895 sectionCont.find('.ays-survey-section-wrap-collapsed').removeClass('display_none');
896 sectionCont.find('.ays-survey-section-wrap-expanded').addClass('display_none');
897 sectionCont.find('.ays-survey-section-collapsed-input').val('collapsed');
898 }
899
900 function expandSection( _this ){
901 var sectionCont = _this.parents('.ays-survey-section-box');
902 sectionCont.find('.ays-survey-section-wrap-collapsed').addClass('display_none');
903 sectionCont.find('.ays-survey-section-wrap-expanded').removeClass('display_none');
904 sectionCont.find('.ays-survey-section-collapsed-input').val('expanded');
905 aysAutosizeUpdate();
906 }
907
908 function aysAutosizeUpdate(){
909 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
910 var aysSurveyQuestionTextArea = sectionCont.find('textarea.ays-survey-question-input-textarea');
911 var aysSurveySectionDescriptionTextArea = sectionCont.find('textarea.ays-survey-section-description');
912 autosize.update(aysSurveyQuestionTextArea);
913 autosize.update(aysSurveySectionDescriptionTextArea);
914 }
915
916 // Add Question and Answer Image
917 $(document).on('click', '.ays-survey-add-question-image, .ays-survey-add-answer-image', function (e) {
918 var dataType = $(this).data('type');
919 openMediaUploader(e, $(this), dataType);
920 });
921
922 // Add Answer Button
923 $(document).on('click', '.ays-survey-action-add-answer', function(e){
924 var $this = $(this);
925 aysSurveyAddAnswer( $this, false );
926 });
927
928 // Delete Answer Button
929 $(document).on('click', '.ays-survey-answer-delete', function(e){
930 var $this = $(this);
931 var itemId = $this.parents('.ays-survey-question-answer-conteiner').data('id');
932 var answerId = $this.parents('.ays-survey-answer-row').data('id');
933 var length = $this.parents('.ays-survey-answers-conteiner').find('.ays-survey-answer-delete').length - 1;
934 var parent = $this.parents('.ays-survey-answers-conteiner');
935 var hideDeleteButton = parent.find('.ays-survey-answer-delete');
936
937 if(length == 1){
938 hideDeleteButton.css('visibility','hidden');
939 }else{
940 hideDeleteButton.removeAttr('style');
941 }
942 if( ! $this.parents('.ays-survey-answer-row').hasClass('ays-survey-new-answer') ){
943 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
944 $this.parents('form').append( delImp );
945 }
946
947 $this.parents('.ays-survey-answer-row [data-toggle="popover"]').popover('hide');
948 $this.parents('.ays-survey-answer-row').remove();
949
950 parent.find('.ays-survey-answer-ordering').each(function(i){
951 $(this).val( i + 1 );
952 });
953 });
954
955 // Add "Other" Answer
956 $(document).on('click', '.ays-survey-other-answer-add', function(e){
957 var $this = $(this);
958 var parent = $this.parents('.ays-survey-question-answer-conteiner');
959 var checkbox = parent.find('.ays-survey-other-answer-checkbox').attr('checked', 'checked');
960 var oterAnswer = parent.find('.ays-survey-other-answer-row');
961 oterAnswer.removeAttr('style');
962 $this.parents('.ays-survey-other-answer-add-wrap').css('display','none');
963 });
964
965 // Delete "Other" Answer
966 $(document).on('click', '.ays-survey-other-answer-delete', function(e){
967 var $this = $(this);
968 var parent = $this.parents('.ays-survey-question-answer-conteiner');
969 var checkbox = parent.find('.ays-survey-other-answer-checkbox').removeAttr('checked');
970 var oterAnswer = parent.find('.ays-survey-other-answer-row');
971 oterAnswer.css('display','none');
972 parent.find('.ays-survey-other-answer-add-wrap').removeAttr('style');
973 });
974
975 // Dublicate Question Button
976 $(document).on('click', '.ays-survey-action-duplicate-question', function(e){
977 var $this = $(this);
978 var sectionId = $this.parents('.ays-survey-section-box').attr('data-id');
979 var thisSection = $this.parents('.ays-survey-section-box');
980 var sectionName = $this.parents('.ays-survey-section-box').attr('data-name');
981 var cloningElement = $this.parents('.ays-survey-question-answer-conteiner');
982 var itemId = cloningElement.data('id');
983 var question_length = cloningElement.parent().find('.ays-survey-question-answer-conteiner').length + 1;
984 var question_type = cloningElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('get value');
985
986 // var questionsCount = questionsLength;
987 var questionsCountBox = thisSection.find(".ays-survey-action-questions-count span").text(question_length);
988
989 cloningElement.find('.ays-survey-question-type').aysDropdown('destroy');
990 var clonedLimitBy = cloningElement.find('.ays-survey-question-word-limit-by-select select').val();
991
992 var clone = cloningElement.clone(true, false).attr('data-id', question_length).addClass('ays-survey-new-question').insertAfter( cloningElement );
993 var newElement = $this.parents('.ays-survey-section-box').find('.ays-survey-question-answer-conteiner.ays-survey-new-question[data-id = '+ question_length +']');
994
995 newElement.attr('data-id', question_length);
996 newElement.data('id', question_length);
997 newElement.attr('data-name', 'questions_add');
998 newElement.find('input[name="ays_question_ids[]"]').remove();
999 newElement.find('textarea.ays-survey-question-input.ays-survey-input').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'title') );
1000 newElement.find('input.ays-survey-question-img-src').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'image') );
1001 newElement.find('input.ays-survey-input-required-question').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'required') );
1002 newElement.find('input.ays-survey-question-ordering').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'ordering') );
1003 newElement.find('input.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'collapsed'));
1004 newElement.find('input.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'user_variant') );
1005 newElement.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_max_selection_count'));
1006 newElement.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'max_selection_count'));
1007 newElement.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'min_selection_count'));
1008 // Text limitation options
1009 newElement.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, question_length, 'options', 'enable_word_limitation'));
1010 newElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'limit_by'));
1011 newElement.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'limit_length'));
1012 newElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'limit_counter'));
1013 // Number limitation options start
1014 newElement.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, question_length, 'options', 'enable_number_limitation'));
1015 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_min_selection'));
1016 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_max_selection'));
1017 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_error_message'));
1018 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_number_error_message'));
1019 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_limit_length'));
1020 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_number_limit_counter'));
1021 // Number limitation options end
1022
1023 newElement.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_admin_note'));
1024 newElement.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'admin_note'));
1025
1026 // Star start
1027 newElement.find('select.ays-survey-choose-for-select-lenght').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'scale_length'));
1028 newElement.find('input.ays-survey-input-star-1').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'star_1'));
1029 newElement.find('input.ays-survey-input-star-2').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'star_2'));
1030 newElement.find('select.ays-survey-choose-for-start-select-lenght').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'star_scale_length'));
1031 // Star end
1032
1033 // Input types placeholders
1034 newElement.find('.ays-survey-remove-default-border.ays-survey-question-types-input.ays-survey-question-types-input-with-placeholder').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'placeholder'));
1035
1036 newElement.find('input.ays-survey-question-image-caption').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'image_caption') );
1037 newElement.find('input.ays-survey-question-img-caption-enable').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'image_caption_enable') );
1038
1039 newElement.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'with_editor'));
1040 if( newElement.find('select.ays-survey-question-type').length ){
1041 newElement.find('select.ays-survey-question-type').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'type') );
1042 }else if( newElement.find('.ays-survey-question-type select').length ){
1043 newElement.find('.ays-survey-question-type select').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'type') );
1044 }
1045 var ddElem = newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('get text');
1046 newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('set text', ddElem);
1047 newElement.find('.ays-survey-question-conteiner .ays-survey-question-type select option[value="'+question_type+'"]').prop('selected', true);
1048 // newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('set selected', question_type);
1049 newElement.find('.ays_question_ids').val(question_length);
1050 newElement.find('.ays_question_old_ids').remove();
1051
1052 var answer = newElement.find('.ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input').each(function(i){
1053 $(this).parents('.ays-survey-answer-row').attr( 'data-id', i+1 );
1054 $(this).parents('.ays-survey-answer-row').attr( 'data-name', 'answers_add' );
1055 $(this).parents('.ays-survey-answer-row').addClass('ays-survey-new-answer');
1056 $(this).attr('name', newAnswerAttrName( sectionName, sectionId, newElement.attr('data-name'), question_length, i+1, 'title') );
1057 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, newElement.attr('data-name'), question_length, i+1, 'image') );
1058 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, newElement.attr('data-name'), question_length, i+1, 'ordering') );
1059 });
1060
1061 newElement.find('.ays-survey-answers-conteiner').sortable(answerDragHandle);
1062 newElement.find('.ays-survey-question-word-limit-by-select select option[value="'+clonedLimitBy+'"]').prop('selected', true);
1063
1064 if( question_type == 'select' ){
1065 newElement.find('.ays-survey-other-answer-row').hide();
1066 newElement.find('.ays-survey-other-answer-checkbox').prop('checked', false );
1067 newElement.find('.ays-survey-other-answer-add-wrap').hide();
1068 }
1069
1070 newElement.find('.ays-survey-question-type').aysDropdown();
1071 cloningElement.find('.ays-survey-question-type').aysDropdown();
1072
1073 var aysSurveyTextArea = newElement.find('textarea.ays-survey-question-input-textarea');
1074 autosize(aysSurveyTextArea);
1075 if( newElement.find('.dropdown .divider').length == 0 ){
1076 newElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1077 newElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1078 }
1079 if( cloningElement.find('.dropdown .divider').length == 0 ){
1080 cloningElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1081 cloningElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1082 }
1083 $this.parents('.ays-survey-section-box').find('.ays-survey-question-ordering').each(function(i){
1084 $(this).val(i+1);
1085 });
1086 // newElement.find('.ays-survey-question-type').dropdown('refresh');
1087 // var answerImg = newElement.find('.aysFormeditorAnswerConteiner input.quantumWizTextinputSimpleinputInput').each(function(i){
1088 // $(this).attr('name', $html_name_prefix + 'section_add['+ sectionId +'][question]['+ question_length +'][answer]['+ i +'][title]');
1089 // });
1090
1091 setTimeout(function(){
1092 newElement.goToTop();
1093 }, 100 );
1094
1095 reInitPopovers( newElement );
1096 aysSurveySectionsInitQuestionsCollapse();
1097 });
1098
1099 // Remove Question Button
1100 $(document).on('click', '.ays-survey-action-delete-question', function(e){
1101 var $this = $(this);
1102 var length = $this.parents('.ays-survey-section-questions').find('.ays-survey-question-answer-conteiner').length;
1103 var status = true;
1104 if(length == 1){
1105 swal.fire({
1106 type: 'warning',
1107 text: SurveyMakerAdmin.minimumCountOfQuestions
1108 });
1109 status = false;
1110 }else{
1111 swal({
1112 html:"<h4>"+ SurveyMakerAdmin.questionDeleteConfirmation +"</h4>",
1113 type: 'error',
1114 showCloseButton: true,
1115 showCancelButton: true,
1116 allowOutsideClick: true,
1117 allowEscapeKey: true,
1118 allowEnterKey: true,
1119 confirmButtonColor: '#d33',
1120 cancelButtonColor: '#3085d6',
1121 confirmButtonText: SurveyMakerAdmin.yes,
1122 cancelButtonText: SurveyMakerAdmin.cancel
1123 }).then( function(result) {
1124
1125 if( result.dismiss && result.dismiss == 'close' ){
1126 return false;
1127 }
1128
1129 var deleteQuest = false;
1130 if (result.value) deleteQuest = true;
1131
1132 if( deleteQuest ){
1133 if( ! $this.parents('.ays-survey-question-answer-conteiner').hasClass('ays-survey-new-question') ){
1134 var qId = $this.parents('.ays-survey-question-answer-conteiner').data('id');
1135 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'questions_delete[]" value="'+ qId +'">';
1136 $this.parents('form').append( delImp );
1137 }
1138 var section = $this.parents('.ays-survey-section-box');
1139 section.find(".ays-survey-action-questions-count span").text(length - 1);
1140 $this.parents('.ays-survey-question-answer-conteiner').remove();
1141 }
1142 } );
1143 }
1144
1145 if (status == false) {
1146 e.preventDefault();
1147 }
1148
1149 });
1150
1151 // Remove Section Button
1152 $(document).on('click', '.ays-survey-delete-section', function(e){
1153 var $this = $(this);
1154
1155 swal({
1156 html:"<h4>"+ SurveyMakerAdmin.sectionDeleteConfirmation +"</h4>",
1157 type: 'error',
1158 showCloseButton: true,
1159 showCancelButton: true,
1160 allowOutsideClick: true,
1161 allowEscapeKey: true,
1162 allowEnterKey: true,
1163 confirmButtonColor: '#d33',
1164 cancelButtonColor: '#3085d6',
1165 confirmButtonText: SurveyMakerAdmin.yes,
1166 cancelButtonText: SurveyMakerAdmin.cancel
1167 }).then( function(result) {
1168
1169 if( result.dismiss && result.dismiss == 'close' ){
1170 return false;
1171 }
1172
1173 var deleteQuest = false;
1174 if (result.value) deleteQuest = true;
1175
1176 if( deleteQuest ){
1177 var parent = $this.parents('.ays-survey-section-box');
1178 if( ! parent.hasClass('ays-survey-new-section') ){
1179 var sId = parent.data('id');
1180 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'sections_delete[]" value="'+ sId +'">';
1181 $this.parents('form').append( delImp );
1182 }
1183 parent.remove();
1184
1185 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1186 var sections = sectionCont.find('.ays-survey-section-box');
1187 var addQuestionButton = $(document).find('.ays-survey-general-action[data-action="add-question"]');
1188
1189 var length = sectionCont.find('.ays-survey-section-box').length;
1190 sections.each(function(i, el){
1191 $(this).find('.ays-survey-section-number').text(i+1);
1192 $(this).find('.ays-survey-sections-count').text( sections.length );
1193 });
1194
1195 if (length == 1) {
1196 addQuestionButton.dropdown('dispose');
1197 addQuestionButton.removeAttr('data-toggle');
1198 sections.find('.ays-survey-section-head-top').addClass('display_none');
1199 sections.find('.ays-survey-section-head').removeClass('ays-survey-section-head-topleft-border-none');
1200 sections.find('.ays-survey-section-actions-more .ays-survey-delete-section').addClass('display_none');
1201 }
1202
1203 aysSurveySectionsInitToAddQuestions();
1204 }
1205 } );
1206 });
1207
1208 // Remove Answer Image
1209 $(document).on('click', '.removeAnswerImage', function (e) {
1210 var $this = $(this);
1211 $this.parents('.ays-survey-answer-image-container').fadeOut(500);
1212 setTimeout(function(){
1213 $this.parents('.ays-survey-answer-image-container').find('.ays-survey-answer-img').removeAttr('src');
1214 $this.parents('.ays-survey-answer-image-container').find('.ays-survey-answer-img-src').val('');
1215 }, 500);
1216 });
1217
1218 // Survey Question Image actions Buttons
1219 $(document).on('click', '.ays-survey-question-img-action', function(e){
1220 var $this = $(this);
1221
1222 var action = $this.attr('data-action');
1223
1224 switch( action ){
1225 case 'edit-image':
1226 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-add-question-image').trigger('click');
1227 break;
1228 case 'delete-image':
1229 $this.parents('.ays-survey-question-image-container').fadeOut(500);
1230 setTimeout(function(){
1231 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img').removeAttr('src');
1232 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-src').val('');
1233 }, 500);
1234 break;
1235 case 'add-caption':
1236 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-image-caption-text-row').removeClass('display_none');
1237 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-caption-enable').val('on');
1238 $this.parents('.ays-survey-question-image-container').find('.ays-survey-input.ays-survey-question-image-caption').focus();
1239 $this.attr('data-action' , 'close-caption');
1240 $this.text(SurveyMakerAdmin.closeQuestionImageCaption);
1241 break;
1242 case 'close-caption':
1243 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-image-caption-text-row').addClass('display_none');
1244 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-caption-enable').val('off');
1245 $this.attr('data-action' , 'add-caption');
1246 $this.text(SurveyMakerAdmin.addQuestionImageCaption);
1247 break;
1248 }
1249 });
1250
1251 // Survey General actions Buttons
1252 $(document).on('click', '.ays-survey-general-action', function(e){
1253 var $this = $(this);
1254 var action = $this.data('action');
1255 switch( action ){
1256 case 'add-question':
1257 if(! $this.attr('data-toggle')){
1258 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1259 var sections = sectionCont.find('.ays-survey-section-box');
1260 aysSurveyAddQuestion( sections.data('id'), false, sections );
1261 }
1262 break;
1263 case 'import-question':
1264
1265 break;
1266 case 'add-section-header':
1267
1268 break;
1269 case 'add-image':
1270
1271 break;
1272 case 'add-video':
1273
1274 break;
1275 case 'add-section':
1276 aysSurveyAddSection( null, null );
1277 aysSurveySectionsInitToAddQuestions();
1278 break;
1279 case 'save-changes':
1280 $(document).find('#ays-button-apply-top').trigger('click');
1281 break;
1282 case 'make-questions-required':
1283 makeAllQuestionsRequired($this , false);
1284 break;
1285 }
1286 });
1287
1288 // Survey Question actions Buttons
1289 $(document).on('click', '.ays-survey-question-action', function(e){
1290 var $this = $(this);
1291 var action = $this.attr('data-action');
1292 var $thisEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count,.ays-survey-question-min-selection-count');
1293 var $thisWordEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations');
1294 var $thisNumberEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations');
1295 var enableNumberLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations-checkbox');
1296
1297 var currentSection = $this.parents('.ays-survey-section-box');
1298 var currentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1299 var sectionId = currentSection.attr('data-id');
1300 var sectionName = currentSection.attr('data-name');
1301 var questionId = currentQuestion.attr('data-id');
1302 var questionName = currentQuestion.attr('data-name');
1303
1304 switch( action ){
1305 case 'max-selection-count-enable':
1306 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1307 enableCheckbox.prop('checked', true);
1308 $thisEl.removeClass('display_none');
1309 $this.attr('data-action', 'max-selection-count-disable');
1310 break;
1311 case 'max-selection-count-disable':
1312 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1313 enableCheckbox.prop('checked', false);
1314 $thisEl.addClass('display_none');
1315 $this.attr('data-action', 'max-selection-count-enable');
1316 break;
1317 case 'word-limitation-enable':
1318 var enableTextLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1319 enableTextLimit.prop('checked', true);
1320 $thisWordEl.removeClass('display_none');
1321 $this.attr('data-action', 'word-limitation-disable');
1322 break;
1323 case 'word-limitation-disable':
1324 var enableTextLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1325 enableTextLimit.prop('checked', false);
1326 $thisWordEl.addClass('display_none');
1327 $this.attr('data-action', 'word-limitation-enable');
1328 break;
1329 case 'number-word-limitation-enable':
1330 enableNumberLimit.prop('checked', true);
1331 $thisNumberEl.removeClass('display_none');
1332 $this.attr('data-action', 'number-word-limitation-disable');
1333 break;
1334 case 'number-word-limitation-disable':
1335 enableNumberLimit.prop('checked', false);
1336 $thisNumberEl.addClass('display_none');
1337 $this.attr('data-action', 'number-word-limitation-enable');
1338 break;
1339 case 'move-to-section':
1340 var popup = $(document).find('#ays-survey-move-to-section');
1341 popup.attr('data-section-id', sectionId);
1342 popup.attr('data-section-name', sectionName);
1343 popup.attr('data-question-id', questionId);
1344 popup.attr('data-question-name', questionName);
1345 aysSurveySectionsInitToMoveQuestions( currentSection, currentQuestion );
1346 popup.aysModal('show');
1347 break;
1348 case 'enable-admin-note':
1349 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1350 var enableCheckbox = parentQuestion.find('.ays-survey-question-admin-note-saver');
1351 parentQuestion.find('.ays-survey-question-admin-note').removeClass('display_none');
1352 enableCheckbox.val('on');
1353 $this.find('.ays-survey-question-action-icon').removeClass('display_none');
1354 $this.attr('data-action', 'disable-admin-note');
1355 break;
1356 case 'disable-admin-note':
1357 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1358 var enableCheckbox = parentQuestion.find('.ays-survey-question-admin-note-saver');
1359 parentQuestion.find('.ays-survey-question-admin-note').addClass('display_none');
1360 enableCheckbox.val('off');
1361 $this.find('.ays-survey-question-action-icon').addClass('display_none');
1362 $this.attr('data-action', 'enable-admin-note');
1363 break;
1364 }
1365 });
1366
1367 $(document).on('show.bs.dropdown', '.ays-survey-question-more-actions', function(e){
1368 // var $this = $(this);
1369 // var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1370 // if( enableCheckbox.prop('checked') == true ){
1371 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.disableMaxSelectionCount);
1372 // }else{
1373 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.enableMaxSelectionCount);
1374 // }
1375
1376 // if( $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-type').aysDropdown( 'get value' ) == 'checkbox' ){
1377 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').removeClass('display_none');
1378 // }
1379 var $this = $(this);
1380 // var question = $this.parents('.ays-survey-question-answer-conteiner');
1381 var questionType = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-type').aysDropdown( 'get value' );
1382 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1383 var enableWordLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1384 var enableNumberLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations-checkbox');
1385 if( enableCheckbox.prop('checked') == true ){
1386 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.disableSelectionCount);
1387 }else{
1388 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.enableSelectionCount);
1389 }
1390
1391 if( questionType == 'checkbox' ){
1392 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').removeClass('display_none');
1393 }else{
1394 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').addClass('display_none');
1395 }
1396
1397 if( enableWordLimit.prop('checked') == true ){
1398 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').text(SurveyMakerAdmin.disableWordLimitation);
1399 }else{
1400 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').text(SurveyMakerAdmin.enableWordLimitation);
1401 }
1402
1403 if( questionType == 'short_text' || questionType == 'text' ){
1404 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').removeClass('display_none');
1405 }else{
1406 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').addClass('display_none');
1407 }
1408
1409 if( enableNumberLimit.prop('checked') == true ){
1410 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').text(SurveyMakerAdmin.disableNumberLimitation);
1411 }else{
1412 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').text(SurveyMakerAdmin.enableNumberLimitation);
1413 }
1414
1415 if( questionType == 'number' || questionType == 'phone'){
1416 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').removeClass('display_none');
1417 }else{
1418 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').addClass('display_none');
1419 }
1420 });
1421
1422 $(document).on('click', '.ays-survey-add-question-to-this-section', function(e){
1423 var section = $(this).parents('.ays-survey-section-box');
1424
1425 var sectionId = section.attr('data-id');
1426 aysSurveyAddQuestion( sectionId, false, section );
1427
1428 });
1429
1430 $(document).on('click', '.ays-survey-add-new-section-from-bottom', function(e){
1431 var afterSectionId = $(this).parents('.ays-survey-section-box').attr('data-id');
1432 var newSection = $(this).parents('.ays-survey-section-box').hasClass('ays-survey-new-section');
1433 aysSurveyAddSection( afterSectionId, newSection );
1434 aysSurveySectionsInitToAddQuestions();
1435 });
1436
1437 $(document).on('click', '.ays-survey-duplicate-section', function(e){
1438 var afterSectionId = $(this).parents('.ays-survey-section-box').data('id');
1439 $(this).parents('.ays-survey-section-box').find(".ays-survey-delete-section").removeClass('display_none');
1440 var newSection = $(this).parents('.ays-survey-section-box').hasClass('ays-survey-new-section');
1441 aysSurveyDuplicateSection( $(this), afterSectionId, newSection);
1442 });
1443
1444 $(document).on('click', '.ays-survey-add-question-into-section', function(e){
1445 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+ $(this).data( 'id' ) +'"]:not(.ays-survey-new-section)');
1446 if( $(this).hasClass('ays-survey-add-new-question-into-section') ){
1447 section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box.ays-survey-new-section[data-id="'+ $(this).data( 'id' ) +'"]');
1448 }
1449 var sectionId = $(this).attr( 'data-id' );
1450 aysSurveyAddQuestion( sectionId, false, section );
1451 });
1452
1453 $(document).on('change', '.ays-survey-question-type', function(e) {
1454 var $this = $(this);
1455 var parent = $this.parents('.ays-survey-section-box');
1456 var sectionId = parent.attr('data-id');
1457 var questionId = $this.parents('.ays-survey-question-answer-conteiner').attr('data-id');
1458 var questionDataName = $this.parents('.ays-survey-question-answer-conteiner').attr('data-name');
1459 var questionType = $this.aysDropdown('get value'); //$this.val();
1460 var questionTypeBeforeChange = $this.parents('.ays-survey-question-type-box').find('.ays-survey-check-type-before-change').val();
1461 var answerIds = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-answers-conteiner .ays-survey-answer-row');
1462 $this.parents('.ays-survey-question-type-box').find('.ays-survey-check-type-before-change').val(questionType);
1463
1464 if( questionType == 'radio' || questionType == 'checkbox' || questionType == 'select' ){
1465 if ( questionTypeBeforeChange == 'yesorno' ) {
1466 if (answerIds != undefined) {
1467 answerIds.each(function(e) {
1468 var answerId = $(this).data('id');
1469 if( ! $(this).hasClass('ays-survey-new-answer') ){
1470 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
1471 $this.parents('form').append( delImp );
1472 }
1473 });
1474 }
1475 }
1476 }else{
1477 if ( questionTypeBeforeChange == 'radio' || questionTypeBeforeChange == 'checkbox' || questionTypeBeforeChange == 'select' || questionTypeBeforeChange == 'yesorno' ) {
1478 if (answerIds != undefined) {
1479 answerIds.each(function(e) {
1480 var answerId = $(this).data('id');
1481 if( ! $(this).hasClass('ays-survey-new-answer') ){
1482 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
1483 $this.parents('form').append( delImp );
1484 }
1485 });
1486 }
1487 }
1488 }
1489
1490 switch( questionType ){
1491 case 'radio':
1492 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1493 break;
1494 case 'checkbox':
1495 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1496 break;
1497 case 'select':
1498 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1499 break;
1500 case 'star':
1501 aysSurveyQuestionType_Star_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1502 break;
1503 case 'text':
1504 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1505 break;
1506 case 'short_text':
1507 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1508 break;
1509 case 'number':
1510 case 'phone':
1511 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1512 break;
1513 case 'yesorno':
1514 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1515 break;
1516 case 'email':
1517 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1518 break;
1519 case 'name':
1520 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1521 break;
1522 case 'date':
1523 aysSurveyQuestionType_Date_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1524 break;
1525 case 'time':
1526 aysSurveyQuestionType_Time_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1527 break;
1528 case 'date_time':
1529 aysSurveyQuestionType_Date_Time_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1530 break;
1531 default:
1532 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1533 }
1534 });
1535
1536 setTimeout(function(){
1537 if($(document).find('#ays_survey_custom_css').length > 0){
1538 if(wp.codeEditor){
1539 wp.codeEditor.initialize($(document).find('#ays_survey_custom_css'), cm_settings);
1540 }
1541 }
1542 }, 500);
1543
1544 $(document).find('a[href="#tab2"]').on('click', function (e) {
1545 setTimeout(function(){
1546 if($(document).find('#ays_survey_custom_css').length > 0){
1547 var ays_survey_custom_css = $(document).find('#ays_survey_custom_css').html();
1548 if(wp.codeEditor){
1549 $(document).find('#ays_survey_custom_css').next('.CodeMirror').remove();
1550 wp.codeEditor.initialize($(document).find('#ays_survey_custom_css'), cm_settings);
1551 $(document).find('#ays_survey_custom_css').html(ays_survey_custom_css);
1552 }
1553 }
1554 }, 500);
1555 });
1556
1557 $(document).find('#ays_survey_schedule_active, #ays_survey_schedule_deactive, #ays_survey_change_creation_date').datetimepicker({
1558 controlType: 'select',
1559 oneLine: true,
1560 dateFormat: "yy-mm-dd",
1561 timeFormat: "HH:mm:ss",
1562 afterInject: function(){
1563 $(document).find('.ui-datepicker-buttonpane button.ui-state-default').addClass('button');
1564 $(document).find('.ui-datepicker-buttonpane button.ui-state-default.ui-priority-primary').addClass('button-primary').css('float', 'right');
1565 }
1566 });
1567
1568 $(document).on('click', '.ays-survey-open-question-editor', function(e){
1569 var editorPopup = $(document).find('#ays-edit-question-content');
1570 // For question
1571 var question = $(this).parents('.ays-survey-question-answer-conteiner');
1572 var questionId = question.data('id');
1573 var questionName = question.data('name');
1574 // For section
1575 var section = question.parents('.ays-survey-section-box');
1576 var sectionId = section.data('id');
1577 var sectionName = section.data('name');
1578 var questionContent = question.find('textarea.ays-survey-question-input-textarea').val();
1579 // For question
1580 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-id', questionId );
1581 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-name', questionName );
1582 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', questionId );
1583 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', questionName );
1584 // For section
1585 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-section-id', sectionId );
1586 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-section-name', sectionName );
1587 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-section-id', sectionId );
1588 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-section-name', sectionName );
1589
1590 if ( $(document).find("#wp-ays_survey_question_editor-wrap").hasClass("tmce-active") ){
1591 window.tinyMCE.get('ays_survey_question_editor').setContent( questionContent );
1592 }else{
1593 $(document).find('#ays_survey_question_editor').val( questionContent );
1594 }
1595
1596 editorPopup.aysEditorModal('open');
1597 });
1598
1599 $(document).on('dblclick click', '.ays-survey-question-preview-box', function(e){
1600 var editorPopup = $(document).find('#ays-edit-question-content');
1601 var question = $(this).parents('.ays-survey-question-answer-conteiner');
1602 var questionId = question.data('id');
1603 var questionName = question.data('name');
1604 var questionContent = question.find('textarea.ays-survey-question-input-textarea').val();
1605 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-id', questionId );
1606 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-name', questionName );
1607 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', questionId );
1608 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', questionName );
1609
1610 var SurveyTinyMCE = window.tinyMCE.get('ays_survey_question_editor');
1611 if(SurveyTinyMCE != null){
1612 SurveyTinyMCE.setContent( questionContent );
1613 }
1614 else{
1615 $(document).find('#ays_survey_question_editor').val( questionContent );
1616 }
1617
1618 editorPopup.aysEditorModal('open');
1619 });
1620
1621 $(document).on('click', '.ays-survey-back-to-textarea', function(e){
1622 var editorPopup = $(document).find('#ays-edit-question-content');
1623 var questionId = $(this).attr('data-question-id');
1624 var questionName = $(this).attr('data-question-name');
1625 var question = $(document).find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionName+'"]');
1626 var aysSurveyQuestionTextArea = question.find('textarea.ays-survey-question-input-textarea');
1627
1628 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', '' );
1629 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', '' );
1630
1631 question.find('.ays-survey-open-question-editor-flag').val('off');
1632
1633 question.find('.ays-survey-question-input-box').removeClass('display_none');
1634 question.find('.ays-survey-question-preview-box').addClass('display_none');
1635
1636 // setTimeout( function(){
1637 autosize.update(aysSurveyQuestionTextArea);
1638 // }, 100 );
1639
1640 editorPopup.aysEditorModal('hide');
1641 });
1642
1643 $(document).on('click', '.ays-survey-move-question-into-section', function(e){
1644 var popup = $(document).find('#ays-survey-move-to-section');
1645 var sectionId = popup.attr('data-section-id');
1646 var sectionDataName = popup.attr('data-section-name');
1647 var questionId = popup.attr('data-question-id');
1648 var questionDataName = popup.attr('data-question-name');
1649 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+ $(this).data( 'id' ) +'"]:not(.ays-survey-new-section)');
1650 if( $(this).hasClass('ays-survey-move-new-question-into-section') ){
1651 section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box.ays-survey-new-section[data-id="'+ $(this).data( 'id' ) +'"]');
1652 }
1653 var oldSection = $(document).find('.ays-survey-section-box[data-id="'+sectionId+'"][data-name="'+sectionDataName+'"]');
1654 var question = oldSection.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
1655 var questions = oldSection.find('.ays-survey-question-answer-conteiner');
1656
1657 if( questions.length <= 1 ){
1658 swal.fire({
1659 type: 'warning',
1660 text: SurveyMakerAdmin.minimumCountOfQuestions
1661 });
1662 }else{
1663 setTimeout(function(){
1664 question.appendTo( section.find('.ays-survey-section-questions') );
1665 draggedQuestionUpdate( question, section );
1666 popup.aysModal('hide');
1667 }, 1);
1668 }
1669 });
1670
1671 /////////////////////////////////////////////////////////////////////////////////////////////
1672 /////////////////////////////////////ARO END/////////////////////////////////////////////////
1673 /////////////////////////////////////////////////////////////////////////////////////////////
1674 /////////////////////////////////////////////////////////////////////////////////////////////
1675
1676 aysSurveySectionsInitToAddQuestions();
1677 function aysSurveySectionsInitToAddQuestions(){
1678 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1679 var sections = sectionCont.find('.ays-survey-section-box');
1680 var addQuestionButton = $(document).find('.ays-survey-general-action[data-action="add-question"]');
1681 var ddmenu = addQuestionButton.parent().find('.dropdown-menu');
1682 ddmenu.html('');
1683 sections.each(function(i){
1684 var _this = $(this);
1685 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
1686 var sectionQuestionsCollapsedValues = [];
1687 var sectionQuestionsExpandedValues = [];
1688 sectionQuestionsCollapsedInputs.each(function(){
1689 if( $(this).val() == 'expanded' ){
1690 sectionQuestionsExpandedValues.push( true );
1691 }else{
1692 sectionQuestionsCollapsedValues.push( true );
1693 }
1694 });
1695
1696 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
1697 if( sectionQuestionsExpandedValues.length == 0 ){
1698 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
1699 }
1700
1701 var newClassToAddQuestion = '';
1702 if( _this.hasClass('ays-survey-new-section') ){
1703 newClassToAddQuestion = 'ays-survey-add-new-question-into-section';
1704 }
1705
1706 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
1707
1708 var buttonItem = '<button class="dropdown-item ays-survey-add-question-into-section '+ newClassToAddQuestion +'" data-id="'+ $(this).data('id') +'" type="button">';
1709 buttonItem += 'Add into Section '+ (i+1);
1710 buttonItem += '</button>';
1711 ddmenu.append(buttonItem);
1712 });
1713 if(sections.length > 1){
1714 addQuestionButton.attr('data-toggle', 'dropdown');
1715 addQuestionButton.attr('aria-expanded', 'false');
1716 }else{
1717 addQuestionButton.dropdown('dispose');
1718 addQuestionButton.removeAttr('data-toggle');
1719 }
1720 }
1721
1722 aysSurveySectionsInitQuestionsCollapse();
1723 function aysSurveySectionsInitQuestionsCollapse(){
1724 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1725 var sections = sectionCont.find('.ays-survey-section-box');
1726 sections.each(function(i){
1727 var _this = $(this);
1728 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
1729 var sectionQuestionsCollapsedValues = [];
1730 var sectionQuestionsExpandedValues = [];
1731 sectionQuestionsCollapsedInputs.each(function(){
1732 if( $(this).val() == 'expanded' ){
1733 sectionQuestionsExpandedValues.push( true );
1734 }else{
1735 sectionQuestionsCollapsedValues.push( true );
1736 }
1737 });
1738
1739 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
1740 var collapseButtonAddClass = 'ays-survey-collapse-sec-quests';
1741 var collapseButtonRemoveClass = 'ays-survey-expand-sec-quests';
1742 if( sectionQuestionsExpandedValues.length == 0 ){
1743 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
1744 collapseButtonAddClass = 'ays-survey-expand-sec-quests';
1745 collapseButtonRemoveClass = 'ays-survey-collapse-sec-quests';
1746 }
1747
1748 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
1749 _this.find('.ays-survey-collapse-section-questions').addClass( collapseButtonAddClass );
1750 _this.find('.ays-survey-collapse-section-questions').removeClass( collapseButtonRemoveClass );
1751 });
1752 }
1753
1754 function aysSurveyAddQuestion( sectionId, returnElem = false, sectionElem = null, isFromTemplate = false ){
1755 var section = sectionElem;
1756
1757 var requiredQuestionButton = section.find('.ays-survey-section-questions-required');
1758 var requiredQuestionButtonFlag = requiredQuestionButton.attr('data-flag');
1759
1760 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner');
1761 var clonedElement = cloningElement.clone( true, false );
1762 // var questionsLength = section.find('.ays-survey-question-answer-conteiner .ays-survey-question-input-box .ays-survey-input[name^="ays_section_add"]').length;
1763 var questionsLength = section.find('.ays-survey-question-answer-conteiner').length;
1764 var defaultQuestionType = $(document).find('input[name="ays_default_question_type"]').val();
1765 var answers = clonedElement.find('.ays-survey-answers-conteiner .ays-survey-answer-row');
1766
1767 // Generate unique number for every new question
1768 var generatedUniqueNumber = aysSurveyUniqueNumber();
1769 var questionId = generatedUniqueNumber;
1770 if(isFromTemplate){
1771 var questionTemplateId = questionsLength + 1;
1772 }
1773
1774 if(requiredQuestionButtonFlag && requiredQuestionButtonFlag == 'on'){
1775 clonedElement.find('.ays-survey-answer-elem-box .ays-survey-input-required-question').prop('checked', true);
1776 }
1777
1778
1779 var questionName = clonedElement.attr('data-name');
1780 var sectionName = section.attr('data-name');
1781 if( sectionElem !== null ){
1782 sectionName = sectionElem.attr('data-name');
1783 }
1784
1785 var questionsCount = questionsLength;
1786 var questionsCountBox = section.find(".ays-survey-action-questions-count span").text(questionsCount + 1);
1787 // Answers ordering jQuery UI
1788 clonedElement.find('.ays-survey-answers-conteiner').sortable(answerDragHandle);
1789
1790
1791 var aysSurveyTextArea = clonedElement.find('textarea.ays-survey-question-input-textarea');
1792 setTimeout( function(){
1793 autosize(aysSurveyTextArea);
1794 }, 100 );
1795
1796 clonedElement.addClass('ays-survey-new-question');
1797 clonedElement.attr('data-id', questionId);
1798 if(isFromTemplate){
1799 clonedElement.attr('data-template-id', questionTemplateId);
1800 }
1801 clonedElement.find('textarea.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'title'));
1802 clonedElement.find('select.ays-survey-question-type').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'type'));
1803 clonedElement.find('.ays-survey-question-img-src').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'image'));
1804 clonedElement.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'user_variant'));
1805 clonedElement.find('.ays-survey-input-required-question').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'required'));
1806 clonedElement.find('.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'collapsed'));
1807 clonedElement.find('.ays-survey-question-ordering').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'ordering'));
1808 clonedElement.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_max_selection_count'));
1809 clonedElement.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'max_selection_count'));
1810 clonedElement.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'min_selection_count'));
1811 // Text limitation options
1812 clonedElement.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, questionId, 'options', 'enable_word_limitation'));
1813 clonedElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_by'));
1814 clonedElement.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_length'));
1815 clonedElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_counter'));
1816 // Number limitation options start
1817 clonedElement.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, questionId, 'options', 'enable_number_limitation'));
1818 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_min_selection'));
1819 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_max_selection'));
1820 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_error_message'));
1821 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_number_error_message'));
1822 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_limit_length'));
1823 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_number_limit_counter'));
1824 // Number limitation options end
1825 clonedElement.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'with_editor'));
1826
1827 clonedElement.find('.ays-survey-question-image-caption').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'image_caption'));
1828 clonedElement.find('.ays-survey-question-img-caption-enable').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'image_caption_enable'));
1829 clonedElement.find('.ays-survey-question-ordering').val(questionId);
1830
1831 clonedElement.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_admin_note'));
1832 clonedElement.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'admin_note'));
1833
1834 answers.each(function(j){
1835 var answerId = j+1; //answers.find('.ays-survey-answer-box input.ays-survey-input').length;
1836 $(this).addClass('ays-survey-new-answer');
1837 $(this).attr('data-id', answerId);
1838 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'title'));
1839 $(this).find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'image'));
1840 $(this).find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'ordering'));
1841
1842 var deleteButton = $(this).find('.ays-survey-answer-delete');
1843 if( answers.length == 1){
1844 deleteButton.css('visibility', 'hidden');
1845 }else{
1846 deleteButton.removeAttr('style');
1847 }
1848 });
1849
1850 clonedElement.find('select.ays-survey-question-type').aysDropdown();
1851 clonedElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1852 clonedElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1853
1854 var sectionCollapsedInput = section.find('.ays-survey-section-collapsed-input');
1855 var sectionCollapsed = sectionCollapsedInput.val() == 'collapsed' ? true : false;
1856
1857 if( sectionCollapsed ){
1858 expandSection( sectionCollapsedInput );
1859 }
1860
1861 if( returnElem ){
1862 return clonedElement;
1863 }else{
1864 section.find('.ays-survey-section-questions').append(clonedElement);
1865 clonedElement = section.find('.ays-survey-question-answer-conteiner.ays-survey-new-question[data-id="'+questionId+'"]');
1866 }
1867
1868 clonedElement.find('.ays-survey-question-type').aysDropdown('set selected', defaultQuestionType);
1869 clonedElement.find('.ays-survey-question-type').aysDropdown('set value', defaultQuestionType);
1870
1871 if(!isFromTemplate){
1872 setTimeout(function(){
1873 clonedElement.goToTop();
1874 }, 100 );
1875 }
1876
1877 reInitPopovers( clonedElement );
1878 aysSurveySectionsInitQuestionsCollapse();
1879 }
1880
1881 // Generate unique number
1882 function aysSurveyUniqueNumber() {
1883 var randomNumber = Math.random();
1884 var timestamp = Date.now();
1885 var uniqueNumber = Math.floor(randomNumber * timestamp);
1886 return uniqueNumber;
1887 }
1888
1889 function aysSurveyAddSection( afterSectionId, newSection, isFromTemplate = false){
1890
1891 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1892 var sections = sectionCont.find('.ays-survey-section-box');
1893 var sectionsAdd = sectionCont.find('.ays-survey-new-section');
1894
1895 var section = $(document).find('.ays-question-to-clone .ays-survey-section-box');
1896 var clonedElement = section.clone( true, false );
1897 var sectionNewId = sectionsAdd.length + 1;
1898
1899 clonedElement.attr('data-id', sectionNewId);
1900 clonedElement.attr('data-name', 'ays_section_add');
1901 clonedElement.addClass('ays-survey-new-section');
1902 clonedElement.find('.ays-survey-section-title').attr('name', newSectionAttrName( sectionNewId, 'title' ));
1903 clonedElement.find('.ays-survey-section-description').attr('name', newSectionAttrName( sectionNewId, 'description' ));
1904 clonedElement.find('.ays-survey-section-ordering').attr('name', newSectionAttrName( sectionNewId, 'ordering' ));
1905 clonedElement.find('.ays-survey-section-collapsed-input').attr('name', newSectionAttrName( sectionNewId, 'options', 'collapsed' ));
1906
1907 if( typeof afterSectionId !== 'undefined' && afterSectionId !== null ){
1908 if( newSection === true ){
1909 clonedElement.insertAfter( sectionCont.find('.ays-survey-section-box.ays-survey-new-section[data-id="' + afterSectionId + '"]') );
1910 }else{
1911 clonedElement.insertAfter( sectionCont.find('.ays-survey-section-box.ays-survey-old-section[data-id="' + afterSectionId + '"]') );
1912 }
1913 }else{
1914 sectionCont.append( clonedElement );
1915 }
1916
1917 var defaultQuestionType = $(document).find('input[name="ays_default_question_type"]').val();
1918 var question = aysSurveyAddQuestion( sectionNewId, true, clonedElement );
1919 clonedElement.find('.ays-survey-section-questions').append( question );
1920
1921 question.find('.ays-survey-question-type').aysDropdown('set selected', defaultQuestionType);
1922 question.find('.ays-survey-question-type').aysDropdown('set value', defaultQuestionType);
1923
1924 clonedElement.find('.ays-survey-section-questions').sortable(questionDragHandle);
1925
1926 sectionCont = $(document).find('.ays-survey-sections-conteiner');
1927 sections = sectionCont.find('.ays-survey-section-box');
1928
1929 sections.each(function(i){
1930 $(this).find('.ays-survey-section-ordering').val( i + 1 );
1931 });
1932
1933 var aysSurveyDescriptionTextArea = clonedElement.find('textarea.ays-survey-section-description');
1934 setTimeout( function(){
1935 autosize(aysSurveyDescriptionTextArea);
1936 }, 100 );
1937
1938 sectionCont.find('.ays-survey-section-head-top').removeClass('display_none');
1939 sectionCont.find('.ays-survey-section-head').addClass('ays-survey-section-head-topleft-border-none');
1940
1941 sectionCont.find('.ays-survey-section-box').each(function( index ){
1942 $(this).find('.ays-survey-section-number').text( index + 1 );
1943 });
1944
1945 sectionCont.find('.ays-survey-sections-count').text( sections.length );
1946
1947 // sectionCont.find('.invisible').removeClass( 'invisible' );
1948 sectionCont.find('.ays-survey-section-actions-more .ays-survey-delete-section').removeClass('display_none');
1949 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-survey-answer-dlg-dragHandle .ays-survey-icons').addClass( 'invisible' );
1950 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-question-img-icon-content').parents('.ays-survey-answer-icon-box').addClass( 'invisible' );
1951 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-survey-other-answer-delete-icon').parents('.ays-survey-answer-icon-box').addClass( 'invisible' );
1952 if(!isFromTemplate){
1953 setTimeout(function(){
1954 clonedElement.goToTop();
1955 }, 100 );
1956 }
1957
1958 reInitPopovers( clonedElement );
1959 }
1960
1961 function aysSurveyDuplicateSection( currentButton, afterSectionId, newSection){
1962 var sectionCont = currentButton.parents('.ays-survey-sections-conteiner');
1963 var sections = sectionCont.find('.ays-survey-section-box');
1964 var sectionsAdd = sectionCont.find('.ays-survey-new-section');
1965 var sectionNewId = sectionsAdd.length + 1;
1966
1967 var currentElement = currentButton.parents(".ays-survey-section-box");
1968 var clonedElement = currentElement.clone( true, false );
1969 clonedElement = aysSetNewSectionNames(clonedElement, sectionNewId);
1970
1971 if( typeof afterSectionId !== 'undefined' && afterSectionId !== null ){
1972 clonedElement.insertAfter( currentElement );
1973 }else{
1974 sectionCont.append( clonedElement );
1975 }
1976
1977 // Get all questions
1978 var allQuestions = clonedElement.find('.ays-survey-question-answer-conteiner');
1979 allQuestions.each(function(i){
1980 var questionElem = this;
1981 var questionId = i+1;
1982 var answers = $(this).find('.ays-survey-answers-conteiner .ays-survey-answer-row');
1983
1984 // Set new names for questions
1985 aysSetNewQuestionNames($(questionElem), sectionNewId, questionId);
1986 answers.each(function(j){
1987 var answerId = j;
1988 // Set new names for answers
1989 aysSetNewAnswerNames($(this), sectionNewId, questionId, answerId);
1990
1991 var deleteButton = $(this).find('.ays-survey-answer-delete');
1992 if( answers.length == 1){
1993 deleteButton.css('visibility', 'hidden');
1994 }else{
1995 deleteButton.removeAttr('style');
1996 }
1997 });
1998 });
1999
2000
2001 clonedElement.find('.ays-survey-section-questions').sortable(questionDragHandle);
2002
2003 sectionCont = $(document).find('.ays-survey-sections-conteiner');
2004 sections = sectionCont.find('.ays-survey-section-box');
2005 sections.each(function(i){
2006 $(this).find('.ays-survey-section-ordering').val( i + 1 );
2007 $(this).find('.ays-survey-section-number').text( i + 1 );
2008 });
2009
2010 sectionCont.find('.ays-survey-sections-count').text( sections.length );
2011
2012 sectionCont.find('.ays-survey-section-head-top').removeClass('display_none');
2013 sectionCont.find('.ays-survey-section-head').addClass('ays-survey-section-head-topleft-border-none');
2014 setTimeout(function(){
2015 clonedElement.goTo();
2016 }, 100 );
2017 reInitPopovers( clonedElement );
2018 }
2019
2020 function aysSetNewSectionNames(element, sectionId){
2021 element.attr('data-id', sectionId);
2022 element.attr('data-name', 'ays_section_add');
2023 element.addClass('ays-survey-new-section');
2024 element.find('.ays-survey-section-title').attr('name', newSectionAttrName( sectionId, 'title' ));
2025 element.find('.ays-survey-section-description').attr('name', newSectionAttrName( sectionId, 'description' ));
2026 element.find('.ays-survey-section-ordering').attr('name', newSectionAttrName( sectionId, 'ordering' ));
2027 element.find('.ays-survey-section-collapsed-input').attr('name', newSectionAttrName( sectionId, 'options', 'collapsed' ));
2028 element.find('.ays-survey-delete-section').removeClass("display_none");
2029 element.find('.dropdown-menu.dropdown-menu-right').removeClass("show");
2030 element.find('input[name*="ays_sections_ids"]').remove();
2031 return element;
2032 }
2033
2034 function aysSetNewQuestionNames(element, sectionId, questionId){
2035 element.removeClass('ays-survey-old-question');
2036 element.addClass('ays-survey-new-question');
2037 element.attr('data-id', questionId);
2038 element.attr('data-name', 'questions_add');
2039 var question_type = element.find('.ays-survey-check-type-before-change').val();
2040
2041 var starScaleOldLength = "";
2042 if(question_type == 'star'){
2043 starScaleOldLength = element.find(".ays-survey-choose-for-start-select-lenght").val();
2044 element.find('select.ays-survey-choose-for-start-select-lenght').val(starScaleOldLength);
2045 element.find('input.ays-survey-input-star-1').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_1'));
2046 element.find('input.ays-survey-input-star-2').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_2'));
2047 element.find('select.ays-survey-choose-for-start-select-lenght').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_scale_length'));
2048 }
2049
2050 element.find('textarea.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'title'));
2051 element.find('.ays-survey-question-type select').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'type'));
2052 element.find('.ays-survey-question-img-src').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'image'));
2053 element.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'user_variant'));
2054 element.find('.ays-survey-input-required-question').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'required'));
2055 element.find('.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'collapsed'));
2056 element.find('.ays-survey-question-ordering').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'ordering'));
2057 element.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_max_selection_count'));
2058 element.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'max_selection_count'));
2059 element.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'min_selection_count'));
2060 // Text limitation options
2061 element.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_word_limitation'));
2062 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'limit_by'));
2063 element.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'limit_length'));
2064 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'limit_counter'));
2065 // Number limitation options start
2066 element.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_number_limitation'));
2067 element.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_min_selection'));
2068 element.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_max_selection'));
2069 element.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_error_message'));
2070 element.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_number_error_message'));
2071 element.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_limit_length'));
2072 element.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_number_limit_counter'));
2073 // Number limitation options end
2074
2075 // Input types placeholders
2076 element.find('.ays-survey-question-types-input-with-placeholder').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'placeholder'));
2077
2078
2079 element.find('.ays-survey-question-image-caption').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'image_caption'));
2080 element.find('.ays-survey-question-img-caption-enable').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'image_caption_enable'));
2081
2082 element.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_admin_note'));
2083 element.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'admin_note'));
2084
2085 element.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'with_editor'));
2086 element.find('.ays-survey-question-ordering').val(questionId);
2087
2088 element.find('.ays-survey-question-type').aysDropdown('set selected', question_type);
2089 element.find('.ays-survey-question-type').aysDropdown('set value', question_type);
2090 element.find('.ays-survey-question-type').aysDropdown();
2091 }
2092
2093 function aysSetNewAnswerNames(element, sectionId, questionId, answerId){
2094 element.addClass('ays-survey-new-answer');
2095 element.attr('data-id', answerId);
2096 element.find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'title'));
2097 element.find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'image'));
2098 element.find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'ordering'));
2099 }
2100
2101 function aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null ){
2102
2103 var removeHtml = true; // Remove Html
2104 if(questionTypeBeforeChange == 'radio' || questionTypeBeforeChange == 'select' || questionTypeBeforeChange == 'checkbox'){
2105 removeHtml = false;
2106 }
2107
2108 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2109 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2110 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner .ays-survey-answers-conteiner');
2111 var cloningElement_2 = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner .ays-survey-other-answer-and-actions-row');
2112
2113 if( questionType == 'yesorno' ){
2114 cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-type-yes-or-no');
2115 removeHtml = true;
2116 }
2117
2118 var clonedElement = cloningElement.clone( true, false );
2119 var clonedElement_2 = cloningElement_2.clone( true, false );
2120
2121 var answers = clonedElement.find('.ays-survey-answer-row');
2122 clonedElement.sortable(answerDragHandle);
2123
2124 var questionName = questionDataName;
2125 var sectionName = section.attr('data-name');
2126 if( sectionElem !== null ){
2127 sectionName = sectionElem.attr('data-name');
2128 }
2129 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2130 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2131 var placeholderVal = '';
2132 var questionTypeIconClass = '';
2133 var answer_icon = clonedElement.find('.ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2134 var other_answer_icon = clonedElement_2.find('.ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2135 switch( questionType ){
2136 case 'radio':
2137 case 'yesorno':
2138 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2139 break;
2140 case 'checkbox':
2141 questionTypeIconClass = SurveyMakerAdmin.icons.checkboxUnchecked;
2142 break;
2143 case 'select':
2144 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2145 break;
2146 default:
2147 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2148 }
2149
2150 other_answer_icon.attr('src', questionTypeIconClass);
2151 answer_icon.attr('src', questionTypeIconClass);
2152
2153 clonedElement_2.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'user_variant'));
2154 clonedElement_2.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_max_selection_count'));
2155 clonedElement_2.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'max_selection_count'));
2156
2157 answers.each(function(i){
2158 var answerId = i+1;
2159 $(this).addClass('ays-survey-new-answer');
2160 $(this).attr('data-id', answerId);
2161 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'title'));
2162 $(this).find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'image'));
2163 $(this).find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'ordering'));
2164 });
2165
2166 if( questionType == 'select' ){
2167 clonedElement_2.find('.ays-survey-other-answer-add-wrap').hide();
2168 clonedElement_2.find('.ays-survey-other-answer-row').hide();
2169 clonedElement_2.find('.ays-survey-other-answer-checkbox').prop('checked', false );
2170 question.find('.ays-survey-other-answer-add-wrap').hide();
2171 question.find('.ays-survey-other-answer-checkbox').prop('checked', false );
2172 }else{
2173 clonedElement_2.find('.ays-survey-other-answer-add-wrap').show();
2174 if( question.find('.ays-survey-other-answer-checkbox').prop('checked') == true ){
2175 question.find('.ays-survey-other-answer-add-wrap').hide();
2176 }else{
2177 question.find('.ays-survey-other-answer-add-wrap').show();
2178 }
2179 }
2180
2181 var enableMaxSelectionCount = question.find('.ays-survey-question-max-selection-count-checkbox').prop('checked');
2182 if( questionType == "checkbox" && enableMaxSelectionCount ){
2183 question.find('.ays-survey-question-more-option-wrap').removeClass('display_none');
2184 }else{
2185 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2186 }
2187
2188 if( questionType != "checkbox" ){
2189 question.find('.ays-survey-question-actions-pro[data-action="go-to-section-based-on-answers-enable"]').removeClass('display_none');
2190 }
2191
2192
2193 question.find('.ays-survey-question-more-actions').removeClass('display_none');
2194
2195
2196 if( returnElem ){
2197 clonedElement = $( clonedElement.html() );
2198 var clonedElementArr = new Array(clonedElement, clonedElement_2);
2199 return clonedElementArr;
2200 }else{
2201 // Remove Html
2202 if (removeHtml) {
2203 clonedElement = $( clonedElement.html() );
2204 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answers-conteiner').html(clonedElement);
2205 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2206 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2207 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2208 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2209 }else{
2210 var answer_icon_tags = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2211 switch( questionType ){
2212 case 'radio':
2213 case 'yesorno':
2214 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2215 break;
2216 case 'checkbox':
2217 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.checkboxUnchecked);
2218 break;
2219 case 'select':
2220 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2221 break;
2222 default:
2223 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2224 }
2225 }
2226
2227 if( questionType == 'select' || questionType == 'checkbox' || questionType == 'radio' || questionType == 'yesorno'){
2228 var addAnswerRow = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-other-answer-and-actions-row');
2229 clonedElement_2.find('.ays-survey-other-answer-row .ays-survey-answer-icon-box .invisible').removeClass( 'invisible' );
2230
2231 if ( removeHtml || questionType == 'select' ) {
2232 addAnswerRow.html(clonedElement_2.html());
2233 }
2234 }
2235 }
2236 }
2237
2238 function aysSurveyQuestionType_Star_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2239
2240 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2241 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2242 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_star');
2243 var clonedElement = cloningElement.clone( true, false );
2244
2245 var sectionName = section.attr('data-name');
2246 if( sectionElem !== null ){
2247 sectionName = sectionElem.attr('data-name');
2248 }
2249
2250 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2251 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2252
2253 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2254 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2255 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2256 clonedElement.find('.ays-survey-choose-for-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'scale_length'));
2257 clonedElement.find('.ays-survey-input-star-1').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_1'));
2258 clonedElement.find('.ays-survey-input-star-2').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_2'));
2259 clonedElement.find('.ays-survey-choose-for-start-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_scale_length'));
2260
2261 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2262 if(returnElem){
2263 return clonedElement;
2264 }else{
2265 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2266 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2267 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2268 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2269 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2270
2271 }
2272 }
2273
2274 function aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId, questionId, questionDataName, questionType, returnElem = false, sectionElem = null ){
2275 var section = sectionElem;
2276 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types');
2277 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2278 var clonedElement = cloningElement.clone( true, false );
2279
2280 var answers = clonedElement.find('.ays-survey-answer-row');
2281
2282 var questionName = questionDataName;
2283 var sectionName = section.attr('data-name');
2284 if( sectionElem !== null ){
2285 sectionName = sectionElem.attr('data-name');
2286 }
2287
2288
2289 var placeholderVal = '';
2290 var questionTypeClass = '';
2291 placeholderVal = SurveyMakerAdmin.inputAnswerText;
2292 switch( questionType ){
2293 case 'text':
2294 questionTypeClass = 'ays-survey-question-type-text-box ays-survey-question-type-all-text-types-box';
2295 break;
2296 case 'short_text':
2297 questionTypeClass = 'ays-survey-question-type-short-text-box ays-survey-question-type-all-text-types-box';
2298 break;
2299 case 'number':
2300 questionTypeClass = 'ays-survey-question-type-number-box ays-survey-question-type-all-text-types-box';
2301 break;
2302 case 'phone':
2303 placeholderVal = SurveyMakerAdmin.phoneAnswerText;
2304 questionTypeClass = 'ays-survey-question-type-number-box ays-survey-question-type-all-text-types-box';
2305 clonedElement.find(".ays-survey-question-types-box-phone-type-note").removeClass("display_none");
2306 question.find(".ays-survey-question-number-min-box,.ays-survey-question-number-max-box").addClass("display_none");
2307 break;
2308 case 'email':
2309 placeholderVal = SurveyMakerAdmin.emailField;
2310 questionTypeClass = 'ays-survey-question-type-email-box ays-survey-question-type-all-text-types-box';
2311 break;
2312 case 'name':
2313 placeholderVal = SurveyMakerAdmin.nameField;
2314 questionTypeClass = 'ays-survey-question-type-name-box ays-survey-question-type-all-text-types-box';
2315 break;
2316 default:
2317 placeholderVal = SurveyMakerAdmin.inputAnswerText;
2318 questionTypeClass = 'ays-survey-question-type-text-box ays-survey-question-type-all-text-types-box';
2319 }
2320
2321 var enableWordLimitation = question.find('.ays-survey-question-word-limitations-checkbox').prop('checked');
2322 if( (questionType == "short_text" || questionType == "text") && enableWordLimitation ){
2323 question.find('.ays-survey-question-word-limitations').removeClass('display_none');
2324 }else{
2325 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2326 }
2327
2328 var enableNumberLimitation = question.find('.ays-survey-question-number-limitations-checkbox').prop('checked');
2329 if( (questionType == "number" || questionType == "phone") && enableNumberLimitation ){
2330 question.find('.ays-survey-question-number-limitations').removeClass('display_none');
2331 }else{
2332 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2333 }
2334
2335 // if( questionType == "short_text" || questionType == "text" || questionType == "number"){
2336 // question.find('.ays-survey-question-more-actions').removeClass('display_none');
2337 // }else{
2338 // question.find('.ays-survey-question-more-actions').addClass('display_none');
2339 // }
2340 // question.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').aysDropdown();
2341 // question.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').aysDropdown();
2342
2343
2344
2345 var answerId = answers.find('input.ays-survey-question-types-input').length;
2346 answers.attr('data-id', answerId);
2347 answers.find('input.ays-survey-question-types-input.ays-survey-question-types-input-with-placeholder').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'placeholder'));
2348 answers.find('input.ays-survey-question-types-input').attr('placeholder', placeholderVal);
2349 answers.find('input.ays-survey-question-types-input').val(placeholderVal);
2350 answers.find('.ays-survey-question-types-box').addClass(questionTypeClass);
2351
2352 // question.find('.ays-survey-question-more-actions').addClass('display_none');
2353 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2354 question.find('.ays-survey-question-actions-pro[data-action="go-to-section-based-on-answers-enable"]').addClass('display_none');
2355
2356 if( returnElem ){
2357 return clonedElement;
2358 }else{
2359 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answers-conteiner').html(clonedElement);
2360 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-other-answer-and-actions-row').html('');
2361 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2362 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2363 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2364 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2365
2366 }
2367 }
2368
2369 function aysSurveyQuestionType_Date_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2370
2371 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2372 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2373 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_date');
2374 var clonedElement = cloningElement.clone( true, false );
2375
2376 var sectionName = section.attr('data-name');
2377 if( sectionElem !== null ){
2378 sectionName = sectionElem.attr('data-name');
2379 }
2380
2381 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2382 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2383
2384 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2385 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2386 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2387 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2388 if(returnElem){
2389 return clonedElement;
2390 }else{
2391 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2392 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2393
2394 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_nps').html('');
2395
2396 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2397 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2398 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-matrix_scale').html(' ');
2399 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-matrix_scale_checkbox').html(' ');
2400 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_range').html('');
2401 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-star_list').html('');
2402 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-slider_list').html('');
2403 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_html').html('');
2404 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_calculation').html('');
2405 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2406 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2407 }
2408
2409 }
2410
2411 function aysSurveyQuestionType_Time_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2412
2413 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2414 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2415 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_time');
2416 var clonedElement = cloningElement.clone( true, false );
2417
2418 var sectionName = section.attr('data-name');
2419 if( sectionElem !== null ){
2420 sectionName = sectionElem.attr('data-name');
2421 }
2422
2423 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2424 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2425
2426 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2427 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2428 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2429 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2430 if(returnElem){
2431 return clonedElement;
2432 }else{
2433 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2434 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2435
2436 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2437 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2438 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2439 }
2440
2441 }
2442
2443
2444 function aysSurveyQuestionType_Date_Time_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2445
2446 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2447 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2448 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_date_time');
2449 var clonedElement = cloningElement.clone( true, false );
2450
2451 var sectionName = section.attr('data-name');
2452 if( sectionElem !== null ){
2453 sectionName = sectionElem.attr('data-name');
2454 }
2455
2456 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2457 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2458
2459 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2460 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2461 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2462 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2463 if(returnElem){
2464 return clonedElement;
2465 }else{
2466 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2467 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2468
2469 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2470 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2471 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2472 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2473
2474 }
2475
2476 }
2477
2478 function aysSurveyAddAnswer( currentAnswer, afterAnswer, isFromTemplate = false ){
2479 var $this = currentAnswer;
2480 var section = $this.parents('.ays-survey-section-box');
2481 var sectionId = section.attr('data-id');
2482 var questsCont = $this.parents('.ays-survey-question-answer-conteiner');
2483 var itemId = questsCont.data('id');
2484 var answersCont = questsCont.find('.ays-survey-answers-conteiner');
2485 var cloningElement = answersCont.find('.ays-survey-answer-row:first-child');
2486 var id = cloningElement.data('id');
2487 var answerLength = answersCont.find('.ays-survey-answer-row').length + 1;
2488
2489 var clone = cloningElement.clone(true, false).attr('data-id', answerLength);
2490
2491 if( afterAnswer === true ){
2492 clone.insertAfter(currentAnswer.parents('.ays-survey-answer-row'));
2493 }else{
2494 clone.appendTo(answersCont);
2495 }
2496
2497 questsCont = clone.parents('.ays-survey-question-answer-conteiner');
2498 itemId = questsCont.data('id');
2499 var answerContainer = questsCont.find('.ays-survey-answers-conteiner');
2500 var length = answerContainer.find('.ays-survey-answer-row').length;
2501 var clonedElem = clone.find('.ays-survey-input');
2502 var clonedElemInp = clonedElem.val('Option '+ length).attr('placeholder', 'Option '+ length);
2503
2504 clonedElem.attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'title'));
2505 // clonedElem.find('.aysAnswerImgConteiner').html('');
2506 // clonedElemInp.select();
2507 if(!isFromTemplate){
2508 clonedElemInp.trigger('focus');
2509 }
2510
2511 clone.addClass('ays-survey-new-answer');
2512 clone.find('.ays-survey-answer-image-container').hide();
2513 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img').removeAttr('src');
2514 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img-src').val('');
2515 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img-src').attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'image'));
2516 clone.find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'ordering'));
2517
2518 answersCont.find('.ays-survey-answer-ordering').each(function(i){
2519 $(this).val( i + 1 );
2520 });
2521
2522 // clone.find('.ays-survey-answer-ordering').val( length );
2523 var deleteButton = answerContainer.find('.ays-survey-answer-delete');
2524 if(length == 1){
2525 deleteButton.css('visibility', 'hidden');
2526 }else{
2527 deleteButton.removeAttr('style');
2528 }
2529 answerContainer.sortable(answerDragHandle);
2530 reInitPopovers( clone );
2531 }
2532
2533 function draggedQuestionUpdate( element, section, oldSection){
2534
2535
2536 var questionsLength = section.find('.ays-survey-question-answer-conteiner').length;
2537 var questionsCount = questionsLength;
2538 var questionsCountBox = section.find(".ays-survey-action-questions-count span").text(questionsCount);
2539
2540 if(oldSection){
2541 var oldQuestionsLength = oldSection.find('.ays-survey-question-answer-conteiner').length;
2542 var oldQuestionsCount = oldQuestionsLength;
2543 var questionsCountBox = oldSection.find(".ays-survey-action-questions-count span").text(oldQuestionsCount);
2544 }
2545
2546 var answers = element.find('.ays-survey-answers-conteiner .ays-survey-answer-row');
2547 var questionName = element.attr('data-name');
2548 var questionId = element.attr('data-id');
2549 if( element.hasClass('ays-survey-new-question') ){
2550 questionId = section.find('.ays-survey-question-answer-conteiner[data-name="questions_add"]').length;
2551 }
2552
2553 var sectionName = section.attr('data-name');
2554 var sectionId = section.attr('data-id');
2555
2556 element.find('textarea.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'title'));
2557 element.find('.ays-survey-question-type-box select').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'type'));
2558 element.find('.ays-survey-question-img-src').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'image'));
2559 element.find('.ays-survey-other-answer-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'user_variant'));
2560 element.find('.ays-survey-input-required-question').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'required'));
2561 element.find('.ays-survey-question-collapsed-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'collapsed'));
2562 element.find('.ays-survey-question-ordering').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'ordering'));
2563 element.find('.ays-survey-question-max-selection-count-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_max_selection_count'));
2564 element.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'max_selection_count'));
2565 element.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'min_selection_count'));
2566 // Text limitation options
2567 element.find('.ays-survey-question-word-limitations-checkbox').attr('name', updateQuestionAttrName(sectionName, sectionId, questionName, questionId, 'options', 'enable_word_limitation'));
2568 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'limit_by'));
2569 element.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'limit_length'));
2570 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'limit_counter'));
2571 // Number limitation options start
2572 element.find('.ays-survey-question-number-limitations-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_number_limitation'));
2573 element.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_min_selection'));
2574 element.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_max_selection'));
2575 element.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_error_message'));
2576 element.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_number_error_message'));
2577 element.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_limit_length'));
2578 element.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_number_limit_counter'));
2579 // Number limitation options end
2580
2581 // Input types placeholders
2582 element.find('.ays-survey-remove-default-border.ays-survey-question-types-input.ays-survey-question-types-input-with-placeholder').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'placeholder'));
2583
2584 element.find('.ays-survey-question-image-caption').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'image_caption'));
2585 element.find('.ays-survey-question-img-caption-enable').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'image_caption_enable'));
2586
2587 element.find('.ays-survey-open-question-editor-flag').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'with_editor'));
2588
2589 element.find('.ays-survey-question-admin-note-saver').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_admin_note'));
2590 element.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'admin_note'));
2591
2592 answers.each(function(){
2593 var answerId = $(this).attr('data-id');
2594 var answerName = $(this).hasClass('ays-survey-new-answer') ? 'answers_add' : 'answers';
2595 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'title'));
2596 $(this).find('.ays-survey-answer-img-src').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'image'));
2597 $(this).find('.ays-survey-answer-ordering').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'ordering'));
2598 });
2599
2600 // Star start
2601 element.find('.ays-survey-choose-for-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'scale_length'));
2602 element.find('.ays-survey-input-star-1').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_1'));
2603 element.find('.ays-survey-input-star-2').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_2'));
2604 element.find('.ays-survey-choose-for-start-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_scale_length'));
2605 // Star end
2606
2607 setTimeout(function(){
2608 element.goToTop();
2609 }, 100 );
2610 }
2611
2612 function newSectionAttrName(sectionId, field, field2 = null){
2613 if(field2 !== null){
2614 return $html_name_prefix + 'section_add['+ sectionId +']['+ field +']['+ field2 +']';
2615 }
2616 return $html_name_prefix + 'section_add['+ sectionId +']['+ field +']';
2617 }
2618
2619 function newQuestionAttrName(sectionName, sectionId, questionId, field, field2 = null){
2620 if(field2 !== null){
2621 return sectionName + '['+ sectionId +'][questions_add]['+ questionId +']['+ field +']['+ field2 +']';
2622 }
2623 return sectionName + '['+ sectionId +'][questions_add]['+ questionId +']['+ field +']';
2624 }
2625
2626 function newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, field, field2 = null){
2627 if(field2 !== null){
2628 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +'][answers_add]['+ answerId +']['+ field +']['+ field2 +']';
2629 }
2630 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +'][answers_add]['+ answerId +']['+ field +']';
2631 }
2632
2633 function updateSectionAttrName( sectionName, sectionId, field, field2 = null){
2634 if(field2 !== null){
2635 return sectionName + '['+ sectionId +']['+ field +']['+ field2 +']';
2636 }
2637 return sectionName + '['+ sectionId +']['+ field +']';
2638 }
2639
2640 function updateQuestionAttrName( sectionName, sectionId, questionName, questionId, field, field2 = null){
2641 if(field2 !== null){
2642 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ field +']['+ field2 +']';
2643 }
2644 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ field +']';
2645 }
2646
2647 function updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, field, field2 = null){
2648 if(field2 !== null){
2649 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ answerName +']['+ answerId +']['+ field +']['+ field2 +']';
2650 }
2651 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ answerName +']['+ answerId +']['+ field +']';
2652 }
2653
2654 function reInitPopovers( parentElement ){
2655 parentElement.find('[data-toggle="popover"]').each(function(){
2656 $(this).popover();
2657 });
2658 }
2659
2660 function aysSurveySectionsInitToMoveQuestions( currentSection, currentQuestion ){
2661 var popup = $(document).find('#ays-survey-move-to-section');
2662 var currentSectionId = popup.attr('data-section-id');
2663 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
2664 var sections = sectionCont.find('.ays-survey-section-box');
2665 var moveSectionsCont = popup.find('.ays-survey-move-to-section-sections-wrap');
2666 moveSectionsCont.html('');
2667
2668 sections.each(function(i){
2669 var _this = $(this);
2670 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
2671 var sectionQuestionsCollapsedValues = [];
2672 var sectionQuestionsExpandedValues = [];
2673 sectionQuestionsCollapsedInputs.each(function(){
2674 if( $(this).val() == 'expanded' ){
2675 sectionQuestionsExpandedValues.push( true );
2676 }else{
2677 sectionQuestionsCollapsedValues.push( true );
2678 }
2679 });
2680
2681 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
2682 if( sectionQuestionsExpandedValues.length == 0 ){
2683 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
2684 }
2685
2686 var disabled = '';
2687 if( currentSectionId == _this.attr('data-id') ){
2688 disabled = ' disabled ';
2689 }
2690
2691 var newClassToAddQuestion = '';
2692 if( _this.hasClass('ays-survey-new-section') ){
2693 newClassToAddQuestion = 'ays-survey-move-new-question-into-section';
2694 }
2695
2696 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
2697
2698 var buttonItem = '<button class="dropdown-item ays-survey-move-question-into-section '+ newClassToAddQuestion +'" ' + disabled + ' data-id="'+ $(this).data('id') +'" type="button">';
2699 buttonItem += aysCreateSectionName( _this, i+1, SurveyMakerAdmin.moveToSection ); //SurveyMakerAdmin.addIntoSection + ' ' + (i+1);
2700 buttonItem += '</button>';
2701 moveSectionsCont.append(buttonItem);
2702 });
2703 }
2704
2705 function aysCreateSectionName( section, index, text ){
2706 var sectionName = section.find('.ays-survey-section-title').val();
2707 var name = text + ' ' + index;
2708 if( sectionName == '' ){
2709 name += ' (Untitled Form) ';
2710 }else{
2711 name += ' ('+ sectionName +') ';
2712 }
2713 return name;
2714 }
2715
2716
2717 $(document).find('#ays_select_surveys').select2({
2718 allowClear: true,
2719 placeholder: false
2720 });
2721
2722 $(document).find('#ays_user_roles').select2({
2723 allowClear: true,
2724 placeholder: SurveyMakerAdmin.selectUserRoles
2725 });
2726
2727 $(document).find('#ays_survey_default_type').select2({
2728 allowClear: true,
2729 placeholder: SurveyMakerAdmin.selectQuestionDefaultType
2730 });
2731
2732 $(document).find('.ays-survey-submission-select').aysDropdown();
2733
2734 $(document).find('.ays-survey-sections-conteiner .ays-survey-question-type').aysDropdown({
2735 // allowClear: true,
2736 // placeholder: false
2737 });
2738
2739 /* CONTINUE FROM HERE */
2740 // $(document).find('.ays-survey-sections-conteiner .ays-survey-question-type').aysDropdown({
2741 // // allowClear: true,
2742 // // placeholder: false
2743 // });
2744
2745 $(document).find('.ays-survey-sections-conteiner .dropdown .item[data-value="email"]').before('<div class="divider"></div>');
2746 $(document).find('.ays-survey-sections-conteiner .dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
2747
2748
2749
2750 // ===============================================================
2751 // ====================== Ani ==========================
2752 // ===============================================================
2753
2754 var count = 0;
2755 $(document).find('.ays_survey_previous_next').on('click',function(){
2756 if($(this).attr('data-name') == 'ays_survey_next'){
2757 if($(document).find('.ays_number_of_result').val() == $(document).find('.ays_number_of_result').attr('max')){
2758 count = $(document).find('.ays_number_of_result').attr('min');
2759 $(document).find('.ays_number_of_result').val(count);
2760 }else{
2761 var selectVal = parseInt($(document).find('.ays_number_of_result').val());
2762 count = selectVal + 1;
2763 $(document).find('.ays_number_of_result').val(count);
2764 }
2765 }else if($(this).attr('data-name') == 'ays_survey_previous'){
2766 if($(document).find('.ays_number_of_result').val() == $(document).find('.ays_number_of_result').attr('min')){
2767 count = $(document).find('.ays_number_of_result').attr('max');
2768 $(document).find('.ays_number_of_result').val(count);
2769 }else{
2770 var selectVal = parseInt($(document).find('.ays_number_of_result').val());
2771 count = selectVal - 1;
2772 $(document).find('.ays_number_of_result').val(count);
2773 }
2774 }
2775 $(document).find('.ays_number_of_result').trigger('change');
2776 });
2777
2778 $(document).find('.ays_number_of_result').on('change', refreshSubmissionData);
2779 // $(document).find('.ays_number_of_result').on('input', refreshSubmissionData);
2780
2781 function refreshSubmissionData(){
2782 var submissionPrevVal;
2783 var $this = $(this);
2784
2785 var parent = $(this).parents('.ays_survey_previous_next_conteiner');
2786 var mainParent = $this.parents('.ays_survey_container_each_result');
2787 var submissionInputs = mainParent.find(".ays_number_of_result ");
2788 var currentNumber = $this.val();
2789 if(+$this.val() > +$this.attr("max") || $this.val() == "" || +$this.val() == 0){
2790 currentNumber = $this.attr("max");
2791 }
2792 submissionInputs.val(currentNumber);
2793
2794 var submissionIdStr = parent.find('.ays_submissions_id_str').val();
2795 var submissionIdArr = submissionIdStr.split(",");
2796 var submissionElVal = parseInt(parent.find('.ays_number_of_result').val());
2797 var surveyId = $(document).find('.ays_number_of_result').attr('data-id');
2798 var submissionId = '';
2799 var data = {};
2800
2801 if(submissionElVal < 0){
2802 submissionElVal = 1;
2803 parseInt(parent.find('.ays_number_of_result').val(1));
2804 }else if(submissionElVal > parseInt(parent.find('.ays_number_of_result').attr('max'))){
2805 var maxVal = parseInt(parent.find('.ays_number_of_result').attr('max'));
2806 parseInt(parent.find('.ays_number_of_result').val(maxVal));
2807 submissionElVal = maxVal;
2808 }
2809
2810 if(submissionElVal>submissionPrevVal || submissionElVal+1){
2811 submissionId = submissionIdArr[submissionElVal-1];
2812 }else{
2813 submissionId = submissionIdArr[submissionElVal+1];
2814 }
2815
2816 data.action = 'ays_survey_submission_report';
2817 data.submissionId = submissionId;
2818 data.surveyId = surveyId;
2819 data.nonce = SurveyMakerAdmin.nonce;
2820 var preloader = $(this).parents('.ays_survey_container_each_result').find('.question_result_container').find('div.ays_survey_preloader');
2821 preloader.css({'display':'flex'});
2822 $.ajax({
2823 url: ajaxurl,
2824 dataType: 'json',
2825 data: data,
2826 method: 'post',
2827 success: function(response){
2828 if (response.status) {
2829 preloader.css({'display':'none'});
2830 var questionsData = response.questions;
2831 var questionsInHTML = $(document).find('.ays_questions_answers');
2832 $(document).find(".ays_survey_each_sub_user_info_name").html(response.user_info.user_name);
2833 $(document).find(".ays_survey_each_sub_user_info_email").text(response.user_info.user_email);
2834 $(document).find(".ays_survey_each_sub_user_info_user_ip").html(response.user_info.user_ip);
2835 $(document).find(".ays_survey_each_sub_user_info_sub_date").html(response.user_info.submission_date);
2836 $(document).find(".ays_survey_each_sub_user_info_sub_id").html(response.user_info.id);
2837 if(typeof response.user_info.user_device_type != 'undefined' && response.user_info.user_device_type){
2838 $(document).find(".ays_survey_each_sub_user_info_device_type").parents('.ays_survey_each_sub_user_info_columns').show();
2839 $(document).find(".ays_survey_each_sub_user_info_device_type").html(response.user_info.user_device_type);
2840 }
2841 else{
2842 $(document).find(".ays_survey_each_sub_user_info_device_type").parents('.ays_survey_each_sub_user_info_columns').hide();
2843 }
2844 $(document).find(".ays_survey_each_sub_user_info_header_button button").attr("data-clipboard-text", response.user_info_for_copy);
2845 $.each(questionsInHTML, function(){
2846 var question = $(this);
2847 var qId = question.data('id');
2848 var qType = question.data('type');
2849
2850 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2851 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
2852 question.find('.ays_each_question_answer .ays-survey-submission-select option').removeAttr('selected');
2853 question.find('.ays_text_answer').html('');
2854
2855 if( typeof questionsData[qId] != 'undefined'){
2856 var surveyAnswer = questionsData[qId];
2857 switch( qType ){
2858 case 'radio':
2859 case 'yesorno':
2860 surveyAnswer = questionsData[qId].answer;
2861 var surveyOtherAnswer = questionsData[qId].otherAnswer;
2862 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2863 question.find('.ays_each_question_answer input[type="radio"]').each(function(){
2864 var thisParent = $(this).parents(".ays_each_question_answer");
2865 if( surveyAnswer == $(this).data('id') ){
2866
2867 if(thisParent.hasClass("ays-survey-answer-label-other") && surveyOtherAnswer != ''){
2868 $(this).prop('checked', true);
2869 }
2870 else if(!thisParent.hasClass("ays-survey-answer-label-other")){
2871 $(this).prop('checked', true);
2872 }
2873
2874 }
2875 });
2876
2877 question.find('.ays-survey-answer-other-input').html((surveyOtherAnswer));
2878 break;
2879 case 'checkbox':
2880 surveyAnswer = questionsData[qId].answer;
2881 var surveyOtherAnswer = questionsData[qId].otherAnswer;
2882 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
2883 question.find('.ays_each_question_answer input[type="checkbox"]').each(function(){
2884 if( Array.isArray(surveyAnswer) ){
2885 for(var i=0; i < surveyAnswer.length; i++){
2886 if( surveyAnswer[i] == $(this).data('id') ){
2887 $(this).prop('checked', true);
2888 }
2889 }
2890 }else{
2891 if( surveyAnswer == $(this).data('id') ){
2892 $(this).prop('checked', true);
2893 }
2894 }
2895 });
2896 question.find('.ays-survey-answer-other-input').html((surveyOtherAnswer));
2897 break;
2898 case 'select':
2899 if( parseInt( surveyAnswer ) == 0 ){
2900 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('clear');
2901 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', '');
2902 }else{
2903 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set selected', surveyAnswer);
2904 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', surveyAnswer);
2905 }
2906 break;
2907 case 'star':
2908 surveyAnswer = questionsData[qId];
2909 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2910 question.find('.ays-survey-star-icon').removeClass('fa_star').addClass('fa_star_o');
2911 question.find('.ays-survey-star-icon').css('color', 'rgb(51, 51, 51)');
2912 question.find('.ays_each_question_answer input[type="radio"]').each(function(){
2913
2914 if( parseInt( surveyAnswer ) >= $(this).data('id') ){
2915 $(this).prop('checked', true);
2916 $(this).parents('.ays-survey-answer-star-radio').find('.ays-survey-star-icon').removeClass('fa_star_o').addClass('fa_star');
2917 $(this).parents('.ays-survey-answer-star-radio').find('.ays-survey-star-icon').css('color', 'rgb(255, 87, 34)');
2918 }
2919 });
2920 break;
2921 case 'text':
2922 if( typeof surveyAnswer !== 'string' ){
2923 surveyAnswer = '';
2924 }
2925 surveyAnswer = nl2br( surveyAnswer );
2926 case 'short_text':
2927 case 'number':
2928 case 'phone':
2929 case 'name':
2930 case 'email':
2931 var elem = question.find('.ays_text_answer');
2932 elem.html( surveyAnswer );
2933 break;
2934 case 'date':
2935 case 'time':
2936 case 'date_time':
2937 surveyAnswer = questionsData[qId];
2938 var elem = question.find('.ays_text_answer');
2939 if( typeof surveyAnswer === 'string' ){
2940 surveyAnswer = surveyAnswer;
2941 }else{
2942 surveyAnswer = surveyAnswer.answer;
2943 }
2944 elem.html( surveyAnswer );
2945 break;
2946 }
2947 }else{
2948 switch( qType ){
2949 case 'radio':
2950 case 'yesorno':
2951 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2952 question.find('.ays-survey-answer-other-input').val('');
2953 break;
2954 case 'checkbox':
2955 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
2956 question.find('.ays-survey-answer-other-input').val('');
2957 break;
2958 case 'select':
2959 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('clear');
2960 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', '');
2961 break;
2962 case 'star':
2963 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2964 question.find('.ays-survey-star-icon').removeClass('fa_star').addClass('fa_star_o');
2965 question.find('.ays-survey-star-icon').css('color', 'rgb(51, 51, 51)');
2966 break;
2967 case 'text':
2968 case 'short_text':
2969 case 'number':
2970 case 'phone':
2971 case 'name':
2972 case 'email':
2973 case 'date':
2974 case 'time':
2975 var elem = question.find('.ays_text_answer');
2976 elem.html( '' );
2977 break;
2978 }
2979 }
2980 });
2981 }
2982 }
2983 });
2984 submissionPrevVal = submissionElVal;
2985 }
2986
2987
2988
2989 // ===============================================================
2990 // ====================== Xcho =========================
2991 // ===============================================================
2992
2993
2994 $('#ays_slack_client').on('input', function () {
2995 var clientId = $(this).val();
2996 if (clientId == '') {
2997 $("#slackOAuth2").addClass('disabled btn-outline-secondary');
2998 $("#slackOAuth2").removeClass('btn-secondary');
2999 return false;
3000 }
3001 var scopes = "channels%3Ahistory%20" +
3002 "channels%3Aread%20" +
3003 "channels%3Awrite%20" +
3004 "groups%3Aread%20" +
3005 "groups%3Awrite%20" +
3006 "mpim%3Aread%20" +
3007 "mpim%3Awrite%20" +
3008 "im%3Awrite%20" +
3009 "im%3Aread%20" +
3010 "chat%3Awrite%3Abot%20" +
3011 "chat%3Awrite%3Auser";
3012 var url = "https://slack.com/oauth/authorize?client_id=" + clientId + "&scope=" + scopes + "&state=" + clientId;
3013 $("#slackOAuth2").attr('data-src', url);//.toggleClass('disabled btn-outline-secondary btn-secondary');
3014 $("#slackOAuth2").removeClass('disabled btn-outline-secondary');
3015 $("#slackOAuth2").addClass('btn-secondary');
3016 });
3017 $("#slackOAuth2").on('click', function () {
3018 var url = $(this).attr('data-src');
3019 if (!url) {
3020 return false;
3021 }
3022 location.replace(url)
3023 });
3024 $('#ays_slack_secret').on('input', function(e) {
3025 if($(this).val() == ''){
3026 $("#slackOAuthGetToken").addClass('disabled btn-outline-secondary');
3027 $("#slackOAuthGetToken").removeClass('btn-secondary');
3028 return false;
3029 }
3030
3031 $("#slackOAuthGetToken").removeClass('disabled btn-outline-secondary');
3032 $("#slackOAuthGetToken").addClass('btn-secondary');
3033 });
3034
3035 // Limitations PRO
3036 $('#ays_survey_users_roles,#ays_survey_users_pro').select2();
3037
3038 $(document).find('#ays_survey_default_type').select2({
3039 allowClear: true,
3040 placeholder: SurveyMakerAdmin.selectQuestionDefaultType
3041 });
3042
3043 $(document).find(".ays-survey-min-votes-field").on("input" , function(){
3044 var $this = $(this);
3045 var minVal = parseInt($(this).val());
3046 var maxField = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-max-votes-field");
3047 if(minVal >= maxField.val())
3048 maxField.val(minVal);
3049 });
3050
3051 $(document).find(".ays-survey-max-votes-field").on("change" , function(){
3052 var $this = $(this);
3053 var maxVal = parseInt($(this).val());
3054 var minField = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-min-votes-field");
3055 var minVal = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-min-votes-field").val();
3056 if(maxVal == ''){
3057 return;
3058 }
3059 if(maxVal < minVal){
3060 $this.val(minVal);
3061 }
3062 });
3063
3064 $(document).on('click', '.ays_toggle_loader_radio', function (e) {
3065 var dataFlag = $(this).attr('data-flag');
3066 var dataType = $(this).attr('data-type');
3067 var state = false;
3068 if (dataFlag == 'true') {
3069 state = true;
3070 }
3071
3072 var parent = $(this).parents('.ays_toggle_loader_parent');
3073 if($(this).hasClass('ays_toggle_loader_slide')){
3074 switch (state) {
3075 case true:
3076 parent.find('.ays_toggle_loader_target').slideDown(250);
3077 break;
3078 case false:
3079 parent.find('.ays_toggle_loader_target').slideUp(250);
3080 break;
3081 }
3082 }else{
3083 switch (state) {
3084 case true:
3085 switch( dataType ){
3086 case 'text':
3087 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').show(250);
3088 parent.find('.ays_toggle_loader_target[data-type="gif"]').hide(250);
3089 break;
3090 case 'gif':
3091 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').show(250);
3092 parent.find('.ays_toggle_loader_target.ays_gif_loader_width_container[data-type="'+ dataType +'"]').css({
3093 'display': 'flex',
3094 'justify-content': 'center',
3095 'align-items': 'center'
3096 });
3097 parent.find('.ays_toggle_loader_target[data-type="text"]').hide(250);
3098 break;
3099 default:
3100 parent.find('.ays_toggle_loader_target').show(250);
3101 break;
3102 }
3103 break;
3104 case false:
3105 switch( dataType ){
3106 case 'text':
3107 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').hide(250);
3108 break;
3109 case 'gif':
3110 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').hide(250);
3111 break;
3112 default:
3113 parent.find('.ays_toggle_loader_target').hide(250);
3114 break;
3115 }
3116 break;
3117 }
3118 }
3119 });
3120
3121 $(document).find(".add_survey_loader_custom_gif,.ays-edit-survey-loader-custom-gif").on("click" , function(e){
3122 openMediaUploaderForGifLoader(e, $(this));
3123 });
3124
3125 $(document).on('click', '.ays-survey-image-wrapper-delete-wrap', function () {
3126 var wrap = $(this).parents('.ays-survey-image-wrap');
3127 wrap.find('.ays-survey-image-container').fadeOut(500);
3128 setTimeout(function(){
3129 wrap.find('img.ays_survey_img_loader_custom_gif').attr('src', '');
3130 wrap.find('input.ays-survey-image-path').val('');
3131 wrap.find('button.add_survey_loader_custom_gif').show();
3132 }, 450);
3133 });
3134
3135 $(document).find("#ays-survey-form .nav-tab").on("click" , function(){
3136 var $this = $(this);
3137 if($this.data("tab") != "undefined" && $this.data("tab") == 'tab1'){
3138 refreshSurveyColor($this);
3139 }
3140 });
3141
3142 function refreshSurveyColor(element){
3143 var customCss = $(document).find("#ays-survey-custom-css-additional");
3144 var parentElement = element.parents("#ays-survey-form");
3145 var surveyColor = parentElement.find("#ays_survey_color").val();
3146 var isModern = $(document).find('input[name="ays_survey_theme"]:checked').val() == 'modern' ? true : false;
3147 var isMinimal = $(document).find('input[name="ays_survey_theme"]:checked').val() == 'minimal' ? true : false;
3148 if( isMinimal || isModern ){
3149 if( parentElement.find("#ays_survey_color").val() == 'rgba(0,0,0,0)' ){
3150 surveyColor = '#333333';
3151 }
3152 }
3153
3154 var newCss = '#ays-survey-form .ays-survey-section-head-wrap .ays-survey-section-head {'
3155 newCss += 'border-top-color: '+surveyColor;
3156 newCss += '}';
3157 newCss += '#ays-survey-form .ays-survey-section-head-wrap .ays-survey-section-head-top .ays-survey-section-counter {'
3158 newCss += 'background-color: '+surveyColor;
3159 newCss += '}';
3160 newCss += '#ays-survey-form .ays-survey-input:focus ~ .ays-survey-input-underline-animation {'
3161 newCss += 'background-color: '+surveyColor;
3162 newCss += '}';
3163 newCss += '#ays-survey-form .dropdown-item:hover {'
3164 newCss += 'background-color: '+surveyColor+'29;';
3165 newCss += '}';
3166 newCss += '#ays-survey-form .dropdown-item:focus {'
3167 newCss += 'background-color: '+surveyColor+'29;';
3168 newCss += '}';
3169 newCss += '#ays-survey-form .dropdown-item:active {'
3170 newCss += 'background-color: '+surveyColor+';';
3171 newCss += '}';
3172 newCss += '#ays-survey-form input.ays-switch-checkbox:checked + .switch-checkbox-wrap .switch-checkbox-circles .switch-checkbox-thumb {'
3173 newCss += 'border-color: '+surveyColor;
3174 newCss += '}';
3175 newCss += '#ays-survey-form input.ays-switch-checkbox:checked + .switch-checkbox-wrap .switch-checkbox-track {'
3176 newCss += 'border-color: '+surveyColor+'53';
3177 newCss += '}';
3178 customCss.html(newCss);
3179 }
3180
3181 // var checkCountdownIsExists = $(document).find('#ays-survey-maker-countdown-main-container');
3182 var checkCountdownIsExists = $(document).find('#ays-survey-countdown-main-container');
3183
3184 if ( checkCountdownIsExists.length > 0 ) {
3185 var second = 1000,
3186 minute = second * 60,
3187 hour = minute * 60,
3188 day = hour * 24;
3189
3190 // var countdownEndTime = "DEC 05, 2025 23:59:59";
3191 var countdownEndTime = SurveyMakerAdmin.surveyBannerDate;
3192 var countDown = new Date(countdownEndTime).getTime(),
3193
3194 x = setInterval(function() {
3195
3196 var now = new Date().getTime(),
3197 distance = countDown - now;
3198
3199 var countDownDays = document.getElementById("ays-survey-countdown-days");
3200 var countDownHours = document.getElementById("ays-survey-countdown-hours");
3201 var countDownMinutes = document.getElementById("ays-survey-countdown-minutes");
3202 var countDownSeconds = document.getElementById("ays-survey-countdown-seconds");
3203
3204 if(countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null){
3205 countDownDays.innerText = Math.floor(distance / (day)),
3206 countDownHours.innerText = Math.floor((distance % (day)) / (hour)),
3207 countDownMinutes.innerText = Math.floor((distance % (hour)) / (minute)),
3208 countDownSeconds.innerText = Math.floor((distance % (minute)) / second);
3209 // countDownDays.innerText = Math.floor(distance / (day)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3210 // countDownHours.innerText = Math.floor((distance % (day)) / (hour)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3211 // countDownMinutes.innerText = Math.floor((distance % (hour)) / (minute)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3212 // countDownSeconds.innerText = Math.floor((distance % (minute)) / second).toLocaleString(undefined,{minimumIntegerDigits: 2});
3213
3214 }
3215
3216 //do something later when date is reached
3217 if (distance < 0) {
3218 var headline = document.getElementById("ays-survey-countdown-headline"),
3219 countdown = document.getElementById("ays-survey-countdown"),
3220 content = document.getElementById("ays-survey-countdown-content");
3221
3222 // headline.innerText = "Sale is over!";
3223 countdown.style.display = "none";
3224 content.style.display = "block";
3225
3226 clearInterval(x);
3227 }
3228 }, 1000);
3229 }
3230
3231 $(document).on('click', '.ays-survey-add-cover-image', function (e) {
3232 openMediaUploaderForCoverImage(e, $(this));
3233 });
3234
3235 $(document).on('click', '.removeCoverImage', function (e) {
3236 var $this = $(this);
3237 var thisParent = $this.parents('.ays_survey_cover_image_main');
3238 thisParent.find('.ays-survey-add-cover-image').html( SurveyMakerAdmin.addImage );
3239 thisParent.find('.ays-survey-image-body').fadeOut(500);
3240 thisParent.find('.ays-survey-cover-image-options,.ays-survey-cover-image-options-hr').fadeOut(500);
3241 setTimeout(function(){
3242 $this.parents('.ays-survey-image-container').find('.ays-survey-cover-img').removeAttr('src');
3243 $this.parents('.ays-survey-image-container').find('.ays-survey-cover-img-src').val('');
3244 }, 500);
3245 });
3246
3247 $(document).on('click', '.ays_survey_each_sub_user_info_header_button button', function () {
3248 selectElementContentsCopy($(this));
3249 });
3250
3251 var surveyResults = $(document).find('.ays_survey_result');
3252 for (var i in surveyResults) {
3253 surveyResults.eq(i).parents('tr').addClass('ays_survey_results');
3254 }
3255
3256 $(document).on("click", ".ays-survey-view-detailed-button", getEachSubmission);
3257
3258 $(document).on('click', '#ays-surveys-next-button,#ays-surveys-prev-button', function(e){
3259 e.preventDefault();
3260 var confirm;
3261 if($(e.target).hasClass("ays-survey-prev-survey-button")){
3262 confirm = window.confirm( SurveyMakerAdmin.prevSurveyPage );
3263 }
3264 else{
3265 confirm = window.confirm( SurveyMakerAdmin.nextSurveyPage );
3266 }
3267 if(confirm){
3268 window.location.replace($(this).attr('href'));
3269 }
3270 });
3271
3272 $(document).find('#ays-survey-title').on('input', function(e){
3273 var surveyTitleVal = $(this).val();
3274 var surveyTitle = aysSurveystripHTML( surveyTitleVal );
3275 $(document).find('.ays_survey_title_in_top').html( surveyTitle );
3276 });
3277
3278 // Select message vars surveys page
3279 $(document).find('.ays-survey-message-vars-icon').on('click', function(e){
3280 $(this).parents(".ays-survey-message-vars-box").find(".ays-survey-message-vars-data").toggle('fast');
3281 });
3282
3283 $(document).find('.ays-survey-open-surveys-list').on('click', function(e){
3284 $(this).parents(".ays-survey-subtitle-main-box").find(".ays-survey-surveys-data").toggle('fast');
3285 });
3286
3287 $(document).on( "click" , function(e){
3288
3289 if($(e.target).closest('.ays-survey-message-vars-box,.ays-survey-subtitle-main-box').length != 0){
3290
3291 }
3292 else{
3293 $(document).find(".ays-survey-message-vars-box .ays-survey-message-vars-data,.ays-survey-subtitle-main-box .ays-survey-surveys-data").hide('fast');
3294 }
3295 //
3296 });
3297
3298 $(document).find(".ays-survey-go-to-surveys").on("click" , function(e){
3299 e.preventDefault();
3300 var confirmRedirect = window.confirm('Are you sure you want to redirect to another survey? Note that the changes made in this survey will not be saved.');
3301 if(confirmRedirect){
3302 window.location = $(this).attr("href");
3303 }
3304 });
3305
3306 $(document).find('.ays-survey-message-vars-each-data').on('click', function(e){
3307 var messageVar = $(this).find(".ays-survey-message-vars-each-var").val();
3308 var mainParent = $(this).parents('.ays-survey-box-for-mv');
3309 var dataTMCE = mainParent.find('.ays-survey-message-vars-data').attr('data-tmce');
3310
3311 if ( mainParent.find("#wp-"+dataTMCE+"-wrap").hasClass("tmce-active") ){
3312 window.tinyMCE.get(dataTMCE).setContent( window.tinyMCE.get(dataTMCE).getContent() + messageVar + " " );
3313 }else{
3314 mainParent.find('#'+dataTMCE).append( " " + messageVar + " ");
3315 }
3316 });
3317 /* */
3318
3319 $(document).find('.ays-survey-add-new-button-video').on('click', function(e){
3320 $(document).find(".page-title-action").trigger("click");
3321 });
3322
3323 var ays_survey_popup_bg_color_picker = {
3324 defaultColor: '#ffffff',
3325 change: function (e) {
3326 }
3327 };
3328
3329 var ays_survey_popup_bg_color_mobile_picker = {
3330 defaultColor: '#ffffff',
3331 change: function (e) {
3332 }
3333 };
3334
3335 var aysSurveyPopupTitleTextColorPicker = {
3336 defaultColor: '#000000',
3337 change: function (e) {
3338 }
3339 };
3340
3341 var aysSurveyPopupTitleBgColorPicker = {
3342 defaultColor: '#00000000',
3343 change: function (e) {
3344 }
3345 };
3346
3347 $(document).find('#ays_survey_popup_trigger').on('change', function(){
3348 var triggerType = $(this).val();
3349 if(triggerType == 'on_click'){
3350 $(document).find('.ays-survey-popup-selector').show(250);
3351 $(document).find('.ays-survey-popup-selector').css('display','flex');
3352 $(document).find('.ays-survey-popup-selector').prev('hr').show(250);
3353 }else{
3354 $(document).find('.ays-survey-popup-selector').hide(250);
3355 $(document).find('.ays-survey-popup-selector').prev('hr').hide(250);
3356 }
3357 });
3358
3359 $(document).find('table#ays-survey-popup-position-table tr td').on('click', function(e){
3360 var val = $(this).data('value');
3361 $(document).find('.popup_survey_position_block #ays-survey-popup-position-val').val(val);
3362 aysCheckPopupPosition();
3363 });
3364
3365 $(document).find('table#ays-survey-position-table tr td').on('click', function(e){
3366 var val = $(this).data('value');
3367 $(document).find('.survey_position_block #ays-survey-position-val').val(val);
3368 aysCheckPosition();
3369 });
3370
3371 function aysCheckPopupPosition(){
3372 var hiddenVal = $(document).find('.popup_survey_position_block #ays-survey-popup-position-val').val();
3373
3374 if (hiddenVal == "") {
3375 var $this = $(document).find('table#ays-survey-popup-position-table tr td[data-value="center-center"]');
3376 }else{
3377 var $this = $(document).find('table#ays-survey-popup-position-table tr td[data-value='+ hiddenVal +']');
3378 }
3379
3380 if (hiddenVal == 'center-center' || hiddenVal == ''){
3381 $(document).find("#popupMargin").addClass('display_none');
3382 $(document).find(".ays_pb_hr_hide").addClass('display_none');
3383 }else{
3384 $(document).find("#popupMargin").removeClass('display_none');
3385 $(document).find(".ays_pb_hr_hide").removeClass('display_none');
3386 }
3387
3388 $(document).find('table#ays-survey-popup-position-table td').removeAttr('style');
3389 $this.css('background-color','#a2d6e7');
3390 }
3391
3392
3393 function aysCheckPosition(){
3394 var hiddenVal = $(document).find('.survey_position_block #ays-survey-position-val').val();
3395
3396 if (hiddenVal == "") {
3397 var $this = $(document).find('table#ays-survey-position-table tr td[data-value="center-center"]');
3398 }else{
3399 var $this = $(document).find('table#ays-survey-position-table tr td[data-value='+ hiddenVal +']');
3400 }
3401
3402 $(document).find('table#ays-survey-position-table td').removeAttr('style');
3403 $this.css('background-color','#a2d6e7');
3404 }
3405
3406 // Initialize popup survey color picker
3407 $(document).find('#ays_survey_popup_bg_color').wpColorPicker(ays_survey_popup_bg_color_picker);
3408 // Initialize popup survey color picker
3409 $(document).find('#ays_survey_popup_bg_color_mobile').wpColorPicker(ays_survey_popup_bg_color_mobile_picker);
3410 // Initialize popup survey title bg color picker
3411 $(document).find('#ays_survey_popup_title_bg_color,#ays_survey_popup_title_bg_color_mobile').wpColorPicker(aysSurveyPopupTitleBgColorPicker);
3412 // Initialize popup survey title text color picker
3413 $(document).find('#ays_survey_popup_title_text_color,#ays_survey_popup_title_text_color_mobile').wpColorPicker(aysSurveyPopupTitleTextColorPicker);
3414
3415 $(document).find('.ays-survey-aysDropdown-answer-view').on('change', function(e){
3416 var answerViewAligne = $(document).find('.ays-survey-aysDropdown-answer-view-alignment');
3417 answerViewAligne.aysDropdown('destroy');
3418 var answerViewType = $(this).aysDropdown('get value');
3419
3420 var dataObj = {
3421 'list': [
3422 {
3423 name : 'Left',
3424 value : 'flex-start',
3425 selected : true
3426 },
3427 {
3428 name : 'Right',
3429 value : 'flex-end',
3430 },
3431 {
3432 name : 'Center',
3433 value : 'center',
3434 }
3435 ],
3436 'grid': [
3437 {
3438 name : 'Space around',
3439 value : 'space-around',
3440 selected : true
3441 },
3442 {
3443 name : 'Space between',
3444 value : 'space-between',
3445 },
3446 {
3447 name : 'Left',
3448 value : 'flex-start',
3449 },
3450 {
3451 name : 'Right',
3452 value : 'flex-end',
3453 },
3454 {
3455 name : 'Center',
3456 value : 'center',
3457 }
3458 ]
3459 }
3460 answerViewAligne.aysDropdown({
3461 values: dataObj[answerViewType]
3462 });
3463 });
3464
3465 // Survey Templates start
3466 $(document).find(".ays-survey-open-templates-modal").on("click" , function(e){
3467 e.preventDefault();
3468 var $this = $('#ays-survey-templates-modal');
3469 $this.find('.ays-modal-content-survey-templates .ays-survey-templates-box.ays-survey-templates-blank-box').remove();
3470 $(document).find('#ays-survey-templates-modal').aysModal('show');
3471 $(document).find('#ays-survey-templates-modal .ays-modal-content-survey-templates-header .ays-close-templates-popup').attr('data-action' , 'in-edit-page');
3472 $(document).find('#ays-survey-templates-modal .ays-modal-content.ays-modal-content-survey-templates').removeClass('no-confirmation');
3473
3474 });
3475
3476 $(document).find(".ays-survey-templates-box-apply-button-blank").on("click" , function(e){
3477 e.preventDefault();
3478 e.stopPropagation();
3479 $(document).find('#ays-survey-templates-modal').aysModal('hide');
3480 });
3481
3482 $(document).find('.ays-survey-templates-box').on('click' , function(){
3483 var tempType = $(this).attr('data-template');
3484 if(tempType == 'blank-form'){
3485 $(document).find(".ays-survey-templates-box-apply-button-blank").trigger('click');
3486 return;
3487 }
3488 $(this).find('.ays-survey-templates-box-apply-button').trigger('click');
3489 });
3490
3491 $(document).find(".ays-survey-templates-box-apply-button").on("click" , function(e){
3492 e.preventDefault();
3493 e.stopPropagation();
3494 var $this = $(this);
3495 var $thisParent = $this.parents(".ays-modal-content-survey-templates");
3496 if(!$thisParent.hasClass('no-confirmation')){
3497 var confirm = window.confirm(SurveyMakerAdmin.confirmMessageTemplate);
3498 }
3499 else{
3500 var confirm = true;
3501 }
3502 if(confirm == true){
3503
3504
3505 var modal = $('#ays-survey-templates-modal');
3506 var otherTypes = new Array(
3507 'text',
3508 'linear_scale',
3509 'star',
3510 'short_text',
3511 'number',
3512 'phone',
3513 'name',
3514 'email',
3515 'date',
3516 'date_time',
3517 'time',
3518 );
3519 $thisParent.find(".ays_survey_preloader").show();
3520
3521 var action = 'ays_survey_add_survey_template';
3522
3523 var templateName = $this.attr('data-template');
3524
3525 $.ajax({
3526 url: ajaxurl,
3527 type: 'post',
3528 dataType: 'json',
3529 data: {
3530 action: action,
3531 template_file_name: templateName
3532 },
3533 success: function(response) {
3534 if (response.status) {
3535 var sections = response.data.sections;
3536 $(document).find('#ays-survey-title').val(response.data.title);
3537 // For Sections
3538 var newQuestion = "";
3539 var parent = $(document).find(".ays-survey-sections-conteiner");
3540 parent.html("");
3541 for(var key in sections){
3542
3543 aysSurveyAddSection( null, null, true );
3544 var lastAddedSection = parent.find(".ays-survey-new-section:last-child");
3545 lastAddedSection.find(".ays-survey-section-questions").html("");
3546 lastAddedSection.find(".ays-survey-section-title").val(sections[key].title);
3547 // For Questions
3548 for(var questionKey in sections[key].questions){
3549 var allAddedAnswers = new Array();
3550 var questionType = typeof sections[key].questions[questionKey].type != "undefined" ? sections[key].questions[questionKey].type : "";
3551 if(questionType != ""){
3552 aysSurveyAddQuestion(lastAddedSection.attr("data-id"), false, lastAddedSection , true);
3553 newQuestion = lastAddedSection.find("div.ays-survey-new-question[data-template-id='"+(Number(questionKey)+1)+"']");
3554 newQuestion.find('.ays-survey-question-type').aysDropdown('set selected', sections[key].questions[questionKey].type );
3555 newQuestion.find('.ays-survey-question-type').aysDropdown('set value', sections[key].questions[questionKey].type );
3556 newQuestion.find('.ays-survey-check-type-before-change').val( sections[key].questions[questionKey].type );
3557 newQuestion.find(".ays-survey-question-input-textarea").html(sections[key].questions[questionKey].question);
3558 newQuestion.find(".ays-survey-question-description-input-textarea").html(sections[key].questions[questionKey].description);
3559 var thisButton = newQuestion.find(".ays-survey-action-add-answer");
3560
3561 // For Answers
3562 for(var answerKey in sections[key].questions[questionKey].answers){
3563
3564 aysSurveyAddAnswer( thisButton, false, true );
3565 var newAnswer = newQuestion.find("div.ays-survey-new-answer[data-id='"+(Number(answerKey)+1)+"']");
3566 allAddedAnswers.push(newAnswer);
3567 newAnswer.find(".ays-survey-input").val(sections[key].questions[questionKey].answers[answerKey].answer);
3568
3569 }
3570
3571 if(sections[key].questions[questionKey].user_variant == 'on'){
3572 var checkbox = newQuestion.find('.ays-survey-other-answer-checkbox').attr('checked', 'checked');
3573 var oterAnswer = newQuestion.find('.ays-survey-other-answer-row');
3574 oterAnswer.removeAttr('style');
3575 newQuestion.find('.ays-survey-other-answer-add-wrap').css('display','none');
3576 }
3577
3578 newQuestion.find('.ays-survey-input-required-question').prop('checked', sections[key].questions[questionKey].options[0].required == 'on' ? true : false );
3579
3580 if(otherTypes.indexOf(questionType) == -1 && allAddedAnswers.length > 0){
3581 newQuestion.find("div.ays-survey-answers-conteiner").html(allAddedAnswers);
3582 }
3583 }
3584 }
3585 }
3586 setTimeout(function(){
3587 $thisParent.find(".ays_survey_preloader").hide();
3588 modal.aysModal('hide');
3589 } , 100);
3590
3591 }
3592 else{
3593 $thisParent.find(".ays_survey_preloader").hide();
3594 }
3595 },
3596 error: function(){
3597 $thisParent.find(".ays_survey_preloader").hide();
3598 modal.aysModal('hide');
3599 }
3600 });
3601 }
3602 });
3603 // Survey Templates end
3604
3605 // Pro features start
3606 $(document).find(".ays-pro-features-v2-upgrade-button").hover(function() {
3607 // Code to execute when the mouse enters the element
3608 var unlockedImg = "Unlocked_24_24.svg";
3609 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
3610 var imgUrl = imgBox.attr("data-img-src");
3611 var newString = imgUrl.replace("Locked_24x24.svg", unlockedImg);
3612
3613 imgBox.css("background-image", 'url(' + newString + ')');
3614 imgBox.attr("data-img-src", newString);
3615 }, function() {
3616
3617 var lockedImg = "Locked_24x24.svg";
3618 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
3619 var imgUrl = imgBox.attr("data-img-src");
3620 var newString = imgUrl.replace("Unlocked_24_24.svg", lockedImg);
3621
3622 imgBox.css("background-image", 'url(' + newString + ')');
3623 imgBox.attr("data-img-src", newString);
3624 });
3625
3626 $(document).find(".ays-pro-features-v2-video-button").hover(function() {
3627 // Code to execute when the mouse enters the element
3628 var unlockedImg = "Video_24x24_Hover.svg";
3629 var imgBox = $(this).find(".ays-pro-features-v2-video-icon");
3630 var imgUrl = imgBox.attr("data-img-src");
3631 var newString = imgUrl.replace("Video_24x24.svg", unlockedImg);
3632
3633 imgBox.css("background-image", 'url(' + newString + ')');
3634 imgBox.attr("data-img-src", newString);
3635 }, function() {
3636
3637 var lockedImg = "Video_24x24.svg";
3638 var imgBox = $(this).find(".ays-pro-features-v2-video-icon");
3639 var imgUrl = imgBox.attr("data-img-src");
3640 var newString = imgUrl.replace("Video_24x24_Hover.svg", lockedImg);
3641
3642 imgBox.css("background-image", 'url(' + newString + ')');
3643 imgBox.attr("data-img-src", newString);
3644 });
3645
3646 $(document).on('click', '.ays-pro-features-v2-video-button,.ays-survey-question-actions-pro-button', function(e){
3647 e.preventDefault();
3648 if($(this).hasClass('ays-survey-question-actions-pro-button')){
3649 var _thisDataParent = $(this);
3650 }
3651 else{
3652 var _thisDataParent = $(this).parents('.ays-pro-features-v2-main-box').find('.ays-pro-pro-features-popup');
3653 }
3654 var popupModal = $(document).find('#pro-features-popup-modal');
3655
3656 // Get option Data
3657 var optionTitle = _thisDataParent.attr('data-option-title');
3658 var optionDesc = _thisDataParent.attr('data-option-text');
3659 var optionVideoUrl = _thisDataParent.attr('data-video-url');
3660
3661 var popupModalTitleBox = popupModal.find('.pro-features-popup-modal-right-box-title');
3662 var popupModalTitleContent = popupModal.find('.pro-features-popup-modal-right-box-content');
3663 popupModalTitleBox.html(optionTitle);
3664 popupModalTitleContent.html(optionDesc);
3665
3666
3667 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3668
3669 if ( typeof optionVideoUrl != "undefined" && optionVideoUrl != "") {
3670 var videoID = ays_youtube_parser(optionVideoUrl);
3671 var iframeHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'+ videoID +'" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen loading="lazy"></iframe>';
3672
3673 leftSection.html(iframeHTML);
3674 }
3675
3676 popupModal.aysModal('show_flex');
3677 });
3678
3679 // Pro features end
3680
3681 // Check new added Survey start
3682 var createdNewSurvey = getCookie('ays_survey_created_new');
3683 if(createdNewSurvey && createdNewSurvey > 1){
3684 var url = new URL(window.location.href);
3685
3686 // Get a specific GET parameter by name
3687 var parameterValue = url.searchParams.get("action");
3688 var htmlDefaultText = '<p style="margin-top:1rem;">For more detailed configuration visit <a href="admin.php?page=survey-maker&action=edit&id=' + createdNewSurvey + '">edit survey page</a>.</p>';
3689
3690 var getCustomPostId = getCookie('ays_survey_created_new_'+createdNewSurvey+'_post_id');
3691 var htmlCustomPostMessage = '';
3692
3693 var link = "#";
3694 if(getCustomPostId){
3695 link = getCustomPostId;
3696 }
3697 var htmlContent = parameterValue && parameterValue == 'edit' ? '' : htmlDefaultText;
3698 htmlContent += htmlCustomPostMessage;
3699
3700 var previewButtonSvgIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">'+
3701 '<path d="M11.9999 7.21325C11.8231 7.21325 11.6535 7.28349 11.5285 7.40851C11.4035 7.53354 11.3333 7.70311 11.3333 7.87992V12.6666C11.3333 12.8434 11.263 13.013 11.138 13.138C11.013 13.263 10.8434 13.3333 10.6666 13.3333H3.33325C3.15644 13.3333 2.98687 13.263 2.86185 13.138C2.73682 13.013 2.66659 12.8434 2.66659 12.6666V5.33325C2.66659 5.15644 2.73682 4.98687 2.86185 4.86185C2.98687 4.73682 3.15644 4.66658 3.33325 4.66658H8.11992C8.29673 4.66658 8.4663 4.59635 8.59132 4.47132C8.71635 4.3463 8.78658 4.17673 8.78658 3.99992C8.78658 3.82311 8.71635 3.65354 8.59132 3.52851C8.4663 3.40349 8.29673 3.33325 8.11992 3.33325H3.33325C2.80282 3.33325 2.29411 3.54397 1.91904 3.91904C1.54397 4.29411 1.33325 4.80282 1.33325 5.33325V12.6666C1.33325 13.197 1.54397 13.7057 1.91904 14.0808C2.29411 14.4559 2.80282 14.6666 3.33325 14.6666H10.6666C11.197 14.6666 11.7057 14.4559 12.0808 14.0808C12.4559 13.7057 12.6666 13.197 12.6666 12.6666V7.87992C12.6666 7.70311 12.5963 7.53354 12.4713 7.40851C12.3463 7.28349 12.1767 7.21325 11.9999 7.21325ZM14.6133 1.74659C14.5456 1.58369 14.4162 1.45424 14.2533 1.38659C14.1731 1.35242 14.087 1.33431 13.9999 1.33325H9.99992C9.82311 1.33325 9.65354 1.40349 9.52851 1.52851C9.40349 1.65354 9.33325 1.82311 9.33325 1.99992C9.33325 2.17673 9.40349 2.3463 9.52851 2.47132C9.65354 2.59635 9.82311 2.66659 9.99992 2.66659H12.3933L5.52659 9.52658C5.4641 9.58856 5.4145 9.66229 5.38066 9.74353C5.34681 9.82477 5.32939 9.91191 5.32939 9.99992C5.32939 10.0879 5.34681 10.1751 5.38066 10.2563C5.4145 10.3375 5.4641 10.4113 5.52659 10.4733C5.58856 10.5357 5.66229 10.5853 5.74353 10.6192C5.82477 10.653 5.91191 10.6705 5.99992 10.6705C6.08793 10.6705 6.17506 10.653 6.2563 10.6192C6.33754 10.5853 6.41128 10.5357 6.47325 10.4733L13.3333 3.60659V5.99992C13.3333 6.17673 13.4035 6.3463 13.5285 6.47132C13.6535 6.59635 13.8231 6.66658 13.9999 6.66658C14.1767 6.66658 14.3463 6.59635 14.4713 6.47132C14.5963 6.3463 14.6666 6.17673 14.6666 5.99992V1.99992C14.6655 1.9128 14.6474 1.82673 14.6133 1.74659Z" fill="#007DCB"/>'+
3702 '</svg>';
3703
3704 swal({
3705 title: '<strong>Great job</strong>',
3706 type: 'success',
3707 html: '<p class="ays-survey-maker-swal2-created-row">Your Survey is Created!.</p><p>Copy the generated shortcode and paste it into any post or page to display Survey.</p><input type="text" id="ays-survey-create-new" onClick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_survey id=\'' + createdNewSurvey + '\']" />' + htmlContent,
3708 showCancelButton: true,
3709 showCloseButton: true,
3710 focusConfirm: false,
3711 cancelButtonClass: "ays-survey-preview-popup-cancel-button",
3712 confirmButtonText: '<i class="ays_fa ays_fa_thumbs_up"></i> Done',
3713 cancelButtonText: '<a href="'+ link +'" target="_blank">'+ SurveyMakerAdmin.preivewSurvey + ' ' + previewButtonSvgIcon +'</a>',
3714 confirmButtonAriaLabel: 'Thumbs up, great!',
3715 });
3716 deleteCookie('ays_survey_created_new');
3717 deleteCookie('ays_survey_created_new_'+createdNewSurvey+'_post_id');
3718 }
3719 // Check new added Survey end
3720
3721 $(document).find('input[type="submit"]#doaction, input[type="submit"]#doaction2').on('click', function(e) {
3722 showConfirmationIfDelete(e);
3723 });
3724
3725 $(document).on('mouseover', '.ays-dashicons', function(){
3726 var allRateStars = $(document).find('.ays-dashicons');
3727 var index = allRateStars.index(this);
3728 allRateStars.removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3729 for (var i = 0; i <= index; i++) {
3730 allRateStars.eq(i).removeClass('ays-dashicons-star-empty').addClass('ays-dashicons-star-filled');
3731 }
3732 });
3733
3734 $(document).on('mouseleave', '.ays-rated-link', function(){
3735 $(document).find('.ays-dashicons').removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3736 });
3737
3738 $(document).on('click', '.ays-survey-collapse-options', function(){
3739 var $this = $(this);
3740 var $thisRotateButton = $(this).find('.ays-survey-collapse-options-button');
3741 var $collapsibleOptions = $this.siblings('.ays-survey-collapsible-options');
3742 var newRotation = 0;
3743
3744 $collapsibleOptions.toggle();
3745
3746 var currentRotation = $thisRotateButton.data('rotation') || 0;
3747
3748 if(currentRotation === 0){
3749 newRotation = -90;
3750 $thisRotateButton.css('color' , '#c4c4c4')
3751 }
3752 else{
3753 newRotation = 0;
3754 $thisRotateButton.css('color' , '#008cff')
3755 }
3756
3757 $thisRotateButton.css('transform', `rotate(${newRotation}deg)`).data('rotation', newRotation);
3758 });
3759
3760 $(document).on('click', '.ays-survey-collapse-all-options', function(){
3761 var $thisMainParent = $(this).parents('.ays-survey-tab-content');
3762 var $thisRotateButtons = $thisMainParent.find('.ays-survey-collapse-options-button');
3763 var $collapsibleAllOptions = $thisMainParent.find('.ays-survey-collapsible-options');
3764 $collapsibleAllOptions.hide();
3765 $thisRotateButtons.css('color' , '#c4c4c4');
3766 $thisRotateButtons.css('transform', `rotate(-90deg)`).data('rotation', -90);
3767 });
3768
3769 $(document).on('click', '.ays-survey-expand-all-options', function(){
3770 var $thisMainParent = $(this).parents('.ays-survey-tab-content');
3771 var $thisRotateButtons = $thisMainParent.find('.ays-survey-collapse-options-button');
3772 var $collapsibleAllOptions = $thisMainParent.find('.ays-survey-collapsible-options');
3773 $collapsibleAllOptions.show();
3774 $thisRotateButtons.css('color' , '#008cff');
3775 $thisRotateButtons.css('transform', `rotate(0deg)`).data('rotation', 0);
3776 });
3777
3778 // Replace image to YouTube embed video
3779 $(document).on('click', '.ays-survey-youtube-placeholder', function() {
3780 var videoId = $(this).data('video-id');
3781 var iframe = $('<iframe>', {
3782 src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1',
3783 class: '',
3784 width: 560,
3785 height: 315,
3786 frameborder: 0,
3787 allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
3788 allowfullscreen: true,
3789 });
3790 $(this).replaceWith(iframe);
3791 });
3792
3793 $(document).on('click', 'body', function(e){
3794 if($(e.target).hasClass('ays-modal')){
3795 $(e.target).find(".ays-close").trigger("click");
3796 $(e.target).find(".ays-close-editor-popup").trigger("click");
3797 }
3798 });
3799
3800 function showConfirmationIfDelete(e) {
3801 var $el = $(e.target);
3802 var elParent = $el.parent();
3803 var actionSelect = elParent.find('select[name="action"]');
3804 var action = actionSelect.val();
3805
3806 if (action === 'bulk-delete') {
3807 e.preventDefault();
3808 var confirmDelete = confirm(SurveyMakerAdmin.deleteElementFromListTable);
3809
3810 if (confirmDelete) {
3811 var form = $el.closest('form');
3812 form.submit();
3813 }
3814 }
3815 }
3816
3817 function getCookie(cname) {
3818 let name = cname + "=";
3819 let decodedCookie = decodeURIComponent(document.cookie);
3820 let ca = decodedCookie.split(';');
3821 for(let i = 0; i <ca.length; i++) {
3822 let c = ca[i];
3823 while (c.charAt(0) == ' ') {
3824 c = c.substring(1);
3825 }
3826 if (c.indexOf(name) == 0) {
3827 return c.substring(name.length, c.length);
3828 }
3829 }
3830 return "";
3831 }
3832
3833 function ays_youtube_parser(url){
3834 var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
3835 var match = url.match(regExp);
3836 return (match&&match[7].length==11)? match[7] : false;
3837 }
3838
3839
3840 function deleteCookie(name) {
3841 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
3842 }
3843
3844 });
3845
3846 })( jQuery );
3847
3848 document.addEventListener("DOMContentLoaded", function() {
3849 var startDate = new Date("2025-09-21");
3850 var endDate = new Date("2025-10-21");
3851 var totalLicenses = 50;
3852 var progressionPattern = new Array(3, 2, 1, 4, 2, 3, 1, 2, 4, 3, 2, 1, 3, 2, 4, 1, 3, 2, 2, 3, 1, 2);
3853 function getCurrentProgress() {
3854 var today = new Date();
3855 // today.setDate(today.getDate() + 1);
3856 var daysPassed = Math.floor((today - startDate) / (1000 * 60 * 60 * 24));
3857 var usedLicenses = 0;
3858 for (var i = 0; i < Math.min(daysPassed, progressionPattern.length); i++) {
3859 usedLicenses += progressionPattern[i];
3860 }
3861 return Math.min(usedLicenses, totalLicenses);
3862 }
3863 function updateProgress() {
3864 var usedLicenses = getCurrentProgress();
3865 var remainingLicenses = totalLicenses - usedLicenses;
3866 var progressPercentage = (usedLicenses / totalLicenses) * 100;
3867 var remainingElement = document.getElementById("remaining-licenses");
3868 var progressElement = document.getElementById("progress-fill");
3869 if (remainingElement) remainingElement.textContent = remainingLicenses;
3870 if (progressElement) progressElement.style.width = progressPercentage + "%";
3871 }
3872 updateProgress();
3873 });
3874
3875 // Copy to clipboard function
3876 function surveyCopyToClipboard(text) {
3877 if (navigator.clipboard && window.isSecureContext) {
3878 navigator.clipboard.writeText(text).then(function() {
3879 surveyShowCopyNotification(SurveyMakerAdmin.successCopyCoupon);
3880 }).catch(function() {
3881 fallbackCopyTextToClipboard(text);
3882 });
3883 } else {
3884 fallbackCopyTextToClipboard(text);
3885 }
3886 }
3887
3888 function fallbackCopyTextToClipboard(text) {
3889 var textArea = document.createElement("textarea");
3890 textArea.value = text;
3891 textArea.style.position = "fixed";
3892 textArea.style.top = "-9999px";
3893 textArea.style.left = "-9999px";
3894 document.body.appendChild(textArea);
3895 textArea.focus();
3896 textArea.select();
3897 try {
3898 var successful = document.execCommand("copy");
3899 if (successful) {
3900 surveyShowCopyNotification(SurveyMakerAdmin.successCopyCoupon);
3901 } else {
3902 surveyShowCopyNotification(SurveyMakerAdmin.failedCopyCoupon);
3903 }
3904 } catch (err) {
3905 surveyShowCopyNotification(SurveyMakerAdmin.failedCopyCoupon);
3906 }
3907 document.body.removeChild(textArea);
3908 }
3909
3910 function surveyShowCopyNotification(message) {
3911 var notification = document.createElement("div");
3912 notification.className = "ays-survey-copy-notification show";
3913 console.log(notification);
3914 notification.textContent = message;
3915 document.body.appendChild(notification);
3916 setTimeout(function() {
3917 notification.classList.remove("show");
3918 setTimeout(function() {
3919 document.body.removeChild(notification);
3920 }, 300);
3921 }, 2000);
3922 }