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

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

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