PluginProbe
Survey Maker by AYS / 5.2.1.8
Survey Maker by AYS v5.2.1.8
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.1.8, at admin/js/survey-maker-admin.js

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