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

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

4,144 lines 234.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2 'use strict';
3 $.fn.serializeFormJSON = function () {
4 let o = {},
5 a = this.serializeArray();
6 $.each(a, function () {
7 if (o[this.name]) {
8 if (!o[this.name].push) {
9 o[this.name] = [o[this.name]];
10 }
11 o[this.name].push(this.value || '');
12 } else {
13 o[this.name] = this.value || '';
14 }
15 });
16 return o;
17 };
18
19 $.fn.goToTop = function() {
20 this.get(0).scrollIntoView({
21 block: "center",
22 behavior: "smooth"
23 });
24 }
25
26 $.fn.goTo = function() {
27 $('html, body').animate({
28 scrollTop: this.offset().top - 200 + 'px'
29 }, 'fast');
30 return this; // for chaining...
31 }
32
33 $.fn.goToNormal = function() {
34 $('html, body').animate({
35 scrollTop: this.offset().top - 200 + 'px'
36 }, 'normal');
37 return this; // for chaining...
38 }
39
40 $(document).ready(function () {
41
42 var maxInputVarsPannelBox = $(document).find('.ays-survey-general-action-max-inps-vars');
43 var maxInputVarsTabsBox = $(document).find('.ays-survey-max-inp-vars-tabs-box');
44 var maxInputVars = +maxInputVarsPannelBox.attr('data-max-inp-vars');
45 if(typeof maxInputVars != 'undefined' && maxInputVars){
46 var filledInputs = +$(':input').filter(function() {return this.value;}).length;
47
48 var calcVarsDiff = maxInputVars - filledInputs;
49 if(calcVarsDiff <= 200){
50 if(calcVarsDiff <= 0){
51 filledInputs = maxInputVars
52 }
53 maxInputVarsPannelBox.removeClass('display_none');
54 maxInputVarsTabsBox.removeClass('display_none');
55 var varsMessageText = SurveyMakerAdmin.maxInputVarsWarningMessage;
56 varsMessageText = varsMessageText.replace(/%f/g, maxInputVars);
57 varsMessageText = varsMessageText.replace(/%t/g, filledInputs);
58 maxInputVarsPannelBox.attr('data-content' , varsMessageText);
59 maxInputVarsTabsBox.find('.ays-survey-max-inp-vars-texts-content').text(varsMessageText);
60 }
61 }
62
63
64 setInterval(function () {
65 $('div.ays-quiz-maker-wrapper h1 i.ays_fa').toggleClass('pulse');
66 $(document).find('.ays_heart_beat i.ays_fa').toggleClass('ays_pulse');
67 }, 1000);
68
69
70 // Disabling submit when press enter button on inputing
71 $(document).on("input", 'input', function(e){
72 if(e.keyCode == 13){
73 if($(document).find("#ays-survey-form").length !== 0 ||
74 $(document).find("#ays-survey-category-form").length !== 0 ||
75 $(document).find("#ays-survey-settings-form").length !== 0){
76 return false;
77 }
78 }
79 });
80
81 $(document).on("keydown", function(e){
82 if(e.target.nodeName == "TEXTAREA"){
83 return true;
84 }
85 if(e.keyCode == 13){
86 if($(document).find("#ays-survey-form").length !== 0 ||
87 $(document).find("#ays-survey-category-form").length !== 0 ||
88 $(document).find("#ays-survey-settings-form").length !== 0){
89 return false;
90 }
91 }
92
93 if ( ( e.ctrlKey && e.which == 83 ) && !( e.which == 19 ) ){
94 var saveButton = $(document).find("input#ays-button-apply, input.ays-survey-gen-settings-save");
95 if( saveButton.length > 0 ){
96 e.preventDefault();
97 saveButton.trigger("click");
98 }
99 return false;
100 }
101
102 if(e.keyCode === 27){
103 $(document).find('.ays-modal').aysModal('hide');
104 return false;
105 }
106 });
107
108 var answerAddedByEnter = false;
109 $(document).on("keyup", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
110 answerAddedByEnter = false;
111 });
112
113 $(document).on("focus", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
114 var _this = $(this);
115 setTimeout(function(){
116 _this.get(0).setSelectionRange(0, _this.get(0).value.length);
117 // _this.select();
118 }, 1);
119 });
120
121 $(document).on("keydown", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
122 if( answerAddedByEnter === false ) {
123 answerAddedByEnter = true;
124
125 if(e.keyCode === 13){
126 aysSurveyAddAnswer( $(this), true );
127 }
128
129 if(e.keyCode == 38 && !e.ctrlKey && !e.shiftKey ){
130 var ansCont = $(this).parents('.ays-survey-answer-row');
131 if( ansCont.prev().length > 0 ){
132 ansCont.prev().find(".ays-survey-answer-box input.ays-survey-input").trigger('focus');
133 }else{
134 return false;
135 }
136 }
137
138 if(e.keyCode === 40 && !e.ctrlKey && !e.shiftKey ){
139 var ansCont = $(this).parents('.ays-survey-answer-row');
140 if( ansCont.next().length > 0 ){
141 ansCont.next().find(".ays-survey-answer-box input.ays-survey-input").trigger('focus');
142 }else{
143 var questCont = $(this).parents('.ays-survey-question-answer-conteiner');
144 questCont.find('.ays-survey-action-add-answer').trigger('click');
145 }
146 }
147
148 if(e.keyCode === 8){
149 if( $(this).val() == '' ){
150 var thatNext = $(this).parents('.ays-survey-answer-row').next().find('input.ays-survey-input');
151 var thatPrev = $(this).parents('.ays-survey-answer-row').prev().find('input.ays-survey-input');
152 if( thatPrev.length > 0 ){
153 thatPrev.trigger('focus');
154 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
155 }else if( thatNext.length > 0 ){
156 thatNext.trigger('focus');
157 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
158 }
159 return false;
160 }
161 }
162
163 if(e.keyCode === 46){
164 if( $(this).val() == '' ){
165 var thatNext = $(this).parents('.ays-survey-answer-row').next().find('input.ays-survey-input');
166 var thatPrev = $(this).parents('.ays-survey-answer-row').prev().find('input.ays-survey-input');
167 if( thatNext.length > 0 ){
168 thatNext.trigger('focus');
169 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
170 }else if( thatPrev.length > 0 ){
171 thatPrev.trigger('focus');
172 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
173 }
174 return false;
175 }
176 }
177 }
178 });
179
180 // Notifications dismiss button
181 var $html_name_prefix = 'ays_';
182 $(document).on('click', '.notice-dismiss', function (e) {
183 changeCurrentUrl('status');
184 });
185
186 if(location.href.indexOf('del_stat')){
187 setTimeout(function(){
188 changeCurrentUrl('del_stat');
189 changeCurrentUrl('mcount');
190 }, 500);
191 }
192
193 var aysSurveyTextArea = $(document).find('textarea.ays-survey-question-input-textarea');
194 autosize(aysSurveyTextArea);
195 var aysSurveyDescriptionTextArea = $(document).find('textarea.ays-survey-section-description');
196 autosize(aysSurveyDescriptionTextArea);
197
198
199 function changeCurrentUrl(key){
200 var linkModified = location.href.split('?')[1].split('&');
201 for(var i = 0; i < linkModified.length; i++){
202 if(linkModified[i].split("=")[0] == key){
203 linkModified.splice(i, 1);
204 }
205 }
206 linkModified = linkModified.join('&');
207 window.history.replaceState({}, document.title, '?'+linkModified);
208 }
209
210 // Quiz toast close button
211 jQuery('.quiz_toast__close').click(function(e){
212 e.preventDefault();
213 var parent = $(this).parent('.quiz_toast');
214 parent.fadeOut("slow", function() { $(this).remove(); } );
215 });
216
217 var toggle_ddmenu = $(document).find('.toggle_ddmenu');
218 toggle_ddmenu.on('click', function () {
219 var ddmenu = $(this).next();
220 var state = ddmenu.attr('data-expanded');
221 switch (state) {
222 case 'true':
223 $(this).find('.ays_fa').css({
224 transform: 'rotate(0deg)'
225 });
226 ddmenu.attr('data-expanded', 'false');
227 break;
228 case 'false':
229 $(this).find('.ays_fa').css({
230 transform: 'rotate(90deg)'
231 });
232 ddmenu.attr('data-expanded', 'true');
233 break;
234 }
235 });
236
237 var ays_results = $(document).find('.ays_result_read');
238 for (var i in ays_results) {
239 if (typeof ays_results.eq(i).val() != 'undefined') {
240 if ( ays_results.eq(i).val() == 0 || ays_results.eq(i).val() == 2 ) {
241 ays_results.eq(i).parents('tr').addClass('ays_read_result');
242 }
243 }
244 }
245
246 // Check if save button closed for unsaved changes confirmation box
247 var subButtons = '#ays_apply_top.button, #ays_apply.button, #ays_submit_top.button, #ays_submit.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-apply-top.button, #ays-button-apply.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-save.button, #ays-button-save-top.button, #ays-button.button';
248 $(document).on('click', subButtons ,function () {
249 var $this = $(this);
250 if(!$this.hasClass('ays-save-button-clicked')){
251 $this.addClass('ays-save-button-clicked');
252 }
253 });
254
255 setTimeout(function() {
256 var aysUnsavedChanges = false;
257
258 var selectorsArr = [
259 '#ays-survey-form .ays-survey-tab-content input',
260 '#ays-survey-form .ays-survey-tab-content select',
261 '#ays-survey-form .ays-survey-tab-content textarea',
262 '#ays-survey-category-form .ays-survey-tab-content input',
263 '#ays-survey-category-form .ays-survey-tab-content select',
264 '#ays-survey-category-form .ays-survey-tab-content textarea',
265 '#ays-survey-popup-surveys-form .ays-survey-tab-content input',
266 '#ays-survey-popup-surveys-form .ays-survey-tab-content select',
267 '#ays-survey-popup-surveys-form .ays-survey-tab-content textarea',
268 '#ays-survey-settings-form input',
269 '#ays-survey-settings-form select',
270 '#ays-survey-settings-form textarea',
271 ];
272
273 var formInputs = selectorsArr.join(',');
274
275 $(document).on('change input', formInputs, function() {
276 aysUnsavedChanges = true;
277 });
278
279 $(window).on('beforeunload', function(event) {
280 var saveButtons = $(document).find('#ays_apply_top.button, #ays_apply.button, #ays_submit_top.button, #ays_submit.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-apply-top.button, #ays-button-apply.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-save.button, #ays-button-save-top.button, #ays-button.button');
281 var savingButtonsClicked = saveButtons.filter('.ays-save-button-clicked').length > 0;
282
283 if (aysUnsavedChanges && !savingButtonsClicked) {
284 event.preventDefault();
285 event.returnValue = true;
286 }
287 });
288 }, 1000);
289
290
291 // $('[data-toggle="popover"]').popover();
292
293 $(document).find('.ays-survey-sections-conteiner [data-toggle="popover"]').popover();
294 $(document).find('.aysFormeditorViewFatRoot [data-toggle="popover"]').popover();
295 $(document).find('.ays_survey_previous_next [data-toggle="popover"]').popover();
296 $('[data-toggle="tooltip"]').tooltip();
297
298 $(document).find('.ays_survey_aysDropdown').aysDropdown();
299 $(document).find('[data-toggle="dropdown"]').dropdown();
300 // $('.dropdown-toggle').dropdown()
301
302 // Disabling submit when press enter button on inputing
303 $(document).on("input", 'input', function(e){
304 if(e.keyCode == 13){
305 if($(document).find("#ays-question-form").length !== 0 ||
306 $(document).find("#ays-survey-category-form").length !== 0 ||
307 $(document).find("#ays-survey-settings-form").length !== 0){
308 return false;
309 }
310 }
311 });
312
313 $(document).find('strong.ays-survey-shortcode-box.ays_survey_each_sub_user_info_header_button button').on('mouseleave', function(){
314 var _this = $(this);
315
316 _this.attr( 'data-original-title', SurveyMakerAdmin.clickForCopy );
317 _this.attr( 'title', SurveyMakerAdmin.clickForCopy );
318 });
319
320 // Modal close
321
322 $(document).find('.ays-close').on('click', function () {
323 $(document).find('.ays-modal').aysModal('hide');
324 });
325
326 $(document).find('.ays-close-editor-popup').on('click', function () {
327 $(document).find('.ays-modal').aysEditorModal('hide');
328 });
329
330 $(document).find('.ays-close-templates-popup').on('click', function (e) {
331 var $this = $(this);
332 var dataAction = $this.attr('data-action');
333 if(dataAction && dataAction !== 'ays-close-templates'){
334 e.preventDefault();
335 $(document).find('#ays-survey-templates-modal').aysModal('hide');
336 }
337
338 });
339
340 $(document).find('.ays-close-pro-popup').on('click', function () {
341 $(this).parents('.ays-modal').aysModal('hide_remove_video');
342 });
343
344
345 $(document).on('change', '.ays_toggle_checkbox', function (e) {
346 var state = $(this).prop('checked');
347 var parent = $(this).parents('.ays_toggle_parent');
348
349 if($(this).hasClass('ays_toggle_slide')){
350 switch (state) {
351 case true:
352 parent.find('.ays_toggle_target').slideDown(250);
353 break;
354 case false:
355 parent.find('.ays_toggle_target').slideUp(250);
356 break;
357 }
358 }else{
359 switch (state) {
360 case true:
361 parent.find('.ays_toggle_target').show(250);
362 break;
363 case false:
364 parent.find('.ays_toggle_target').hide(250);
365 break;
366 }
367 }
368 });
369
370 $(document).on('change', '.ays_toggle_select', function (e) {
371 var state = $(this).val();
372 var toggle = $(this).data('hide');
373 var parent = $(this).parents('.ays_toggle_parent');
374
375 if($(this).hasClass('ays_toggle_slide')){
376 if (toggle == state) {
377 parent.find('.ays_toggle_target').slideUp(250);
378 parent.find('.ays_toggle_target_inverse').slideDown(150);
379 }else{
380 parent.find('.ays_toggle_target').slideDown(150);
381 parent.find('.ays_toggle_target_inverse').slideUp(250);
382 }
383 }else{
384 if (toggle == state) {
385 parent.find('.ays_toggle_target').hide(150);
386 parent.find('.ays_toggle_target_inverse').show(250);
387 }else{
388 parent.find('.ays_toggle_target').show(250);
389 parent.find('.ays_toggle_target_inverse').hide(150);
390 }
391 }
392 });
393
394
395 $(document).find('#ays-category').select2({
396 placeholder: 'Select category'
397 });
398
399 $(document).find('#ays-status').select2({
400 placeholder: 'Select status'
401 });
402
403 // 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 newElement.find('.ays-survey-question-value-prefix-saver').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_value_prefix'));
1087 newElement.find('.ays-survey-question-value-prefix-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'value_prefix'));
1088 newElement.find('.ays-survey-question-value-suffix-saver').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_value_suffix'));
1089 newElement.find('.ays-survey-question-value-suffix-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'value_suffix'));
1090
1091 // Input types placeholders
1092 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'));
1093
1094 newElement.find('input.ays-survey-question-image-caption').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'image_caption') );
1095 newElement.find('input.ays-survey-question-img-caption-enable').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'image_caption_enable') );
1096
1097 newElement.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'with_editor'));
1098 if( newElement.find('select.ays-survey-question-type').length ){
1099 newElement.find('select.ays-survey-question-type').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'type') );
1100 }else if( newElement.find('.ays-survey-question-type select').length ){
1101 newElement.find('.ays-survey-question-type select').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'type') );
1102 }
1103 var ddElem = newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('get text');
1104 newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('set text', ddElem);
1105 newElement.find('.ays-survey-question-conteiner .ays-survey-question-type select option[value="'+question_type+'"]').prop('selected', true);
1106 // newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('set selected', question_type);
1107 newElement.find('.ays_question_ids').val(question_length);
1108 newElement.find('.ays_question_old_ids').remove();
1109
1110 var answer = newElement.find('.ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input').each(function(i){
1111 $(this).parents('.ays-survey-answer-row').attr( 'data-id', i+1 );
1112 $(this).parents('.ays-survey-answer-row').attr( 'data-name', 'answers_add' );
1113 $(this).parents('.ays-survey-answer-row').addClass('ays-survey-new-answer');
1114 $(this).attr('name', newAnswerAttrName( sectionName, sectionId, newElement.attr('data-name'), question_length, i+1, 'title') );
1115 $(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') );
1116 $(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') );
1117 });
1118
1119 newElement.find('.ays-survey-answers-conteiner').sortable(answerDragHandle);
1120 newElement.find('.ays-survey-question-word-limit-by-select select option[value="'+clonedLimitBy+'"]').prop('selected', true);
1121
1122 if( question_type == 'select' ){
1123 newElement.find('.ays-survey-other-answer-row').hide();
1124 newElement.find('.ays-survey-other-answer-checkbox').prop('checked', false );
1125 newElement.find('.ays-survey-other-answer-add-wrap').hide();
1126 }
1127
1128 newElement.find('.ays-survey-question-type').aysDropdown();
1129 cloningElement.find('.ays-survey-question-type').aysDropdown();
1130
1131 var aysSurveyTextArea = newElement.find('textarea.ays-survey-question-input-textarea');
1132 autosize(aysSurveyTextArea);
1133 if( newElement.find('.dropdown .divider').length == 0 ){
1134 newElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1135 newElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1136 }
1137 if( cloningElement.find('.dropdown .divider').length == 0 ){
1138 cloningElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1139 cloningElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1140 }
1141 $this.parents('.ays-survey-section-box').find('.ays-survey-question-ordering').each(function(i){
1142 $(this).val(i+1);
1143 });
1144 // newElement.find('.ays-survey-question-type').dropdown('refresh');
1145 // var answerImg = newElement.find('.aysFormeditorAnswerConteiner input.quantumWizTextinputSimpleinputInput').each(function(i){
1146 // $(this).attr('name', $html_name_prefix + 'section_add['+ sectionId +'][question]['+ question_length +'][answer]['+ i +'][title]');
1147 // });
1148
1149 setTimeout(function(){
1150 newElement.goToTop();
1151 }, 100 );
1152
1153 reInitPopovers( newElement );
1154 aysSurveySectionsInitQuestionsCollapse();
1155 });
1156
1157 // Remove Question Button
1158 $(document).on('click', '.ays-survey-action-delete-question', function(e){
1159 var $this = $(this);
1160 var length = $this.parents('.ays-survey-section-questions').find('.ays-survey-question-answer-conteiner').length;
1161 var status = true;
1162 if(length == 1){
1163 swal.fire({
1164 type: 'warning',
1165 text: SurveyMakerAdmin.minimumCountOfQuestions
1166 });
1167 status = false;
1168 }else{
1169 swal({
1170 html:"<h4>"+ SurveyMakerAdmin.questionDeleteConfirmation +"</h4>",
1171 type: 'error',
1172 showCloseButton: true,
1173 showCancelButton: true,
1174 allowOutsideClick: true,
1175 allowEscapeKey: true,
1176 allowEnterKey: true,
1177 confirmButtonColor: '#d33',
1178 cancelButtonColor: '#3085d6',
1179 confirmButtonText: SurveyMakerAdmin.yes,
1180 cancelButtonText: SurveyMakerAdmin.cancel
1181 }).then( function(result) {
1182
1183 if( result.dismiss && result.dismiss == 'close' ){
1184 return false;
1185 }
1186
1187 var deleteQuest = false;
1188 if (result.value) deleteQuest = true;
1189
1190 if( deleteQuest ){
1191 if( ! $this.parents('.ays-survey-question-answer-conteiner').hasClass('ays-survey-new-question') ){
1192 var qId = $this.parents('.ays-survey-question-answer-conteiner').data('id');
1193 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'questions_delete[]" value="'+ qId +'">';
1194 $this.parents('form').append( delImp );
1195 }
1196 var section = $this.parents('.ays-survey-section-box');
1197 section.find(".ays-survey-action-questions-count span").text(length - 1);
1198 $this.parents('.ays-survey-question-answer-conteiner').remove();
1199 }
1200 } );
1201 }
1202
1203 if (status == false) {
1204 e.preventDefault();
1205 }
1206
1207 });
1208
1209 // Remove Section Button
1210 $(document).on('click', '.ays-survey-delete-section', function(e){
1211 var $this = $(this);
1212
1213 swal({
1214 html:"<h4>"+ SurveyMakerAdmin.sectionDeleteConfirmation +"</h4>",
1215 type: 'error',
1216 showCloseButton: true,
1217 showCancelButton: true,
1218 allowOutsideClick: true,
1219 allowEscapeKey: true,
1220 allowEnterKey: true,
1221 confirmButtonColor: '#d33',
1222 cancelButtonColor: '#3085d6',
1223 confirmButtonText: SurveyMakerAdmin.yes,
1224 cancelButtonText: SurveyMakerAdmin.cancel
1225 }).then( function(result) {
1226
1227 if( result.dismiss && result.dismiss == 'close' ){
1228 return false;
1229 }
1230
1231 var deleteQuest = false;
1232 if (result.value) deleteQuest = true;
1233
1234 if( deleteQuest ){
1235 var parent = $this.parents('.ays-survey-section-box');
1236 if( ! parent.hasClass('ays-survey-new-section') ){
1237 var sId = parent.data('id');
1238 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'sections_delete[]" value="'+ sId +'">';
1239 $this.parents('form').append( delImp );
1240 }
1241 parent.remove();
1242
1243 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1244 var sections = sectionCont.find('.ays-survey-section-box');
1245 var addQuestionButton = $(document).find('.ays-survey-general-action[data-action="add-question"]');
1246
1247 var length = sectionCont.find('.ays-survey-section-box').length;
1248 sections.each(function(i, el){
1249 $(this).find('.ays-survey-section-number').text(i+1);
1250 $(this).find('.ays-survey-sections-count').text( sections.length );
1251 });
1252
1253 if (length == 1) {
1254 addQuestionButton.dropdown('dispose');
1255 addQuestionButton.removeAttr('data-toggle');
1256 sections.find('.ays-survey-section-head-top').addClass('display_none');
1257 sections.find('.ays-survey-section-head').removeClass('ays-survey-section-head-topleft-border-none');
1258 sections.find('.ays-survey-section-actions-more .ays-survey-delete-section').addClass('display_none');
1259 }
1260
1261 aysSurveySectionsInitToAddQuestions();
1262 }
1263 } );
1264 });
1265
1266 // Remove Answer Image
1267 $(document).on('click', '.removeAnswerImage', function (e) {
1268 var $this = $(this);
1269 $this.parents('.ays-survey-answer-image-container').fadeOut(500);
1270 setTimeout(function(){
1271 $this.parents('.ays-survey-answer-image-container').find('.ays-survey-answer-img').removeAttr('src');
1272 $this.parents('.ays-survey-answer-image-container').find('.ays-survey-answer-img-src').val('');
1273 }, 500);
1274 });
1275
1276 // Survey Question Image actions Buttons
1277 $(document).on('click', '.ays-survey-question-img-action', function(e){
1278 var $this = $(this);
1279
1280 var action = $this.attr('data-action');
1281
1282 switch( action ){
1283 case 'edit-image':
1284 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-add-question-image').trigger('click');
1285 break;
1286 case 'delete-image':
1287 $this.parents('.ays-survey-question-image-container').fadeOut(500);
1288 setTimeout(function(){
1289 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img').removeAttr('src');
1290 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-src').val('');
1291 }, 500);
1292 break;
1293 case 'add-caption':
1294 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-image-caption-text-row').removeClass('display_none');
1295 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-caption-enable').val('on');
1296 $this.parents('.ays-survey-question-image-container').find('.ays-survey-input.ays-survey-question-image-caption').focus();
1297 $this.attr('data-action' , 'close-caption');
1298 $this.text(SurveyMakerAdmin.closeQuestionImageCaption);
1299 break;
1300 case 'close-caption':
1301 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-image-caption-text-row').addClass('display_none');
1302 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-caption-enable').val('off');
1303 $this.attr('data-action' , 'add-caption');
1304 $this.text(SurveyMakerAdmin.addQuestionImageCaption);
1305 break;
1306 }
1307 });
1308
1309 // Survey General actions Buttons
1310 $(document).on('click', '.ays-survey-general-action', function(e){
1311 var $this = $(this);
1312 var action = $this.data('action');
1313 switch( action ){
1314 case 'add-question':
1315 if(! $this.attr('data-toggle')){
1316 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1317 var sections = sectionCont.find('.ays-survey-section-box');
1318 aysSurveyAddQuestion( sections.data('id'), false, sections );
1319 }
1320 break;
1321 case 'import-question':
1322
1323 break;
1324 case 'add-section-header':
1325
1326 break;
1327 case 'add-image':
1328
1329 break;
1330 case 'add-video':
1331
1332 break;
1333 case 'add-section':
1334 aysSurveyAddSection( null, null );
1335 aysSurveySectionsInitToAddQuestions();
1336 break;
1337 case 'save-changes':
1338 $(document).find('#ays-button-apply-top').trigger('click');
1339 break;
1340 case 'make-questions-required':
1341 makeAllQuestionsRequired($this , false);
1342 break;
1343 }
1344 });
1345
1346 // Survey Question actions Buttons
1347 $(document).on('click', '.ays-survey-question-action', function(e){
1348 var $this = $(this);
1349 var action = $this.attr('data-action');
1350 var $thisEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count,.ays-survey-question-min-selection-count');
1351 var $thisWordEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations');
1352 var $thisNumberEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations');
1353 var enableNumberLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations-checkbox');
1354
1355 var currentSection = $this.parents('.ays-survey-section-box');
1356 var currentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1357 var sectionId = currentSection.attr('data-id');
1358 var sectionName = currentSection.attr('data-name');
1359 var questionId = currentQuestion.attr('data-id');
1360 var questionName = currentQuestion.attr('data-name');
1361
1362 switch( action ){
1363 case 'max-selection-count-enable':
1364 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1365 enableCheckbox.prop('checked', true);
1366 $thisEl.removeClass('display_none');
1367 $this.attr('data-action', 'max-selection-count-disable');
1368 break;
1369 case 'max-selection-count-disable':
1370 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1371 enableCheckbox.prop('checked', false);
1372 $thisEl.addClass('display_none');
1373 $this.attr('data-action', 'max-selection-count-enable');
1374 break;
1375 case 'word-limitation-enable':
1376 var enableTextLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1377 enableTextLimit.prop('checked', true);
1378 $thisWordEl.removeClass('display_none');
1379 $this.attr('data-action', 'word-limitation-disable');
1380 break;
1381 case 'word-limitation-disable':
1382 var enableTextLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1383 enableTextLimit.prop('checked', false);
1384 $thisWordEl.addClass('display_none');
1385 $this.attr('data-action', 'word-limitation-enable');
1386 break;
1387 case 'number-word-limitation-enable':
1388 enableNumberLimit.prop('checked', true);
1389 $thisNumberEl.removeClass('display_none');
1390 $this.attr('data-action', 'number-word-limitation-disable');
1391 break;
1392 case 'number-word-limitation-disable':
1393 enableNumberLimit.prop('checked', false);
1394 $thisNumberEl.addClass('display_none');
1395 $this.attr('data-action', 'number-word-limitation-enable');
1396 break;
1397 case 'move-to-section':
1398 var popup = $(document).find('#ays-survey-move-to-section');
1399 popup.attr('data-section-id', sectionId);
1400 popup.attr('data-section-name', sectionName);
1401 popup.attr('data-question-id', questionId);
1402 popup.attr('data-question-name', questionName);
1403 aysSurveySectionsInitToMoveQuestions( currentSection, currentQuestion );
1404 popup.aysModal('show');
1405 break;
1406 case 'enable-admin-note':
1407 aysSurveySetAdminNoteState( $this.parents('.ays-survey-question-answer-conteiner'), true );
1408 break;
1409 case 'disable-admin-note':
1410 aysSurveySetAdminNoteState( $this.parents('.ays-survey-question-answer-conteiner'), false );
1411 break;
1412 case 'enable-value-prefix':
1413 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1414 var enableCheckbox = parentQuestion.find('.ays-survey-question-value-prefix-saver');
1415 parentQuestion.find('.ays-survey-question-value-prefix').removeClass('display_none');
1416 enableCheckbox.val('on');
1417 $this.find('.ays-survey-question-action-icon').removeClass('display_none');
1418 $this.attr('data-action', 'disable-value-prefix');
1419 break;
1420 case 'disable-value-prefix':
1421 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1422 var enableCheckbox = parentQuestion.find('.ays-survey-question-value-prefix-saver');
1423 parentQuestion.find('.ays-survey-question-value-prefix').addClass('display_none');
1424 enableCheckbox.val('off');
1425 $this.find('.ays-survey-question-action-icon').addClass('display_none');
1426 $this.attr('data-action', 'enable-value-prefix');
1427 break;
1428 case 'enable-value-suffix':
1429 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1430 var enableCheckbox = parentQuestion.find('.ays-survey-question-value-suffix-saver');
1431 parentQuestion.find('.ays-survey-question-value-suffix').removeClass('display_none');
1432 enableCheckbox.val('on');
1433 $this.find('.ays-survey-question-action-icon').removeClass('display_none');
1434 $this.attr('data-action', 'disable-value-suffix');
1435 break;
1436 case 'disable-value-suffix':
1437 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1438 var enableCheckbox = parentQuestion.find('.ays-survey-question-value-suffix-saver');
1439 parentQuestion.find('.ays-survey-question-value-suffix').addClass('display_none');
1440 enableCheckbox.val('off');
1441 $this.find('.ays-survey-question-action-icon').addClass('display_none');
1442 $this.attr('data-action', 'enable-value-suffix');
1443 break;
1444 }
1445 });
1446
1447 $(document).on('click', '.ays-survey-admin-note-delete', function(e){
1448 e.preventDefault();
1449
1450 var $this = $(this);
1451 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1452
1453 $this.popover('hide');
1454 aysSurveySetAdminNoteState( parentQuestion, false );
1455 });
1456
1457 function aysSurveySetAdminNoteState( parentQuestion, enabled ){
1458 var adminNoteAction = parentQuestion.find('.ays-survey-question-action[data-action="enable-admin-note"], .ays-survey-question-action[data-action="disable-admin-note"]');
1459 var adminNoteSaver = parentQuestion.find('.ays-survey-question-admin-note-saver');
1460 var adminNote = parentQuestion.find('.ays-survey-question-admin-note');
1461
1462 if( enabled ){
1463 adminNote.removeClass('display_none');
1464 adminNoteSaver.val('on');
1465 adminNoteAction.find('.ays-survey-question-action-icon').removeClass('display_none');
1466 adminNoteAction.attr('data-action', 'disable-admin-note');
1467 }else{
1468 adminNote.addClass('display_none');
1469 adminNoteSaver.val('off');
1470 adminNoteAction.find('.ays-survey-question-action-icon').addClass('display_none');
1471 adminNoteAction.attr('data-action', 'enable-admin-note');
1472 }
1473 }
1474
1475 $(document).on('show.bs.dropdown', '.ays-survey-question-more-actions', function(e){
1476 // var $this = $(this);
1477 // var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1478 // if( enableCheckbox.prop('checked') == true ){
1479 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.disableMaxSelectionCount);
1480 // }else{
1481 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.enableMaxSelectionCount);
1482 // }
1483
1484 // if( $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-type').aysDropdown( 'get value' ) == 'checkbox' ){
1485 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').removeClass('display_none');
1486 // }
1487 var $this = $(this);
1488 // var question = $this.parents('.ays-survey-question-answer-conteiner');
1489 var questionType = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-type').aysDropdown( 'get value' );
1490 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1491 var enableWordLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1492 var enableNumberLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations-checkbox');
1493 if( enableCheckbox.prop('checked') == true ){
1494 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.disableSelectionCount);
1495 }else{
1496 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.enableSelectionCount);
1497 }
1498
1499 if( questionType == 'checkbox' ){
1500 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').removeClass('display_none');
1501 }else{
1502 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').addClass('display_none');
1503 }
1504
1505 if( enableWordLimit.prop('checked') == true ){
1506 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').text(SurveyMakerAdmin.disableWordLimitation);
1507 }else{
1508 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').text(SurveyMakerAdmin.enableWordLimitation);
1509 }
1510
1511 if( questionType == 'short_text' || questionType == 'text' ){
1512 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').removeClass('display_none');
1513 }else{
1514 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').addClass('display_none');
1515 }
1516
1517 if( enableNumberLimit.prop('checked') == true ){
1518 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').text(SurveyMakerAdmin.disableNumberLimitation);
1519 }else{
1520 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').text(SurveyMakerAdmin.enableNumberLimitation);
1521 }
1522
1523 if( questionType == 'number' || questionType == 'phone'){
1524 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').removeClass('display_none');
1525 }else{
1526 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').addClass('display_none');
1527 }
1528
1529 if( questionType == 'short_text' || questionType == 'number' || questionType == 'phone' ){
1530 $this.find('.ays-survey-question-action[data-action$="value-prefix"]').removeClass('display_none');
1531 $this.find('.ays-survey-question-action[data-action$="value-suffix"]').removeClass('display_none');
1532 }else{
1533 $this.find('.ays-survey-question-action[data-action$="value-prefix"]').addClass('display_none');
1534 $this.find('.ays-survey-question-action[data-action$="value-suffix"]').addClass('display_none');
1535 }
1536 });
1537
1538 $(document).on('click', '.ays-survey-add-question-to-this-section', function(e){
1539 var section = $(this).parents('.ays-survey-section-box');
1540
1541 var sectionId = section.attr('data-id');
1542 aysSurveyAddQuestion( sectionId, false, section );
1543
1544 });
1545
1546 $(document).on('click', '.ays-survey-add-new-section-from-bottom', function(e){
1547 var afterSectionId = $(this).parents('.ays-survey-section-box').attr('data-id');
1548 var newSection = $(this).parents('.ays-survey-section-box').hasClass('ays-survey-new-section');
1549 aysSurveyAddSection( afterSectionId, newSection );
1550 aysSurveySectionsInitToAddQuestions();
1551 });
1552
1553 $(document).on('click', '.ays-survey-duplicate-section', function(e){
1554 var afterSectionId = $(this).parents('.ays-survey-section-box').data('id');
1555 $(this).parents('.ays-survey-section-box').find(".ays-survey-delete-section").removeClass('display_none');
1556 var newSection = $(this).parents('.ays-survey-section-box').hasClass('ays-survey-new-section');
1557 aysSurveyDuplicateSection( $(this), afterSectionId, newSection);
1558 });
1559
1560 $(document).on('click', '.ays-survey-add-question-into-section', function(e){
1561 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+ $(this).data( 'id' ) +'"]:not(.ays-survey-new-section)');
1562 if( $(this).hasClass('ays-survey-add-new-question-into-section') ){
1563 section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box.ays-survey-new-section[data-id="'+ $(this).data( 'id' ) +'"]');
1564 }
1565 var sectionId = $(this).attr( 'data-id' );
1566 aysSurveyAddQuestion( sectionId, false, section );
1567 });
1568
1569 $(document).on('change', '.ays-survey-question-type', function(e) {
1570 var $this = $(this);
1571 var parent = $this.parents('.ays-survey-section-box');
1572 var sectionId = parent.attr('data-id');
1573 var questionId = $this.parents('.ays-survey-question-answer-conteiner').attr('data-id');
1574 var questionDataName = $this.parents('.ays-survey-question-answer-conteiner').attr('data-name');
1575 var questionType = $this.aysDropdown('get value'); //$this.val();
1576 var questionTypeBeforeChange = $this.parents('.ays-survey-question-type-box').find('.ays-survey-check-type-before-change').val();
1577 var answerIds = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-answers-conteiner .ays-survey-answer-row');
1578 $this.parents('.ays-survey-question-type-box').find('.ays-survey-check-type-before-change').val(questionType);
1579
1580 if( questionType == 'radio' || questionType == 'checkbox' || questionType == 'select' ){
1581 if ( questionTypeBeforeChange == 'yesorno' ) {
1582 if (answerIds != undefined) {
1583 answerIds.each(function(e) {
1584 var answerId = $(this).data('id');
1585 if( ! $(this).hasClass('ays-survey-new-answer') ){
1586 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
1587 $this.parents('form').append( delImp );
1588 }
1589 });
1590 }
1591 }
1592 }else{
1593 if ( questionTypeBeforeChange == 'radio' || questionTypeBeforeChange == 'checkbox' || questionTypeBeforeChange == 'select' || questionTypeBeforeChange == 'yesorno' ) {
1594 if (answerIds != undefined) {
1595 answerIds.each(function(e) {
1596 var answerId = $(this).data('id');
1597 if( ! $(this).hasClass('ays-survey-new-answer') ){
1598 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
1599 $this.parents('form').append( delImp );
1600 }
1601 });
1602 }
1603 }
1604 }
1605
1606 var enablePrefixCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-value-prefix-saver');
1607 var enableSuffixCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-value-suffix-saver');
1608
1609 if( enablePrefixCheckbox.length > 0 ){
1610 enablePrefixCheckbox.val("off");
1611 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-action[data-action$="value-prefix"]').attr('data-action', 'enable-value-prefix');
1612 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-action[data-action$="value-prefix"] .ays-survey-question-action-icon').addClass('display_none');
1613 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-value-prefix').addClass('display_none');
1614 }
1615
1616 if( enableSuffixCheckbox.length > 0 ){
1617 enableSuffixCheckbox.val("off");
1618 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-action[data-action$="value-suffix"]').attr('data-action', 'enable-value-suffix');
1619 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-action[data-action$="value-suffix"] .ays-survey-question-action-icon').addClass('display_none');
1620 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-value-suffix').addClass('display_none');
1621 }
1622
1623 switch( questionType ){
1624 case 'radio':
1625 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1626 break;
1627 case 'checkbox':
1628 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1629 break;
1630 case 'select':
1631 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1632 break;
1633 case 'star':
1634 aysSurveyQuestionType_Star_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1635 break;
1636 case 'text':
1637 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1638 break;
1639 case 'short_text':
1640 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1641 break;
1642 case 'number':
1643 case 'phone':
1644 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1645 break;
1646 case 'yesorno':
1647 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1648 break;
1649 case 'email':
1650 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1651 break;
1652 case 'name':
1653 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1654 break;
1655 case 'date':
1656 aysSurveyQuestionType_Date_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1657 break;
1658 case 'time':
1659 aysSurveyQuestionType_Time_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1660 break;
1661 case 'date_time':
1662 aysSurveyQuestionType_Date_Time_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1663 break;
1664 default:
1665 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1666 }
1667
1668 reInitPopovers( parent );
1669 });
1670
1671 setTimeout(function(){
1672 if($(document).find('#ays_survey_custom_css').length > 0){
1673 if(wp.codeEditor){
1674 wp.codeEditor.initialize($(document).find('#ays_survey_custom_css'), cm_settings);
1675 }
1676 }
1677 }, 500);
1678
1679 $(document).find('a[href="#tab2"]').on('click', function (e) {
1680 setTimeout(function(){
1681 if($(document).find('#ays_survey_custom_css').length > 0){
1682 var ays_survey_custom_css = $(document).find('#ays_survey_custom_css').html();
1683 if(wp.codeEditor){
1684 $(document).find('#ays_survey_custom_css').next('.CodeMirror').remove();
1685 wp.codeEditor.initialize($(document).find('#ays_survey_custom_css'), cm_settings);
1686 $(document).find('#ays_survey_custom_css').html(ays_survey_custom_css);
1687 }
1688 }
1689 }, 500);
1690 });
1691
1692 $(document).find('#ays_survey_schedule_active, #ays_survey_schedule_deactive, #ays_survey_change_creation_date').datetimepicker({
1693 controlType: 'select',
1694 oneLine: true,
1695 dateFormat: "yy-mm-dd",
1696 timeFormat: "HH:mm:ss",
1697 afterInject: function(){
1698 $(document).find('.ui-datepicker-buttonpane button.ui-state-default').addClass('button');
1699 $(document).find('.ui-datepicker-buttonpane button.ui-state-default.ui-priority-primary').addClass('button-primary').css('float', 'right');
1700 }
1701 });
1702
1703 $(document).on('click', '.ays-survey-open-question-editor', function(e){
1704 var editorPopup = $(document).find('#ays-edit-question-content');
1705 // For question
1706 var question = $(this).parents('.ays-survey-question-answer-conteiner');
1707 var questionId = question.data('id');
1708 var questionName = question.data('name');
1709 // For section
1710 var section = question.parents('.ays-survey-section-box');
1711 var sectionId = section.data('id');
1712 var sectionName = section.data('name');
1713 var questionContent = question.find('textarea.ays-survey-question-input-textarea').val();
1714 // For question
1715 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-id', questionId );
1716 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-name', questionName );
1717 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', questionId );
1718 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', questionName );
1719 // For section
1720 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-section-id', sectionId );
1721 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-section-name', sectionName );
1722 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-section-id', sectionId );
1723 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-section-name', sectionName );
1724
1725 if ( $(document).find("#wp-ays_survey_question_editor-wrap").hasClass("tmce-active") ){
1726 window.tinyMCE.get('ays_survey_question_editor').setContent( questionContent );
1727 }else{
1728 $(document).find('#ays_survey_question_editor').val( questionContent );
1729 }
1730
1731 editorPopup.aysEditorModal('open');
1732 });
1733
1734 $(document).on('dblclick click', '.ays-survey-question-preview-box', function(e){
1735 var editorPopup = $(document).find('#ays-edit-question-content');
1736 var question = $(this).parents('.ays-survey-question-answer-conteiner');
1737 var questionId = question.data('id');
1738 var questionName = question.data('name');
1739 var questionContent = question.find('textarea.ays-survey-question-input-textarea').val();
1740 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-id', questionId );
1741 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-name', questionName );
1742 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', questionId );
1743 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', questionName );
1744
1745 var SurveyTinyMCE = window.tinyMCE.get('ays_survey_question_editor');
1746 if(SurveyTinyMCE != null){
1747 SurveyTinyMCE.setContent( questionContent );
1748 }
1749 else{
1750 $(document).find('#ays_survey_question_editor').val( questionContent );
1751 }
1752
1753 editorPopup.aysEditorModal('open');
1754 });
1755
1756 $(document).on('click', '.ays-survey-back-to-textarea', function(e){
1757 var editorPopup = $(document).find('#ays-edit-question-content');
1758 var questionId = $(this).attr('data-question-id');
1759 var questionName = $(this).attr('data-question-name');
1760 var question = $(document).find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionName+'"]');
1761 var aysSurveyQuestionTextArea = question.find('textarea.ays-survey-question-input-textarea');
1762
1763 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', '' );
1764 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', '' );
1765
1766 question.find('.ays-survey-open-question-editor-flag').val('off');
1767
1768 question.find('.ays-survey-question-input-box').removeClass('display_none');
1769 question.find('.ays-survey-question-preview-box').addClass('display_none');
1770
1771 // setTimeout( function(){
1772 autosize.update(aysSurveyQuestionTextArea);
1773 // }, 100 );
1774
1775 editorPopup.aysEditorModal('hide');
1776 });
1777
1778 $(document).on('click', '.ays-survey-move-question-into-section', function(e){
1779 var popup = $(document).find('#ays-survey-move-to-section');
1780 var sectionId = popup.attr('data-section-id');
1781 var sectionDataName = popup.attr('data-section-name');
1782 var questionId = popup.attr('data-question-id');
1783 var questionDataName = popup.attr('data-question-name');
1784 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+ $(this).data( 'id' ) +'"]:not(.ays-survey-new-section)');
1785 if( $(this).hasClass('ays-survey-move-new-question-into-section') ){
1786 section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box.ays-survey-new-section[data-id="'+ $(this).data( 'id' ) +'"]');
1787 }
1788 var oldSection = $(document).find('.ays-survey-section-box[data-id="'+sectionId+'"][data-name="'+sectionDataName+'"]');
1789 var question = oldSection.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
1790 var questions = oldSection.find('.ays-survey-question-answer-conteiner');
1791
1792 if( questions.length <= 1 ){
1793 swal.fire({
1794 type: 'warning',
1795 text: SurveyMakerAdmin.minimumCountOfQuestions
1796 });
1797 }else{
1798 setTimeout(function(){
1799 question.appendTo( section.find('.ays-survey-section-questions') );
1800 draggedQuestionUpdate( question, section );
1801 popup.aysModal('hide');
1802 }, 1);
1803 }
1804 });
1805
1806 /////////////////////////////////////////////////////////////////////////////////////////////
1807 /////////////////////////////////////ARO END/////////////////////////////////////////////////
1808 /////////////////////////////////////////////////////////////////////////////////////////////
1809 /////////////////////////////////////////////////////////////////////////////////////////////
1810
1811 aysSurveySectionsInitToAddQuestions();
1812 function aysSurveySectionsInitToAddQuestions(){
1813 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1814 var sections = sectionCont.find('.ays-survey-section-box');
1815 var addQuestionButton = $(document).find('.ays-survey-general-action[data-action="add-question"]');
1816 var ddmenu = addQuestionButton.parent().find('.dropdown-menu');
1817 ddmenu.html('');
1818 sections.each(function(i){
1819 var _this = $(this);
1820 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
1821 var sectionQuestionsCollapsedValues = [];
1822 var sectionQuestionsExpandedValues = [];
1823 sectionQuestionsCollapsedInputs.each(function(){
1824 if( $(this).val() == 'expanded' ){
1825 sectionQuestionsExpandedValues.push( true );
1826 }else{
1827 sectionQuestionsCollapsedValues.push( true );
1828 }
1829 });
1830
1831 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
1832 if( sectionQuestionsExpandedValues.length == 0 ){
1833 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
1834 }
1835
1836 var newClassToAddQuestion = '';
1837 if( _this.hasClass('ays-survey-new-section') ){
1838 newClassToAddQuestion = 'ays-survey-add-new-question-into-section';
1839 }
1840
1841 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
1842
1843 var buttonItem = '<button class="dropdown-item ays-survey-add-question-into-section '+ newClassToAddQuestion +'" data-id="'+ $(this).data('id') +'" type="button">';
1844 buttonItem += 'Add into Section '+ (i+1);
1845 buttonItem += '</button>';
1846 ddmenu.append(buttonItem);
1847 });
1848 if(sections.length > 1){
1849 addQuestionButton.attr('data-toggle', 'dropdown');
1850 addQuestionButton.attr('aria-expanded', 'false');
1851 }else{
1852 addQuestionButton.dropdown('dispose');
1853 addQuestionButton.removeAttr('data-toggle');
1854 }
1855 }
1856
1857 aysSurveySectionsInitQuestionsCollapse();
1858 function aysSurveySectionsInitQuestionsCollapse(){
1859 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1860 var sections = sectionCont.find('.ays-survey-section-box');
1861 sections.each(function(i){
1862 var _this = $(this);
1863 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
1864 var sectionQuestionsCollapsedValues = [];
1865 var sectionQuestionsExpandedValues = [];
1866 sectionQuestionsCollapsedInputs.each(function(){
1867 if( $(this).val() == 'expanded' ){
1868 sectionQuestionsExpandedValues.push( true );
1869 }else{
1870 sectionQuestionsCollapsedValues.push( true );
1871 }
1872 });
1873
1874 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
1875 var collapseButtonAddClass = 'ays-survey-collapse-sec-quests';
1876 var collapseButtonRemoveClass = 'ays-survey-expand-sec-quests';
1877 if( sectionQuestionsExpandedValues.length == 0 ){
1878 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
1879 collapseButtonAddClass = 'ays-survey-expand-sec-quests';
1880 collapseButtonRemoveClass = 'ays-survey-collapse-sec-quests';
1881 }
1882
1883 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
1884 _this.find('.ays-survey-collapse-section-questions').addClass( collapseButtonAddClass );
1885 _this.find('.ays-survey-collapse-section-questions').removeClass( collapseButtonRemoveClass );
1886 });
1887 }
1888
1889 function aysSurveyAddQuestion( sectionId, returnElem = false, sectionElem = null, isFromTemplate = false ){
1890 var section = sectionElem;
1891
1892 var requiredQuestionButton = section.find('.ays-survey-section-questions-required');
1893 var requiredQuestionButtonFlag = requiredQuestionButton.attr('data-flag');
1894
1895 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner');
1896 var clonedElement = cloningElement.clone( true, false );
1897 // var questionsLength = section.find('.ays-survey-question-answer-conteiner .ays-survey-question-input-box .ays-survey-input[name^="ays_section_add"]').length;
1898 var questionsLength = section.find('.ays-survey-question-answer-conteiner').length;
1899 var defaultQuestionType = $(document).find('input[name="ays_default_question_type"]').val();
1900 var answers = clonedElement.find('.ays-survey-answers-conteiner .ays-survey-answer-row');
1901
1902 // Generate unique number for every new question
1903 var generatedUniqueNumber = aysSurveyUniqueNumber();
1904 var questionId = generatedUniqueNumber;
1905 if(isFromTemplate){
1906 var questionTemplateId = questionsLength + 1;
1907 }
1908
1909 if(requiredQuestionButtonFlag && requiredQuestionButtonFlag == 'on'){
1910 clonedElement.find('.ays-survey-answer-elem-box .ays-survey-input-required-question').prop('checked', true);
1911 }
1912
1913
1914 var questionName = clonedElement.attr('data-name');
1915 var sectionName = section.attr('data-name');
1916 if( sectionElem !== null ){
1917 sectionName = sectionElem.attr('data-name');
1918 }
1919
1920 var questionsCount = questionsLength;
1921 var questionsCountBox = section.find(".ays-survey-action-questions-count span").text(questionsCount + 1);
1922 // Answers ordering jQuery UI
1923 clonedElement.find('.ays-survey-answers-conteiner').sortable(answerDragHandle);
1924
1925
1926 var aysSurveyTextArea = clonedElement.find('textarea.ays-survey-question-input-textarea');
1927 setTimeout( function(){
1928 autosize(aysSurveyTextArea);
1929 }, 100 );
1930
1931 clonedElement.addClass('ays-survey-new-question');
1932 clonedElement.attr('data-id', questionId);
1933 if(isFromTemplate){
1934 clonedElement.attr('data-template-id', questionTemplateId);
1935 }
1936 clonedElement.find('textarea.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'title'));
1937 clonedElement.find('select.ays-survey-question-type').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'type'));
1938 clonedElement.find('.ays-survey-question-img-src').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'image'));
1939 clonedElement.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'user_variant'));
1940 clonedElement.find('.ays-survey-input-required-question').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'required'));
1941 clonedElement.find('.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'collapsed'));
1942 clonedElement.find('.ays-survey-question-ordering').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'ordering'));
1943 clonedElement.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_max_selection_count'));
1944 clonedElement.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'max_selection_count'));
1945 clonedElement.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'min_selection_count'));
1946 // Text limitation options
1947 clonedElement.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, questionId, 'options', 'enable_word_limitation'));
1948 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'));
1949 clonedElement.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_length'));
1950 clonedElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_counter'));
1951 // Number limitation options start
1952 clonedElement.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, questionId, 'options', 'enable_number_limitation'));
1953 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_min_selection'));
1954 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_max_selection'));
1955 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_error_message'));
1956 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'));
1957 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_limit_length'));
1958 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'));
1959 // Number limitation options end
1960 clonedElement.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'with_editor'));
1961
1962 clonedElement.find('.ays-survey-question-image-caption').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'image_caption'));
1963 clonedElement.find('.ays-survey-question-img-caption-enable').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'image_caption_enable'));
1964 clonedElement.find('.ays-survey-question-ordering').val(questionId);
1965
1966 clonedElement.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_admin_note'));
1967 clonedElement.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'admin_note'));
1968
1969 clonedElement.find('.ays-survey-question-value-prefix-saver').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_value_prefix'));
1970 clonedElement.find('.ays-survey-question-value-prefix-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'value_prefix'));
1971 clonedElement.find('.ays-survey-question-value-suffix-saver').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_value_suffix'));
1972 clonedElement.find('.ays-survey-question-value-suffix-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'value_suffix'));
1973
1974 answers.each(function(j){
1975 var answerId = j+1; //answers.find('.ays-survey-answer-box input.ays-survey-input').length;
1976 $(this).addClass('ays-survey-new-answer');
1977 $(this).attr('data-id', answerId);
1978 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'title'));
1979 $(this).find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'image'));
1980 $(this).find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'ordering'));
1981
1982 var deleteButton = $(this).find('.ays-survey-answer-delete');
1983 if( answers.length == 1){
1984 deleteButton.css('visibility', 'hidden');
1985 }else{
1986 deleteButton.removeAttr('style');
1987 }
1988 });
1989
1990 clonedElement.find('select.ays-survey-question-type').aysDropdown();
1991 clonedElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1992 clonedElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1993
1994 var sectionCollapsedInput = section.find('.ays-survey-section-collapsed-input');
1995 var sectionCollapsed = sectionCollapsedInput.val() == 'collapsed' ? true : false;
1996
1997 if( sectionCollapsed ){
1998 expandSection( sectionCollapsedInput );
1999 }
2000
2001 if( returnElem ){
2002 return clonedElement;
2003 }else{
2004 section.find('.ays-survey-section-questions').append(clonedElement);
2005 clonedElement = section.find('.ays-survey-question-answer-conteiner.ays-survey-new-question[data-id="'+questionId+'"]');
2006 }
2007
2008 clonedElement.find('.ays-survey-question-type').aysDropdown('set selected', defaultQuestionType);
2009 clonedElement.find('.ays-survey-question-type').aysDropdown('set value', defaultQuestionType);
2010
2011 if(!isFromTemplate){
2012 setTimeout(function(){
2013 clonedElement.goToTop();
2014 }, 100 );
2015 }
2016
2017 reInitPopovers( clonedElement );
2018 aysSurveySectionsInitQuestionsCollapse();
2019 }
2020
2021 // Generate unique number
2022 function aysSurveyUniqueNumber() {
2023 var randomNumber = Math.random();
2024 var timestamp = Date.now();
2025 var uniqueNumber = Math.floor(randomNumber * timestamp);
2026 return uniqueNumber;
2027 }
2028
2029 function aysSurveyAddSection( afterSectionId, newSection, isFromTemplate = false){
2030
2031 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
2032 var sections = sectionCont.find('.ays-survey-section-box');
2033 var sectionsAdd = sectionCont.find('.ays-survey-new-section');
2034
2035 var section = $(document).find('.ays-question-to-clone .ays-survey-section-box');
2036 var clonedElement = section.clone( true, false );
2037 var sectionNewId = sectionsAdd.length + 1;
2038
2039 clonedElement.attr('data-id', sectionNewId);
2040 clonedElement.attr('data-name', 'ays_section_add');
2041 clonedElement.addClass('ays-survey-new-section');
2042 clonedElement.find('.ays-survey-section-title').attr('name', newSectionAttrName( sectionNewId, 'title' ));
2043 clonedElement.find('.ays-survey-section-description').attr('name', newSectionAttrName( sectionNewId, 'description' ));
2044 clonedElement.find('.ays-survey-section-ordering').attr('name', newSectionAttrName( sectionNewId, 'ordering' ));
2045 clonedElement.find('.ays-survey-section-collapsed-input').attr('name', newSectionAttrName( sectionNewId, 'options', 'collapsed' ));
2046
2047 if( typeof afterSectionId !== 'undefined' && afterSectionId !== null ){
2048 if( newSection === true ){
2049 clonedElement.insertAfter( sectionCont.find('.ays-survey-section-box.ays-survey-new-section[data-id="' + afterSectionId + '"]') );
2050 }else{
2051 clonedElement.insertAfter( sectionCont.find('.ays-survey-section-box.ays-survey-old-section[data-id="' + afterSectionId + '"]') );
2052 }
2053 }else{
2054 sectionCont.append( clonedElement );
2055 }
2056
2057 var defaultQuestionType = $(document).find('input[name="ays_default_question_type"]').val();
2058 var question = aysSurveyAddQuestion( sectionNewId, true, clonedElement );
2059 clonedElement.find('.ays-survey-section-questions').append( question );
2060
2061 question.find('.ays-survey-question-type').aysDropdown('set selected', defaultQuestionType);
2062 question.find('.ays-survey-question-type').aysDropdown('set value', defaultQuestionType);
2063
2064 clonedElement.find('.ays-survey-section-questions').sortable(questionDragHandle);
2065
2066 sectionCont = $(document).find('.ays-survey-sections-conteiner');
2067 sections = sectionCont.find('.ays-survey-section-box');
2068
2069 sections.each(function(i){
2070 $(this).find('.ays-survey-section-ordering').val( i + 1 );
2071 });
2072
2073 var aysSurveyDescriptionTextArea = clonedElement.find('textarea.ays-survey-section-description');
2074 setTimeout( function(){
2075 autosize(aysSurveyDescriptionTextArea);
2076 }, 100 );
2077
2078 sectionCont.find('.ays-survey-section-head-top').removeClass('display_none');
2079 sectionCont.find('.ays-survey-section-head').addClass('ays-survey-section-head-topleft-border-none');
2080
2081 sectionCont.find('.ays-survey-section-box').each(function( index ){
2082 $(this).find('.ays-survey-section-number').text( index + 1 );
2083 });
2084
2085 sectionCont.find('.ays-survey-sections-count').text( sections.length );
2086
2087 // sectionCont.find('.invisible').removeClass( 'invisible' );
2088 sectionCont.find('.ays-survey-section-actions-more .ays-survey-delete-section').removeClass('display_none');
2089 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-survey-answer-dlg-dragHandle .ays-survey-icons').addClass( 'invisible' );
2090 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-question-img-icon-content').parents('.ays-survey-answer-icon-box').addClass( 'invisible' );
2091 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-survey-other-answer-delete-icon').parents('.ays-survey-answer-icon-box').addClass( 'invisible' );
2092 if(!isFromTemplate){
2093 setTimeout(function(){
2094 clonedElement.goToTop();
2095 }, 100 );
2096 }
2097
2098 reInitPopovers( clonedElement );
2099 }
2100
2101 function aysSurveyDuplicateSection( currentButton, afterSectionId, newSection){
2102 var sectionCont = currentButton.parents('.ays-survey-sections-conteiner');
2103 var sections = sectionCont.find('.ays-survey-section-box');
2104 var sectionsAdd = sectionCont.find('.ays-survey-new-section');
2105 var sectionNewId = sectionsAdd.length + 1;
2106
2107 var currentElement = currentButton.parents(".ays-survey-section-box");
2108 var clonedElement = currentElement.clone( true, false );
2109 clonedElement = aysSetNewSectionNames(clonedElement, sectionNewId);
2110
2111 if( typeof afterSectionId !== 'undefined' && afterSectionId !== null ){
2112 clonedElement.insertAfter( currentElement );
2113 }else{
2114 sectionCont.append( clonedElement );
2115 }
2116
2117 // Get all questions
2118 var allQuestions = clonedElement.find('.ays-survey-question-answer-conteiner');
2119 allQuestions.each(function(i){
2120 var questionElem = this;
2121 var questionId = i+1;
2122 var answers = $(this).find('.ays-survey-answers-conteiner .ays-survey-answer-row');
2123
2124 // Set new names for questions
2125 aysSetNewQuestionNames($(questionElem), sectionNewId, questionId);
2126 answers.each(function(j){
2127 var answerId = j;
2128 // Set new names for answers
2129 aysSetNewAnswerNames($(this), sectionNewId, questionId, answerId);
2130
2131 var deleteButton = $(this).find('.ays-survey-answer-delete');
2132 if( answers.length == 1){
2133 deleteButton.css('visibility', 'hidden');
2134 }else{
2135 deleteButton.removeAttr('style');
2136 }
2137 });
2138 });
2139
2140
2141 clonedElement.find('.ays-survey-section-questions').sortable(questionDragHandle);
2142
2143 sectionCont = $(document).find('.ays-survey-sections-conteiner');
2144 sections = sectionCont.find('.ays-survey-section-box');
2145 sections.each(function(i){
2146 $(this).find('.ays-survey-section-ordering').val( i + 1 );
2147 $(this).find('.ays-survey-section-number').text( i + 1 );
2148 });
2149
2150 sectionCont.find('.ays-survey-sections-count').text( sections.length );
2151
2152 sectionCont.find('.ays-survey-section-head-top').removeClass('display_none');
2153 sectionCont.find('.ays-survey-section-head').addClass('ays-survey-section-head-topleft-border-none');
2154 setTimeout(function(){
2155 clonedElement.goTo();
2156 }, 100 );
2157 reInitPopovers( clonedElement );
2158 }
2159
2160 function aysSetNewSectionNames(element, sectionId){
2161 element.attr('data-id', sectionId);
2162 element.attr('data-name', 'ays_section_add');
2163 element.addClass('ays-survey-new-section');
2164 element.find('.ays-survey-section-title').attr('name', newSectionAttrName( sectionId, 'title' ));
2165 element.find('.ays-survey-section-description').attr('name', newSectionAttrName( sectionId, 'description' ));
2166 element.find('.ays-survey-section-ordering').attr('name', newSectionAttrName( sectionId, 'ordering' ));
2167 element.find('.ays-survey-section-collapsed-input').attr('name', newSectionAttrName( sectionId, 'options', 'collapsed' ));
2168 element.find('.ays-survey-delete-section').removeClass("display_none");
2169 element.find('.dropdown-menu.dropdown-menu-right').removeClass("show");
2170 element.find('input[name*="ays_sections_ids"]').remove();
2171 return element;
2172 }
2173
2174 function aysSetNewQuestionNames(element, sectionId, questionId){
2175 element.removeClass('ays-survey-old-question');
2176 element.addClass('ays-survey-new-question');
2177 element.attr('data-id', questionId);
2178 element.attr('data-name', 'questions_add');
2179 var question_type = element.find('.ays-survey-check-type-before-change').val();
2180
2181 var starScaleOldLength = "";
2182 if(question_type == 'star'){
2183 starScaleOldLength = element.find(".ays-survey-choose-for-start-select-lenght").val();
2184 element.find('select.ays-survey-choose-for-start-select-lenght').val(starScaleOldLength);
2185 element.find('input.ays-survey-input-star-1').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_1'));
2186 element.find('input.ays-survey-input-star-2').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_2'));
2187 element.find('select.ays-survey-choose-for-start-select-lenght').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_scale_length'));
2188 }
2189
2190 element.find('textarea.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'title'));
2191 element.find('.ays-survey-question-type select').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'type'));
2192 element.find('.ays-survey-question-img-src').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'image'));
2193 element.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'user_variant'));
2194 element.find('.ays-survey-input-required-question').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'required'));
2195 element.find('.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'collapsed'));
2196 element.find('.ays-survey-question-ordering').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'ordering'));
2197 element.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_max_selection_count'));
2198 element.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'max_selection_count'));
2199 element.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'min_selection_count'));
2200 // Text limitation options
2201 element.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_word_limitation'));
2202 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'));
2203 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'));
2204 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'));
2205 // Number limitation options start
2206 element.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_number_limitation'));
2207 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'));
2208 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'));
2209 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'));
2210 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'));
2211 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'));
2212 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'));
2213 // Number limitation options end
2214
2215 // Input types placeholders
2216 element.find('.ays-survey-question-types-input-with-placeholder').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'placeholder'));
2217
2218
2219 element.find('.ays-survey-question-image-caption').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'image_caption'));
2220 element.find('.ays-survey-question-img-caption-enable').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'image_caption_enable'));
2221
2222 element.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_admin_note'));
2223 element.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'admin_note'));
2224
2225 element.find('.ays-survey-question-value-prefix-saver').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_value_prefix'));
2226 element.find('.ays-survey-question-value-prefix-label input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'value_prefix'));
2227 element.find('.ays-survey-question-value-suffix-saver').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_value_suffix'));
2228 element.find('.ays-survey-question-value-suffix-label input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'value_suffix'));
2229
2230 element.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'with_editor'));
2231 element.find('.ays-survey-question-ordering').val(questionId);
2232
2233 element.find('.ays-survey-question-type').aysDropdown('set selected', question_type);
2234 element.find('.ays-survey-question-type').aysDropdown('set value', question_type);
2235 element.find('.ays-survey-question-type').aysDropdown();
2236 }
2237
2238 function aysSetNewAnswerNames(element, sectionId, questionId, answerId){
2239 element.addClass('ays-survey-new-answer');
2240 element.attr('data-id', answerId);
2241 element.find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'title'));
2242 element.find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'image'));
2243 element.find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'ordering'));
2244 }
2245
2246 function aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null ){
2247
2248 var removeHtml = true; // Remove Html
2249 if(questionTypeBeforeChange == 'radio' || questionTypeBeforeChange == 'select' || questionTypeBeforeChange == 'checkbox'){
2250 removeHtml = false;
2251 }
2252
2253 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2254 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2255 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner .ays-survey-answers-conteiner');
2256 var cloningElement_2 = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner .ays-survey-other-answer-and-actions-row');
2257
2258 if( questionType == 'yesorno' ){
2259 cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-type-yes-or-no');
2260 removeHtml = true;
2261 }
2262
2263 var clonedElement = cloningElement.clone( true, false );
2264 var clonedElement_2 = cloningElement_2.clone( true, false );
2265
2266 var answers = clonedElement.find('.ays-survey-answer-row');
2267 clonedElement.sortable(answerDragHandle);
2268
2269 var questionName = questionDataName;
2270 var sectionName = section.attr('data-name');
2271 if( sectionElem !== null ){
2272 sectionName = sectionElem.attr('data-name');
2273 }
2274 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2275 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2276 var placeholderVal = '';
2277 var questionTypeIconClass = '';
2278 var answer_icon = clonedElement.find('.ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2279 var other_answer_icon = clonedElement_2.find('.ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2280 switch( questionType ){
2281 case 'radio':
2282 case 'yesorno':
2283 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2284 break;
2285 case 'checkbox':
2286 questionTypeIconClass = SurveyMakerAdmin.icons.checkboxUnchecked;
2287 break;
2288 case 'select':
2289 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2290 break;
2291 default:
2292 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2293 }
2294
2295 other_answer_icon.attr('src', questionTypeIconClass);
2296 answer_icon.attr('src', questionTypeIconClass);
2297
2298 clonedElement_2.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'user_variant'));
2299 clonedElement_2.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_max_selection_count'));
2300 clonedElement_2.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'max_selection_count'));
2301
2302 answers.each(function(i){
2303 var answerId = i+1;
2304 $(this).addClass('ays-survey-new-answer');
2305 $(this).attr('data-id', answerId);
2306 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'title'));
2307 $(this).find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'image'));
2308 $(this).find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'ordering'));
2309 });
2310
2311 if( questionType == 'select' ){
2312 clonedElement_2.find('.ays-survey-other-answer-add-wrap').hide();
2313 clonedElement_2.find('.ays-survey-other-answer-row').hide();
2314 clonedElement_2.find('.ays-survey-other-answer-checkbox').prop('checked', false );
2315 question.find('.ays-survey-other-answer-add-wrap').hide();
2316 question.find('.ays-survey-other-answer-checkbox').prop('checked', false );
2317 }else{
2318 clonedElement_2.find('.ays-survey-other-answer-add-wrap').show();
2319 if( question.find('.ays-survey-other-answer-checkbox').prop('checked') == true ){
2320 question.find('.ays-survey-other-answer-add-wrap').hide();
2321 }else{
2322 question.find('.ays-survey-other-answer-add-wrap').show();
2323 }
2324 }
2325
2326 var enableMaxSelectionCount = question.find('.ays-survey-question-max-selection-count-checkbox').prop('checked');
2327 if( questionType == "checkbox" && enableMaxSelectionCount ){
2328 question.find('.ays-survey-question-more-option-wrap').removeClass('display_none');
2329 }else{
2330 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2331 }
2332
2333 if( questionType != "checkbox" ){
2334 question.find('.ays-survey-question-actions-pro[data-action="go-to-section-based-on-answers-enable"]').removeClass('display_none');
2335 }
2336
2337
2338 question.find('.ays-survey-question-more-actions').removeClass('display_none');
2339
2340
2341 if( returnElem ){
2342 clonedElement = $( clonedElement.html() );
2343 var clonedElementArr = new Array(clonedElement, clonedElement_2);
2344 return clonedElementArr;
2345 }else{
2346 // Remove Html
2347 if (removeHtml) {
2348 clonedElement = $( clonedElement.html() );
2349 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answers-conteiner').html(clonedElement);
2350 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2351 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2352 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2353 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2354 }else{
2355 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');
2356 switch( questionType ){
2357 case 'radio':
2358 case 'yesorno':
2359 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2360 break;
2361 case 'checkbox':
2362 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.checkboxUnchecked);
2363 break;
2364 case 'select':
2365 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2366 break;
2367 default:
2368 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2369 }
2370 }
2371
2372 if( questionType == 'select' || questionType == 'checkbox' || questionType == 'radio' || questionType == 'yesorno'){
2373 var addAnswerRow = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-other-answer-and-actions-row');
2374 clonedElement_2.find('.ays-survey-other-answer-row .ays-survey-answer-icon-box .invisible').removeClass( 'invisible' );
2375
2376 if ( removeHtml || questionType == 'select' ) {
2377 addAnswerRow.html(clonedElement_2.html());
2378 }
2379 }
2380 }
2381 }
2382
2383 function aysSurveyQuestionType_Star_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2384
2385 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2386 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2387 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_star');
2388 var clonedElement = cloningElement.clone( true, false );
2389
2390 var sectionName = section.attr('data-name');
2391 if( sectionElem !== null ){
2392 sectionName = sectionElem.attr('data-name');
2393 }
2394
2395 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2396 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2397
2398 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2399 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2400 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2401 clonedElement.find('.ays-survey-choose-for-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'scale_length'));
2402 clonedElement.find('.ays-survey-input-star-1').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_1'));
2403 clonedElement.find('.ays-survey-input-star-2').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_2'));
2404 clonedElement.find('.ays-survey-choose-for-start-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_scale_length'));
2405
2406 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2407 if(returnElem){
2408 return clonedElement;
2409 }else{
2410 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2411 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2412 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2413 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2414 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2415
2416 }
2417 }
2418
2419 function aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId, questionId, questionDataName, questionType, returnElem = false, sectionElem = null ){
2420 var section = sectionElem;
2421 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types');
2422 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2423 var clonedElement = cloningElement.clone( true, false );
2424
2425 var answers = clonedElement.find('.ays-survey-answer-row');
2426
2427 var questionName = questionDataName;
2428 var sectionName = section.attr('data-name');
2429 if( sectionElem !== null ){
2430 sectionName = sectionElem.attr('data-name');
2431 }
2432
2433
2434 var placeholderVal = '';
2435 var questionTypeClass = '';
2436 placeholderVal = SurveyMakerAdmin.inputAnswerText;
2437 switch( questionType ){
2438 case 'text':
2439 questionTypeClass = 'ays-survey-question-type-text-box ays-survey-question-type-all-text-types-box';
2440 break;
2441 case 'short_text':
2442 questionTypeClass = 'ays-survey-question-type-short-text-box ays-survey-question-type-all-text-types-box';
2443 break;
2444 case 'number':
2445 questionTypeClass = 'ays-survey-question-type-number-box ays-survey-question-type-all-text-types-box';
2446 break;
2447 case 'phone':
2448 placeholderVal = SurveyMakerAdmin.phoneAnswerText;
2449 questionTypeClass = 'ays-survey-question-type-number-box ays-survey-question-type-all-text-types-box';
2450 clonedElement.find(".ays-survey-question-types-box-phone-type-note").removeClass("display_none");
2451 question.find(".ays-survey-question-number-min-box,.ays-survey-question-number-max-box").addClass("display_none");
2452 break;
2453 case 'email':
2454 placeholderVal = SurveyMakerAdmin.emailField;
2455 questionTypeClass = 'ays-survey-question-type-email-box ays-survey-question-type-all-text-types-box';
2456 break;
2457 case 'name':
2458 placeholderVal = SurveyMakerAdmin.nameField;
2459 questionTypeClass = 'ays-survey-question-type-name-box ays-survey-question-type-all-text-types-box';
2460 break;
2461 default:
2462 placeholderVal = SurveyMakerAdmin.inputAnswerText;
2463 questionTypeClass = 'ays-survey-question-type-text-box ays-survey-question-type-all-text-types-box';
2464 }
2465
2466 var enableWordLimitation = question.find('.ays-survey-question-word-limitations-checkbox').prop('checked');
2467 if( (questionType == "short_text" || questionType == "text") && enableWordLimitation ){
2468 question.find('.ays-survey-question-word-limitations').removeClass('display_none');
2469 }else{
2470 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2471 }
2472
2473 var enableNumberLimitation = question.find('.ays-survey-question-number-limitations-checkbox').prop('checked');
2474 if( (questionType == "number" || questionType == "phone") && enableNumberLimitation ){
2475 question.find('.ays-survey-question-number-limitations').removeClass('display_none');
2476 }else{
2477 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2478 }
2479
2480 // if( questionType == "short_text" || questionType == "text" || questionType == "number"){
2481 // question.find('.ays-survey-question-more-actions').removeClass('display_none');
2482 // }else{
2483 // question.find('.ays-survey-question-more-actions').addClass('display_none');
2484 // }
2485 // question.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').aysDropdown();
2486 // question.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').aysDropdown();
2487
2488
2489
2490 var answerId = answers.find('input.ays-survey-question-types-input').length;
2491 answers.attr('data-id', answerId);
2492 answers.find('input.ays-survey-question-types-input.ays-survey-question-types-input-with-placeholder').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'placeholder'));
2493 answers.find('input.ays-survey-question-types-input').attr('placeholder', placeholderVal);
2494 answers.find('input.ays-survey-question-types-input').val(placeholderVal);
2495 answers.find('.ays-survey-question-types-box').addClass(questionTypeClass);
2496
2497 // question.find('.ays-survey-question-more-actions').addClass('display_none');
2498 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2499 question.find('.ays-survey-question-actions-pro[data-action="go-to-section-based-on-answers-enable"]').addClass('display_none');
2500
2501 if( returnElem ){
2502 return clonedElement;
2503 }else{
2504 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answers-conteiner').html(clonedElement);
2505 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-other-answer-and-actions-row').html('');
2506 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2507 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2508 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2509 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2510
2511 }
2512 }
2513
2514 function aysSurveyQuestionType_Date_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2515
2516 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2517 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2518 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_date');
2519 var clonedElement = cloningElement.clone( true, false );
2520
2521 var sectionName = section.attr('data-name');
2522 if( sectionElem !== null ){
2523 sectionName = sectionElem.attr('data-name');
2524 }
2525
2526 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2527 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2528
2529 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2530 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2531 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2532 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2533 if(returnElem){
2534 return clonedElement;
2535 }else{
2536 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2537 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2538
2539 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_nps').html('');
2540
2541 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2542 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2543 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-matrix_scale').html(' ');
2544 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-matrix_scale_checkbox').html(' ');
2545 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_range').html('');
2546 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-star_list').html('');
2547 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-slider_list').html('');
2548 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_html').html('');
2549 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_calculation').html('');
2550 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2551 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2552 }
2553
2554 }
2555
2556 function aysSurveyQuestionType_Time_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2557
2558 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2559 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2560 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_time');
2561 var clonedElement = cloningElement.clone( true, false );
2562
2563 var sectionName = section.attr('data-name');
2564 if( sectionElem !== null ){
2565 sectionName = sectionElem.attr('data-name');
2566 }
2567
2568 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2569 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2570
2571 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2572 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2573 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2574 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2575 if(returnElem){
2576 return clonedElement;
2577 }else{
2578 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2579 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2580
2581 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2582 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2583 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2584 }
2585
2586 }
2587
2588
2589 function aysSurveyQuestionType_Date_Time_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2590
2591 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2592 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2593 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_date_time');
2594 var clonedElement = cloningElement.clone( true, false );
2595
2596 var sectionName = section.attr('data-name');
2597 if( sectionElem !== null ){
2598 sectionName = sectionElem.attr('data-name');
2599 }
2600
2601 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2602 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2603
2604 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2605 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2606 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2607 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2608 if(returnElem){
2609 return clonedElement;
2610 }else{
2611 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2612 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2613
2614 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2615 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2616 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2617 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2618
2619 }
2620
2621 }
2622
2623 function aysSurveyAddAnswer( currentAnswer, afterAnswer, isFromTemplate = false ){
2624 var $this = currentAnswer;
2625 var section = $this.parents('.ays-survey-section-box');
2626 var sectionId = section.attr('data-id');
2627 var questsCont = $this.parents('.ays-survey-question-answer-conteiner');
2628 var itemId = questsCont.data('id');
2629 var answersCont = questsCont.find('.ays-survey-answers-conteiner');
2630 var cloningElement = answersCont.find('.ays-survey-answer-row:first-child');
2631 var id = cloningElement.data('id');
2632 var answerLength = answersCont.find('.ays-survey-answer-row').length + 1;
2633
2634 var clone = cloningElement.clone(true, false).attr('data-id', answerLength);
2635
2636 if( afterAnswer === true ){
2637 clone.insertAfter(currentAnswer.parents('.ays-survey-answer-row'));
2638 }else{
2639 clone.appendTo(answersCont);
2640 }
2641
2642 questsCont = clone.parents('.ays-survey-question-answer-conteiner');
2643 itemId = questsCont.data('id');
2644 var answerContainer = questsCont.find('.ays-survey-answers-conteiner');
2645 var length = answerContainer.find('.ays-survey-answer-row').length;
2646 var clonedElem = clone.find('.ays-survey-input');
2647 var clonedElemInp = clonedElem.val('Option '+ length).attr('placeholder', 'Option '+ length);
2648
2649 clonedElem.attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'title'));
2650 // clonedElem.find('.aysAnswerImgConteiner').html('');
2651 // clonedElemInp.select();
2652 if(!isFromTemplate){
2653 clonedElemInp.trigger('focus');
2654 }
2655
2656 clone.addClass('ays-survey-new-answer');
2657 clone.find('.ays-survey-answer-image-container').hide();
2658 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img').removeAttr('src');
2659 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img-src').val('');
2660 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'));
2661 clone.find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'ordering'));
2662
2663 answersCont.find('.ays-survey-answer-ordering').each(function(i){
2664 $(this).val( i + 1 );
2665 });
2666
2667 // clone.find('.ays-survey-answer-ordering').val( length );
2668 var deleteButton = answerContainer.find('.ays-survey-answer-delete');
2669 if(length == 1){
2670 deleteButton.css('visibility', 'hidden');
2671 }else{
2672 deleteButton.removeAttr('style');
2673 }
2674 answerContainer.sortable(answerDragHandle);
2675 reInitPopovers( clone );
2676 }
2677
2678 function draggedQuestionUpdate( element, section, oldSection){
2679
2680
2681 var questionsLength = section.find('.ays-survey-question-answer-conteiner').length;
2682 var questionsCount = questionsLength;
2683 var questionsCountBox = section.find(".ays-survey-action-questions-count span").text(questionsCount);
2684
2685 if(oldSection){
2686 var oldQuestionsLength = oldSection.find('.ays-survey-question-answer-conteiner').length;
2687 var oldQuestionsCount = oldQuestionsLength;
2688 var questionsCountBox = oldSection.find(".ays-survey-action-questions-count span").text(oldQuestionsCount);
2689 }
2690
2691 var answers = element.find('.ays-survey-answers-conteiner .ays-survey-answer-row');
2692 var questionName = element.attr('data-name');
2693 var questionId = element.attr('data-id');
2694 if( element.hasClass('ays-survey-new-question') ){
2695 questionId = section.find('.ays-survey-question-answer-conteiner[data-name="questions_add"]').length;
2696 }
2697
2698 var sectionName = section.attr('data-name');
2699 var sectionId = section.attr('data-id');
2700
2701 element.find('textarea.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'title'));
2702 element.find('.ays-survey-question-type-box select').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'type'));
2703 element.find('.ays-survey-question-img-src').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'image'));
2704 element.find('.ays-survey-other-answer-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'user_variant'));
2705 element.find('.ays-survey-input-required-question').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'required'));
2706 element.find('.ays-survey-question-collapsed-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'collapsed'));
2707 element.find('.ays-survey-question-ordering').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'ordering'));
2708 element.find('.ays-survey-question-max-selection-count-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_max_selection_count'));
2709 element.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'max_selection_count'));
2710 element.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'min_selection_count'));
2711 // Text limitation options
2712 element.find('.ays-survey-question-word-limitations-checkbox').attr('name', updateQuestionAttrName(sectionName, sectionId, questionName, questionId, 'options', 'enable_word_limitation'));
2713 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'));
2714 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'));
2715 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'));
2716 // Number limitation options start
2717 element.find('.ays-survey-question-number-limitations-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_number_limitation'));
2718 element.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_min_selection'));
2719 element.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_max_selection'));
2720 element.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_error_message'));
2721 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'));
2722 element.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_limit_length'));
2723 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'));
2724 // Number limitation options end
2725
2726 // Input types placeholders
2727 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'));
2728
2729 element.find('.ays-survey-question-image-caption').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'image_caption'));
2730 element.find('.ays-survey-question-img-caption-enable').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'image_caption_enable'));
2731
2732 element.find('.ays-survey-open-question-editor-flag').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'with_editor'));
2733
2734 element.find('.ays-survey-question-admin-note-saver').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_admin_note'));
2735 element.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'admin_note'));
2736
2737 element.find('.ays-survey-question-value-prefix-saver').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_value_prefix'));
2738 element.find('.ays-survey-question-value-prefix-label input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'value_prefix'));
2739 element.find('.ays-survey-question-value-suffix-saver').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_value_suffix'));
2740 element.find('.ays-survey-question-value-suffix-label input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'value_suffix'));
2741
2742 answers.each(function(){
2743 var answerId = $(this).attr('data-id');
2744 var answerName = $(this).hasClass('ays-survey-new-answer') ? 'answers_add' : 'answers';
2745 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'title'));
2746 $(this).find('.ays-survey-answer-img-src').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'image'));
2747 $(this).find('.ays-survey-answer-ordering').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'ordering'));
2748 });
2749
2750 // Star start
2751 element.find('.ays-survey-choose-for-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'scale_length'));
2752 element.find('.ays-survey-input-star-1').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_1'));
2753 element.find('.ays-survey-input-star-2').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_2'));
2754 element.find('.ays-survey-choose-for-start-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_scale_length'));
2755 // Star end
2756
2757 setTimeout(function(){
2758 element.goToTop();
2759 }, 100 );
2760 }
2761
2762 function newSectionAttrName(sectionId, field, field2 = null){
2763 if(field2 !== null){
2764 return $html_name_prefix + 'section_add['+ sectionId +']['+ field +']['+ field2 +']';
2765 }
2766 return $html_name_prefix + 'section_add['+ sectionId +']['+ field +']';
2767 }
2768
2769 function newQuestionAttrName(sectionName, sectionId, questionId, field, field2 = null){
2770 if(field2 !== null){
2771 return sectionName + '['+ sectionId +'][questions_add]['+ questionId +']['+ field +']['+ field2 +']';
2772 }
2773 return sectionName + '['+ sectionId +'][questions_add]['+ questionId +']['+ field +']';
2774 }
2775
2776 function newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, field, field2 = null){
2777 if(field2 !== null){
2778 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +'][answers_add]['+ answerId +']['+ field +']['+ field2 +']';
2779 }
2780 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +'][answers_add]['+ answerId +']['+ field +']';
2781 }
2782
2783 function updateSectionAttrName( sectionName, sectionId, field, field2 = null){
2784 if(field2 !== null){
2785 return sectionName + '['+ sectionId +']['+ field +']['+ field2 +']';
2786 }
2787 return sectionName + '['+ sectionId +']['+ field +']';
2788 }
2789
2790 function updateQuestionAttrName( sectionName, sectionId, questionName, questionId, field, field2 = null){
2791 if(field2 !== null){
2792 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ field +']['+ field2 +']';
2793 }
2794 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ field +']';
2795 }
2796
2797 function updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, field, field2 = null){
2798 if(field2 !== null){
2799 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ answerName +']['+ answerId +']['+ field +']['+ field2 +']';
2800 }
2801 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ answerName +']['+ answerId +']['+ field +']';
2802 }
2803
2804 function reInitPopovers( parentElement ){
2805 var popoverElements = parentElement.find('[data-toggle="popover"]');
2806
2807 if( parentElement.is('[data-toggle="popover"]') ){
2808 popoverElements = popoverElements.add( parentElement );
2809 }
2810
2811 popoverElements.each(function(){
2812 var $this = $(this);
2813
2814 if( $this.data('bs.popover') ){
2815 $this.popover('dispose');
2816 }
2817
2818 $this.popover();
2819 });
2820 }
2821
2822 function aysSurveySectionsInitToMoveQuestions( currentSection, currentQuestion ){
2823 var popup = $(document).find('#ays-survey-move-to-section');
2824 var currentSectionId = popup.attr('data-section-id');
2825 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
2826 var sections = sectionCont.find('.ays-survey-section-box');
2827 var moveSectionsCont = popup.find('.ays-survey-move-to-section-sections-wrap');
2828 moveSectionsCont.html('');
2829
2830 sections.each(function(i){
2831 var _this = $(this);
2832 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
2833 var sectionQuestionsCollapsedValues = [];
2834 var sectionQuestionsExpandedValues = [];
2835 sectionQuestionsCollapsedInputs.each(function(){
2836 if( $(this).val() == 'expanded' ){
2837 sectionQuestionsExpandedValues.push( true );
2838 }else{
2839 sectionQuestionsCollapsedValues.push( true );
2840 }
2841 });
2842
2843 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
2844 if( sectionQuestionsExpandedValues.length == 0 ){
2845 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
2846 }
2847
2848 var disabled = '';
2849 if( currentSectionId == _this.attr('data-id') ){
2850 disabled = ' disabled ';
2851 }
2852
2853 var newClassToAddQuestion = '';
2854 if( _this.hasClass('ays-survey-new-section') ){
2855 newClassToAddQuestion = 'ays-survey-move-new-question-into-section';
2856 }
2857
2858 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
2859
2860 var buttonItem = '<button class="dropdown-item ays-survey-move-question-into-section '+ newClassToAddQuestion +'" ' + disabled + ' data-id="'+ $(this).data('id') +'" type="button">';
2861 buttonItem += aysCreateSectionName( _this, i+1, SurveyMakerAdmin.moveToSection ); //SurveyMakerAdmin.addIntoSection + ' ' + (i+1);
2862 buttonItem += '</button>';
2863 moveSectionsCont.append(buttonItem);
2864 });
2865 }
2866
2867 function aysCreateSectionName( section, index, text ){
2868 var sectionName = section.find('.ays-survey-section-title').val();
2869 var name = text + ' ' + index;
2870 if( sectionName == '' ){
2871 name += ' (Untitled Form) ';
2872 }else{
2873 name += ' ('+ sectionName +') ';
2874 }
2875 return name;
2876 }
2877
2878
2879 $(document).find('#ays_select_surveys').select2({
2880 allowClear: true,
2881 placeholder: false
2882 });
2883
2884 $(document).find('#ays_user_roles').select2({
2885 allowClear: true,
2886 placeholder: SurveyMakerAdmin.selectUserRoles
2887 });
2888
2889 $(document).find('#ays_survey_default_type').select2({
2890 allowClear: true,
2891 placeholder: SurveyMakerAdmin.selectQuestionDefaultType
2892 });
2893
2894 $(document).find('.ays-survey-submission-select').aysDropdown();
2895
2896 $(document).find('.ays-survey-sections-conteiner .ays-survey-question-type').aysDropdown({
2897 // allowClear: true,
2898 // placeholder: false
2899 });
2900
2901 /* CONTINUE FROM HERE */
2902 // $(document).find('.ays-survey-sections-conteiner .ays-survey-question-type').aysDropdown({
2903 // // allowClear: true,
2904 // // placeholder: false
2905 // });
2906
2907 $(document).find('.ays-survey-sections-conteiner .dropdown .item[data-value="email"]').before('<div class="divider"></div>');
2908 $(document).find('.ays-survey-sections-conteiner .dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
2909
2910
2911
2912 // ===============================================================
2913 // ====================== Ani ==========================
2914 // ===============================================================
2915
2916 var count = 0;
2917 $(document).find('.ays_survey_previous_next').on('click',function(){
2918 if($(this).attr('data-name') == 'ays_survey_next'){
2919 if($(document).find('.ays_number_of_result').val() == $(document).find('.ays_number_of_result').attr('max')){
2920 count = $(document).find('.ays_number_of_result').attr('min');
2921 $(document).find('.ays_number_of_result').val(count);
2922 }else{
2923 var selectVal = parseInt($(document).find('.ays_number_of_result').val());
2924 count = selectVal + 1;
2925 $(document).find('.ays_number_of_result').val(count);
2926 }
2927 }else if($(this).attr('data-name') == 'ays_survey_previous'){
2928 if($(document).find('.ays_number_of_result').val() == $(document).find('.ays_number_of_result').attr('min')){
2929 count = $(document).find('.ays_number_of_result').attr('max');
2930 $(document).find('.ays_number_of_result').val(count);
2931 }else{
2932 var selectVal = parseInt($(document).find('.ays_number_of_result').val());
2933 count = selectVal - 1;
2934 $(document).find('.ays_number_of_result').val(count);
2935 }
2936 }
2937 $(document).find('.ays_number_of_result').trigger('change');
2938 });
2939
2940 $(document).find('.ays_number_of_result').on('change', refreshSubmissionData);
2941 // $(document).find('.ays_number_of_result').on('input', refreshSubmissionData);
2942
2943 function refreshSubmissionData(){
2944 var submissionPrevVal;
2945 var $this = $(this);
2946
2947 var parent = $(this).parents('.ays_survey_previous_next_conteiner');
2948 var mainParent = $this.parents('.ays_survey_container_each_result');
2949 var submissionInputs = mainParent.find(".ays_number_of_result ");
2950 var currentNumber = $this.val();
2951 if(+$this.val() > +$this.attr("max") || $this.val() == "" || +$this.val() == 0){
2952 currentNumber = $this.attr("max");
2953 }
2954 submissionInputs.val(currentNumber);
2955
2956 var submissionIdStr = parent.find('.ays_submissions_id_str').val();
2957 var submissionIdArr = submissionIdStr.split(",");
2958 var submissionElVal = parseInt(parent.find('.ays_number_of_result').val());
2959 var surveyId = $(document).find('.ays_number_of_result').attr('data-id');
2960 var submissionId = '';
2961 var data = {};
2962
2963 if(submissionElVal < 0){
2964 submissionElVal = 1;
2965 parseInt(parent.find('.ays_number_of_result').val(1));
2966 }else if(submissionElVal > parseInt(parent.find('.ays_number_of_result').attr('max'))){
2967 var maxVal = parseInt(parent.find('.ays_number_of_result').attr('max'));
2968 parseInt(parent.find('.ays_number_of_result').val(maxVal));
2969 submissionElVal = maxVal;
2970 }
2971
2972 if(submissionElVal>submissionPrevVal || submissionElVal+1){
2973 submissionId = submissionIdArr[submissionElVal-1];
2974 }else{
2975 submissionId = submissionIdArr[submissionElVal+1];
2976 }
2977
2978 data.action = 'ays_survey_submission_report';
2979 data.submissionId = submissionId;
2980 data.surveyId = surveyId;
2981 data.nonce = SurveyMakerAdmin.nonce;
2982 var preloader = $(this).parents('.ays_survey_container_each_result').find('.question_result_container').find('div.ays_survey_preloader');
2983 preloader.css({'display':'flex'});
2984 $.ajax({
2985 url: ajaxurl,
2986 dataType: 'json',
2987 data: data,
2988 method: 'post',
2989 success: function(response){
2990 if (response.status) {
2991 preloader.css({'display':'none'});
2992 var questionsData = response.questions;
2993 var questionsInHTML = $(document).find('.ays_questions_answers');
2994 $(document).find(".ays_survey_each_sub_user_info_name").html(response.user_info.user_name);
2995 $(document).find(".ays_survey_each_sub_user_info_email").text(response.user_info.user_email);
2996 $(document).find(".ays_survey_each_sub_user_info_user_ip").html(response.user_info.user_ip);
2997 $(document).find(".ays_survey_each_sub_user_info_sub_date").html(response.user_info.submission_date);
2998 $(document).find(".ays_survey_each_sub_user_info_sub_id").html(response.user_info.id);
2999 if(typeof response.user_info.user_device_type != 'undefined' && response.user_info.user_device_type){
3000 $(document).find(".ays_survey_each_sub_user_info_device_type").parents('.ays_survey_each_sub_user_info_columns').show();
3001 $(document).find(".ays_survey_each_sub_user_info_device_type").html(response.user_info.user_device_type);
3002 }
3003 else{
3004 $(document).find(".ays_survey_each_sub_user_info_device_type").parents('.ays_survey_each_sub_user_info_columns').hide();
3005 }
3006 $(document).find(".ays_survey_each_sub_user_info_header_button button").attr("data-clipboard-text", response.user_info_for_copy);
3007 $.each(questionsInHTML, function(){
3008 var question = $(this);
3009 var qId = question.data('id');
3010 var qType = question.data('type');
3011
3012 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
3013 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
3014 question.find('.ays_each_question_answer .ays-survey-submission-select option').removeAttr('selected');
3015 question.find('.ays_text_answer').html('');
3016
3017 if( typeof questionsData[qId] != 'undefined'){
3018 var surveyAnswer = questionsData[qId];
3019 switch( qType ){
3020 case 'radio':
3021 case 'yesorno':
3022 surveyAnswer = questionsData[qId].answer;
3023 var surveyOtherAnswer = questionsData[qId].otherAnswer;
3024 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
3025 question.find('.ays_each_question_answer input[type="radio"]').each(function(){
3026 var thisParent = $(this).parents(".ays_each_question_answer");
3027 if( surveyAnswer == $(this).data('id') ){
3028
3029 if(thisParent.hasClass("ays-survey-answer-label-other") && surveyOtherAnswer != ''){
3030 $(this).prop('checked', true);
3031 }
3032 else if(!thisParent.hasClass("ays-survey-answer-label-other")){
3033 $(this).prop('checked', true);
3034 }
3035
3036 }
3037 });
3038
3039 question.find('.ays-survey-answer-other-input').html((surveyOtherAnswer));
3040 break;
3041 case 'checkbox':
3042 surveyAnswer = questionsData[qId].answer;
3043 var surveyOtherAnswer = questionsData[qId].otherAnswer;
3044 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
3045 question.find('.ays_each_question_answer input[type="checkbox"]').each(function(){
3046 if( Array.isArray(surveyAnswer) ){
3047 for(var i=0; i < surveyAnswer.length; i++){
3048 if( surveyAnswer[i] == $(this).data('id') ){
3049 $(this).prop('checked', true);
3050 }
3051 }
3052 }else{
3053 if( surveyAnswer == $(this).data('id') ){
3054 $(this).prop('checked', true);
3055 }
3056 }
3057 });
3058 question.find('.ays-survey-answer-other-input').html((surveyOtherAnswer));
3059 break;
3060 case 'select':
3061 if( parseInt( surveyAnswer ) == 0 ){
3062 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('clear');
3063 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', '');
3064 }else{
3065 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set selected', surveyAnswer);
3066 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', surveyAnswer);
3067 }
3068 break;
3069 case 'star':
3070 surveyAnswer = questionsData[qId];
3071 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
3072 question.find('.ays-survey-star-icon').removeClass('fa_star').addClass('fa_star_o');
3073 question.find('.ays-survey-star-icon').css('color', 'rgb(51, 51, 51)');
3074 question.find('.ays_each_question_answer input[type="radio"]').each(function(){
3075
3076 if( parseInt( surveyAnswer ) >= $(this).data('id') ){
3077 $(this).prop('checked', true);
3078 $(this).parents('.ays-survey-answer-star-radio').find('.ays-survey-star-icon').removeClass('fa_star_o').addClass('fa_star');
3079 $(this).parents('.ays-survey-answer-star-radio').find('.ays-survey-star-icon').css('color', 'rgb(255, 87, 34)');
3080 }
3081 });
3082 break;
3083 case 'text':
3084 if( typeof surveyAnswer !== 'string' ){
3085 surveyAnswer = '';
3086 }
3087 surveyAnswer = nl2br( surveyAnswer );
3088 case 'short_text':
3089 case 'number':
3090 case 'phone':
3091 case 'name':
3092 case 'email':
3093 var elem = question.find('.ays_text_answer');
3094 elem.html( surveyAnswer );
3095 break;
3096 case 'date':
3097 case 'time':
3098 case 'date_time':
3099 surveyAnswer = questionsData[qId];
3100 var elem = question.find('.ays_text_answer');
3101 if( typeof surveyAnswer === 'string' ){
3102 surveyAnswer = surveyAnswer;
3103 }else{
3104 surveyAnswer = surveyAnswer.answer;
3105 }
3106 elem.html( surveyAnswer );
3107 break;
3108 }
3109 }else{
3110 switch( qType ){
3111 case 'radio':
3112 case 'yesorno':
3113 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
3114 question.find('.ays-survey-answer-other-input').val('');
3115 break;
3116 case 'checkbox':
3117 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
3118 question.find('.ays-survey-answer-other-input').val('');
3119 break;
3120 case 'select':
3121 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('clear');
3122 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', '');
3123 break;
3124 case 'star':
3125 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
3126 question.find('.ays-survey-star-icon').removeClass('fa_star').addClass('fa_star_o');
3127 question.find('.ays-survey-star-icon').css('color', 'rgb(51, 51, 51)');
3128 break;
3129 case 'text':
3130 case 'short_text':
3131 case 'number':
3132 case 'phone':
3133 case 'name':
3134 case 'email':
3135 case 'date':
3136 case 'time':
3137 var elem = question.find('.ays_text_answer');
3138 elem.html( '' );
3139 break;
3140 }
3141 }
3142 });
3143 }
3144 }
3145 });
3146 submissionPrevVal = submissionElVal;
3147 }
3148
3149
3150
3151 // ===============================================================
3152 // ====================== Xcho =========================
3153 // ===============================================================
3154
3155
3156 $('#ays_slack_client').on('input', function () {
3157 var clientId = $(this).val();
3158 if (clientId == '') {
3159 $("#slackOAuth2").addClass('disabled btn-outline-secondary');
3160 $("#slackOAuth2").removeClass('btn-secondary');
3161 return false;
3162 }
3163 var scopes = "channels%3Ahistory%20" +
3164 "channels%3Aread%20" +
3165 "channels%3Awrite%20" +
3166 "groups%3Aread%20" +
3167 "groups%3Awrite%20" +
3168 "mpim%3Aread%20" +
3169 "mpim%3Awrite%20" +
3170 "im%3Awrite%20" +
3171 "im%3Aread%20" +
3172 "chat%3Awrite%3Abot%20" +
3173 "chat%3Awrite%3Auser";
3174 var url = "https://slack.com/oauth/authorize?client_id=" + clientId + "&scope=" + scopes + "&state=" + clientId;
3175 $("#slackOAuth2").attr('data-src', url);//.toggleClass('disabled btn-outline-secondary btn-secondary');
3176 $("#slackOAuth2").removeClass('disabled btn-outline-secondary');
3177 $("#slackOAuth2").addClass('btn-secondary');
3178 });
3179 $("#slackOAuth2").on('click', function () {
3180 var url = $(this).attr('data-src');
3181 if (!url) {
3182 return false;
3183 }
3184 location.replace(url)
3185 });
3186 $('#ays_slack_secret').on('input', function(e) {
3187 if($(this).val() == ''){
3188 $("#slackOAuthGetToken").addClass('disabled btn-outline-secondary');
3189 $("#slackOAuthGetToken").removeClass('btn-secondary');
3190 return false;
3191 }
3192
3193 $("#slackOAuthGetToken").removeClass('disabled btn-outline-secondary');
3194 $("#slackOAuthGetToken").addClass('btn-secondary');
3195 });
3196
3197 // Limitations PRO
3198 $('#ays_survey_users_roles,#ays_survey_users_pro').select2();
3199
3200 $(document).find('#ays_survey_default_type').select2({
3201 allowClear: true,
3202 placeholder: SurveyMakerAdmin.selectQuestionDefaultType
3203 });
3204
3205 $(document).find(".ays-survey-min-votes-field").on("input" , function(){
3206 var $this = $(this);
3207 var minVal = parseInt($(this).val());
3208 var maxField = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-max-votes-field");
3209 if(minVal >= maxField.val())
3210 maxField.val(minVal);
3211 });
3212
3213 $(document).find(".ays-survey-max-votes-field").on("change" , function(){
3214 var $this = $(this);
3215 var maxVal = parseInt($(this).val());
3216 var minField = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-min-votes-field");
3217 var minVal = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-min-votes-field").val();
3218 if(maxVal == ''){
3219 return;
3220 }
3221 if(maxVal < minVal){
3222 $this.val(minVal);
3223 }
3224 });
3225
3226 $(document).on('click', '.ays_toggle_loader_radio', function (e) {
3227 var dataFlag = $(this).attr('data-flag');
3228 var dataType = $(this).attr('data-type');
3229 var state = false;
3230 if (dataFlag == 'true') {
3231 state = true;
3232 }
3233
3234 var parent = $(this).parents('.ays_toggle_loader_parent');
3235 if($(this).hasClass('ays_toggle_loader_slide')){
3236 switch (state) {
3237 case true:
3238 parent.find('.ays_toggle_loader_target').slideDown(250);
3239 break;
3240 case false:
3241 parent.find('.ays_toggle_loader_target').slideUp(250);
3242 break;
3243 }
3244 }else{
3245 switch (state) {
3246 case true:
3247 switch( dataType ){
3248 case 'text':
3249 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').show(250);
3250 parent.find('.ays_toggle_loader_target[data-type="gif"]').hide(250);
3251 break;
3252 case 'gif':
3253 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').show(250);
3254 parent.find('.ays_toggle_loader_target.ays_gif_loader_width_container[data-type="'+ dataType +'"]').css({
3255 'display': 'flex',
3256 'justify-content': 'center',
3257 'align-items': 'center'
3258 });
3259 parent.find('.ays_toggle_loader_target[data-type="text"]').hide(250);
3260 break;
3261 default:
3262 parent.find('.ays_toggle_loader_target').show(250);
3263 break;
3264 }
3265 break;
3266 case false:
3267 switch( dataType ){
3268 case 'text':
3269 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').hide(250);
3270 break;
3271 case 'gif':
3272 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').hide(250);
3273 break;
3274 default:
3275 parent.find('.ays_toggle_loader_target').hide(250);
3276 break;
3277 }
3278 break;
3279 }
3280 }
3281 });
3282
3283 $(document).find(".add_survey_loader_custom_gif,.ays-edit-survey-loader-custom-gif").on("click" , function(e){
3284 openMediaUploaderForGifLoader(e, $(this));
3285 });
3286
3287 $(document).on('click', '.ays-survey-image-wrapper-delete-wrap', function () {
3288 var wrap = $(this).parents('.ays-survey-image-wrap');
3289 wrap.find('.ays-survey-image-container').fadeOut(500);
3290 setTimeout(function(){
3291 wrap.find('img.ays_survey_img_loader_custom_gif').attr('src', '');
3292 wrap.find('input.ays-survey-image-path').val('');
3293 wrap.find('button.add_survey_loader_custom_gif').show();
3294 }, 450);
3295 });
3296
3297 $(document).find("#ays-survey-form .nav-tab").on("click" , function(){
3298 var $this = $(this);
3299 if($this.data("tab") != "undefined" && $this.data("tab") == 'tab1'){
3300 refreshSurveyColor($this);
3301 }
3302 });
3303
3304 function refreshSurveyColor(element){
3305 var customCss = $(document).find("#ays-survey-custom-css-additional");
3306 var parentElement = element.parents("#ays-survey-form");
3307 var surveyColor = parentElement.find("#ays_survey_color").val();
3308 var isModern = $(document).find('input[name="ays_survey_theme"]:checked').val() == 'modern' ? true : false;
3309 var isMinimal = $(document).find('input[name="ays_survey_theme"]:checked').val() == 'minimal' ? true : false;
3310 if( isMinimal || isModern ){
3311 if( parentElement.find("#ays_survey_color").val() == 'rgba(0,0,0,0)' ){
3312 surveyColor = '#333333';
3313 }
3314 }
3315
3316 var newCss = '#ays-survey-form .ays-survey-section-head-wrap .ays-survey-section-head {'
3317 newCss += 'border-top-color: '+surveyColor;
3318 newCss += '}';
3319 newCss += '#ays-survey-form .ays-survey-section-head-wrap .ays-survey-section-head-top .ays-survey-section-counter {'
3320 newCss += 'background-color: '+surveyColor;
3321 newCss += '}';
3322 newCss += '#ays-survey-form .ays-survey-input:focus ~ .ays-survey-input-underline-animation {'
3323 newCss += 'background-color: '+surveyColor;
3324 newCss += '}';
3325 newCss += '#ays-survey-form .dropdown-item:hover {'
3326 newCss += 'background-color: '+surveyColor+'29;';
3327 newCss += '}';
3328 newCss += '#ays-survey-form .dropdown-item:focus {'
3329 newCss += 'background-color: '+surveyColor+'29;';
3330 newCss += '}';
3331 newCss += '#ays-survey-form .dropdown-item:active {'
3332 newCss += 'background-color: '+surveyColor+';';
3333 newCss += '}';
3334 newCss += '#ays-survey-form input.ays-switch-checkbox:checked + .switch-checkbox-wrap .switch-checkbox-circles .switch-checkbox-thumb {'
3335 newCss += 'border-color: '+surveyColor;
3336 newCss += '}';
3337 newCss += '#ays-survey-form input.ays-switch-checkbox:checked + .switch-checkbox-wrap .switch-checkbox-track {'
3338 newCss += 'border-color: '+surveyColor+'53';
3339 newCss += '}';
3340 customCss.html(newCss);
3341 }
3342
3343 // var checkCountdownIsExists = $(document).find('#ays-survey-maker-countdown-main-container');
3344 var checkCountdownIsExists = $(document).find('#ays-survey-countdown-main-container');
3345
3346 if ( checkCountdownIsExists.length > 0 ) {
3347 var second = 1000,
3348 minute = second * 60,
3349 hour = minute * 60,
3350 day = hour * 24;
3351
3352 // var countdownEndTime = "DEC 05, 2025 23:59:59";
3353 var countdownEndTime = SurveyMakerAdmin.surveyBannerDate;
3354 var countDown = new Date(countdownEndTime).getTime(),
3355
3356 x = setInterval(function() {
3357
3358 var now = new Date().getTime(),
3359 distance = countDown - now;
3360
3361 var countDownDays = document.getElementById("ays-survey-countdown-days");
3362 var countDownHours = document.getElementById("ays-survey-countdown-hours");
3363 var countDownMinutes = document.getElementById("ays-survey-countdown-minutes");
3364 var countDownSeconds = document.getElementById("ays-survey-countdown-seconds");
3365
3366 if(countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null){
3367 countDownDays.innerText = Math.floor(distance / (day)),
3368 countDownHours.innerText = Math.floor((distance % (day)) / (hour)),
3369 countDownMinutes.innerText = Math.floor((distance % (hour)) / (minute)),
3370 countDownSeconds.innerText = Math.floor((distance % (minute)) / second);
3371 // countDownDays.innerText = Math.floor(distance / (day)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3372 // countDownHours.innerText = Math.floor((distance % (day)) / (hour)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3373 // countDownMinutes.innerText = Math.floor((distance % (hour)) / (minute)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3374 // countDownSeconds.innerText = Math.floor((distance % (minute)) / second).toLocaleString(undefined,{minimumIntegerDigits: 2});
3375
3376 }
3377
3378 //do something later when date is reached
3379 if (distance < 0) {
3380 var headline = document.getElementById("ays-survey-countdown-headline"),
3381 countdown = document.getElementById("ays-survey-countdown"),
3382 content = document.getElementById("ays-survey-countdown-content");
3383
3384 // headline.innerText = "Sale is over!";
3385 countdown.style.display = "none";
3386 content.style.display = "block";
3387
3388 clearInterval(x);
3389 }
3390 }, 1000);
3391 }
3392
3393 $(document).on('click', '.ays-survey-add-cover-image', function (e) {
3394 openMediaUploaderForCoverImage(e, $(this));
3395 });
3396
3397 $(document).on('click', '.removeCoverImage', function (e) {
3398 var $this = $(this);
3399 var thisParent = $this.parents('.ays_survey_cover_image_main');
3400 thisParent.find('.ays-survey-add-cover-image').html( SurveyMakerAdmin.addImage );
3401 thisParent.find('.ays-survey-image-body').fadeOut(500);
3402 thisParent.find('.ays-survey-cover-image-options,.ays-survey-cover-image-options-hr').fadeOut(500);
3403 setTimeout(function(){
3404 $this.parents('.ays-survey-image-container').find('.ays-survey-cover-img').removeAttr('src');
3405 $this.parents('.ays-survey-image-container').find('.ays-survey-cover-img-src').val('');
3406 }, 500);
3407 });
3408
3409 $(document).on('click', '.ays_survey_each_sub_user_info_header_button button', function () {
3410 selectElementContentsCopy($(this));
3411 });
3412
3413 var surveyResults = $(document).find('.ays_survey_result');
3414 for (var i in surveyResults) {
3415 surveyResults.eq(i).parents('tr').addClass('ays_survey_results');
3416 }
3417
3418 $(document).on("click", ".ays-survey-view-detailed-button", getEachSubmission);
3419
3420 $(document).on('click', '#ays-surveys-next-button,#ays-surveys-prev-button', function(e){
3421 e.preventDefault();
3422 var confirm;
3423 if($(e.target).hasClass("ays-survey-prev-survey-button")){
3424 confirm = window.confirm( SurveyMakerAdmin.prevSurveyPage );
3425 }
3426 else{
3427 confirm = window.confirm( SurveyMakerAdmin.nextSurveyPage );
3428 }
3429 if(confirm){
3430 window.location.replace($(this).attr('href'));
3431 }
3432 });
3433
3434 $(document).find('#ays-survey-title').on('input', function(e){
3435 var surveyTitleVal = $(this).val();
3436 var surveyTitle = aysSurveystripHTML( surveyTitleVal );
3437 $(document).find('.ays_survey_title_in_top').html( surveyTitle );
3438 });
3439
3440 // Select message vars surveys page
3441 $(document).find('.ays-survey-message-vars-icon').on('click', function(e){
3442 $(this).parents(".ays-survey-message-vars-box").find(".ays-survey-message-vars-data").toggle('fast');
3443 });
3444
3445 $(document).find('.ays-survey-open-surveys-list').on('click', function(e){
3446 $(this).parents(".ays-survey-subtitle-main-box").find(".ays-survey-surveys-data").toggle('fast');
3447 });
3448
3449 $(document).on( "click" , function(e){
3450
3451 if($(e.target).closest('.ays-survey-message-vars-box,.ays-survey-subtitle-main-box').length != 0){
3452
3453 }
3454 else{
3455 $(document).find(".ays-survey-message-vars-box .ays-survey-message-vars-data,.ays-survey-subtitle-main-box .ays-survey-surveys-data").hide('fast');
3456 }
3457 //
3458 });
3459
3460 $(document).find(".ays-survey-go-to-surveys").on("click" , function(e){
3461 e.preventDefault();
3462 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.');
3463 if(confirmRedirect){
3464 window.location = $(this).attr("href");
3465 }
3466 });
3467
3468 $(document).find('.ays-survey-message-vars-each-data').on('click', function(e){
3469 var messageVar = $(this).find(".ays-survey-message-vars-each-var").val();
3470 var mainParent = $(this).parents('.ays-survey-box-for-mv');
3471 var dataTMCE = mainParent.find('.ays-survey-message-vars-data').attr('data-tmce');
3472
3473 if ( mainParent.find("#wp-"+dataTMCE+"-wrap").hasClass("tmce-active") ){
3474 window.tinyMCE.get(dataTMCE).setContent( window.tinyMCE.get(dataTMCE).getContent() + messageVar + " " );
3475 }else{
3476 mainParent.find('#'+dataTMCE).append( " " + messageVar + " ");
3477 }
3478 });
3479 /* */
3480
3481 $(document).find('.ays-survey-add-new-button-video').on('click', function(e){
3482 $(document).find(".page-title-action").trigger("click");
3483 });
3484
3485 var ays_survey_popup_bg_color_picker = {
3486 defaultColor: '#ffffff',
3487 change: function (e) {
3488 }
3489 };
3490
3491 var ays_survey_popup_bg_color_mobile_picker = {
3492 defaultColor: '#ffffff',
3493 change: function (e) {
3494 }
3495 };
3496
3497 var aysSurveyPopupTitleTextColorPicker = {
3498 defaultColor: '#000000',
3499 change: function (e) {
3500 }
3501 };
3502
3503 var aysSurveyPopupTitleBgColorPicker = {
3504 defaultColor: '#00000000',
3505 change: function (e) {
3506 }
3507 };
3508
3509 $(document).find('#ays_survey_popup_trigger').on('change', function(){
3510 var triggerType = $(this).val();
3511 if(triggerType == 'on_click'){
3512 $(document).find('.ays-survey-popup-selector').show(250);
3513 $(document).find('.ays-survey-popup-selector').css('display','flex');
3514 $(document).find('.ays-survey-popup-selector').prev('hr').show(250);
3515 }else{
3516 $(document).find('.ays-survey-popup-selector').hide(250);
3517 $(document).find('.ays-survey-popup-selector').prev('hr').hide(250);
3518 }
3519 });
3520
3521 $(document).find('table#ays-survey-popup-position-table tr td').on('click', function(e){
3522 var val = $(this).data('value');
3523 $(document).find('.popup_survey_position_block #ays-survey-popup-position-val').val(val);
3524 aysCheckPopupPosition();
3525 });
3526
3527 $(document).find('table#ays-survey-position-table tr td').on('click', function(e){
3528 var val = $(this).data('value');
3529 $(document).find('.survey_position_block #ays-survey-position-val').val(val);
3530 aysCheckPosition();
3531 });
3532
3533 function aysCheckPopupPosition(){
3534 var hiddenVal = $(document).find('.popup_survey_position_block #ays-survey-popup-position-val').val();
3535
3536 if (hiddenVal == "") {
3537 var $this = $(document).find('table#ays-survey-popup-position-table tr td[data-value="center-center"]');
3538 }else{
3539 var $this = $(document).find('table#ays-survey-popup-position-table tr td[data-value='+ hiddenVal +']');
3540 }
3541
3542 if (hiddenVal == 'center-center' || hiddenVal == ''){
3543 $(document).find("#popupMargin").addClass('display_none');
3544 $(document).find(".ays_pb_hr_hide").addClass('display_none');
3545 }else{
3546 $(document).find("#popupMargin").removeClass('display_none');
3547 $(document).find(".ays_pb_hr_hide").removeClass('display_none');
3548 }
3549
3550 $(document).find('table#ays-survey-popup-position-table td').removeAttr('style');
3551 $this.css('background-color','#a2d6e7');
3552 }
3553
3554
3555 function aysCheckPosition(){
3556 var hiddenVal = $(document).find('.survey_position_block #ays-survey-position-val').val();
3557
3558 if (hiddenVal == "") {
3559 var $this = $(document).find('table#ays-survey-position-table tr td[data-value="center-center"]');
3560 }else{
3561 var $this = $(document).find('table#ays-survey-position-table tr td[data-value='+ hiddenVal +']');
3562 }
3563
3564 $(document).find('table#ays-survey-position-table td').removeAttr('style');
3565 $this.css('background-color','#a2d6e7');
3566 }
3567
3568 // Initialize popup survey color picker
3569 $(document).find('#ays_survey_popup_bg_color').wpColorPicker(ays_survey_popup_bg_color_picker);
3570 // Initialize popup survey color picker
3571 $(document).find('#ays_survey_popup_bg_color_mobile').wpColorPicker(ays_survey_popup_bg_color_mobile_picker);
3572 // Initialize popup survey title bg color picker
3573 $(document).find('#ays_survey_popup_title_bg_color,#ays_survey_popup_title_bg_color_mobile').wpColorPicker(aysSurveyPopupTitleBgColorPicker);
3574 // Initialize popup survey title text color picker
3575 $(document).find('#ays_survey_popup_title_text_color,#ays_survey_popup_title_text_color_mobile').wpColorPicker(aysSurveyPopupTitleTextColorPicker);
3576
3577 $(document).find('.ays-survey-aysDropdown-answer-view').on('change', function(e){
3578 var answerViewAligne = $(document).find('.ays-survey-aysDropdown-answer-view-alignment');
3579 answerViewAligne.aysDropdown('destroy');
3580 var answerViewType = $(this).aysDropdown('get value');
3581
3582 var dataObj = {
3583 'list': [
3584 {
3585 name : 'Left',
3586 value : 'flex-start',
3587 selected : true
3588 },
3589 {
3590 name : 'Right',
3591 value : 'flex-end',
3592 },
3593 {
3594 name : 'Center',
3595 value : 'center',
3596 }
3597 ],
3598 'grid': [
3599 {
3600 name : 'Space around',
3601 value : 'space-around',
3602 selected : true
3603 },
3604 {
3605 name : 'Space between',
3606 value : 'space-between',
3607 },
3608 {
3609 name : 'Left',
3610 value : 'flex-start',
3611 },
3612 {
3613 name : 'Right',
3614 value : 'flex-end',
3615 },
3616 {
3617 name : 'Center',
3618 value : 'center',
3619 }
3620 ]
3621 }
3622 answerViewAligne.aysDropdown({
3623 values: dataObj[answerViewType]
3624 });
3625 });
3626
3627 // Survey Templates start
3628 $(document).find(".ays-survey-open-templates-modal").on("click" , function(e){
3629 e.preventDefault();
3630 var $this = $('#ays-survey-templates-modal');
3631 $this.find('.ays-modal-content-survey-templates .ays-survey-templates-box.ays-survey-templates-blank-box').remove();
3632 $(document).find('#ays-survey-templates-modal').aysModal('show');
3633 $(document).find('#ays-survey-templates-modal .ays-modal-content-survey-templates-header .ays-close-templates-popup').attr('data-action' , 'in-edit-page');
3634 $(document).find('#ays-survey-templates-modal .ays-modal-content.ays-modal-content-survey-templates').removeClass('no-confirmation');
3635
3636 });
3637
3638 $(document).find(".ays-survey-templates-box-apply-button-blank").on("click" , function(e){
3639 e.preventDefault();
3640 e.stopPropagation();
3641 $(document).find('#ays-survey-templates-modal').aysModal('hide');
3642 });
3643
3644 $(document).find('.ays-survey-templates-box').on('click' , function(){
3645 var tempType = $(this).attr('data-template');
3646 if(tempType == 'blank-form'){
3647 $(document).find(".ays-survey-templates-box-apply-button-blank").trigger('click');
3648 return;
3649 }
3650 $(this).find('.ays-survey-templates-box-apply-button').trigger('click');
3651 });
3652
3653 $(document).find(".ays-survey-templates-box-apply-button").on("click" , function(e){
3654 e.preventDefault();
3655 e.stopPropagation();
3656 var $this = $(this);
3657 var $thisParent = $this.parents(".ays-modal-content-survey-templates");
3658 if(!$thisParent.hasClass('no-confirmation')){
3659 var confirm = window.confirm(SurveyMakerAdmin.confirmMessageTemplate);
3660 }
3661 else{
3662 var confirm = true;
3663 }
3664 if(confirm == true){
3665
3666
3667 var modal = $('#ays-survey-templates-modal');
3668 var otherTypes = new Array(
3669 'text',
3670 'linear_scale',
3671 'star',
3672 'short_text',
3673 'number',
3674 'phone',
3675 'name',
3676 'email',
3677 'date',
3678 'date_time',
3679 'time',
3680 );
3681 $thisParent.find(".ays_survey_preloader").show();
3682
3683 var action = 'ays_survey_add_survey_template';
3684
3685 var templateName = $this.attr('data-template');
3686
3687 $.ajax({
3688 url: ajaxurl,
3689 type: 'post',
3690 dataType: 'json',
3691 data: {
3692 action: action,
3693 template_file_name: templateName
3694 },
3695 success: function(response) {
3696 if (response.status) {
3697 var sections = response.data.sections;
3698 $(document).find('#ays-survey-title').val(response.data.title);
3699 // For Sections
3700 var newQuestion = "";
3701 var parent = $(document).find(".ays-survey-sections-conteiner");
3702 parent.html("");
3703 for(var key in sections){
3704
3705 aysSurveyAddSection( null, null, true );
3706 var lastAddedSection = parent.find(".ays-survey-new-section:last-child");
3707 lastAddedSection.find(".ays-survey-section-questions").html("");
3708 lastAddedSection.find(".ays-survey-section-title").val(sections[key].title);
3709 // For Questions
3710 for(var questionKey in sections[key].questions){
3711 var allAddedAnswers = new Array();
3712 var questionType = typeof sections[key].questions[questionKey].type != "undefined" ? sections[key].questions[questionKey].type : "";
3713 if(questionType != ""){
3714 aysSurveyAddQuestion(lastAddedSection.attr("data-id"), false, lastAddedSection , true);
3715 newQuestion = lastAddedSection.find("div.ays-survey-new-question[data-template-id='"+(Number(questionKey)+1)+"']");
3716 newQuestion.find('.ays-survey-question-type').aysDropdown('set selected', sections[key].questions[questionKey].type );
3717 newQuestion.find('.ays-survey-question-type').aysDropdown('set value', sections[key].questions[questionKey].type );
3718 newQuestion.find('.ays-survey-check-type-before-change').val( sections[key].questions[questionKey].type );
3719 newQuestion.find(".ays-survey-question-input-textarea").html(sections[key].questions[questionKey].question);
3720 newQuestion.find(".ays-survey-question-description-input-textarea").html(sections[key].questions[questionKey].description);
3721 var thisButton = newQuestion.find(".ays-survey-action-add-answer");
3722
3723 // For Answers
3724 for(var answerKey in sections[key].questions[questionKey].answers){
3725
3726 aysSurveyAddAnswer( thisButton, false, true );
3727 var newAnswer = newQuestion.find("div.ays-survey-new-answer[data-id='"+(Number(answerKey)+1)+"']");
3728 allAddedAnswers.push(newAnswer);
3729 newAnswer.find(".ays-survey-input").val(sections[key].questions[questionKey].answers[answerKey].answer);
3730
3731 }
3732
3733 if(sections[key].questions[questionKey].user_variant == 'on'){
3734 var checkbox = newQuestion.find('.ays-survey-other-answer-checkbox').attr('checked', 'checked');
3735 var oterAnswer = newQuestion.find('.ays-survey-other-answer-row');
3736 oterAnswer.removeAttr('style');
3737 newQuestion.find('.ays-survey-other-answer-add-wrap').css('display','none');
3738 }
3739
3740 newQuestion.find('.ays-survey-input-required-question').prop('checked', sections[key].questions[questionKey].options[0].required == 'on' ? true : false );
3741
3742 if(otherTypes.indexOf(questionType) == -1 && allAddedAnswers.length > 0){
3743 newQuestion.find("div.ays-survey-answers-conteiner").html(allAddedAnswers);
3744 }
3745
3746 reInitPopovers( newQuestion );
3747 }
3748 }
3749 }
3750 reInitPopovers( parent );
3751 setTimeout(function(){
3752 $thisParent.find(".ays_survey_preloader").hide();
3753 modal.aysModal('hide');
3754 } , 100);
3755
3756 }
3757 else{
3758 $thisParent.find(".ays_survey_preloader").hide();
3759 }
3760 },
3761 error: function(){
3762 $thisParent.find(".ays_survey_preloader").hide();
3763 modal.aysModal('hide');
3764 }
3765 });
3766 }
3767 });
3768 // Survey Templates end
3769
3770 // Pro features start
3771 $(document).find(".ays-pro-features-v2-upgrade-button").hover(function() {
3772 // Code to execute when the mouse enters the element
3773 var unlockedImg = "Unlocked_24_24.svg";
3774 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
3775 var imgUrl = imgBox.attr("data-img-src");
3776 var newString = imgUrl.replace("Locked_24x24.svg", unlockedImg);
3777
3778 imgBox.css("background-image", 'url(' + newString + ')');
3779 imgBox.attr("data-img-src", newString);
3780 }, function() {
3781
3782 var lockedImg = "Locked_24x24.svg";
3783 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
3784 var imgUrl = imgBox.attr("data-img-src");
3785 var newString = imgUrl.replace("Unlocked_24_24.svg", lockedImg);
3786
3787 imgBox.css("background-image", 'url(' + newString + ')');
3788 imgBox.attr("data-img-src", newString);
3789 });
3790
3791 $(document).find(".ays-pro-features-v2-video-button").hover(function() {
3792 // Code to execute when the mouse enters the element
3793 var unlockedImg = "Video_24x24_Hover.svg";
3794 var imgBox = $(this).find(".ays-pro-features-v2-video-icon");
3795 var imgUrl = imgBox.attr("data-img-src");
3796 var newString = imgUrl.replace("Video_24x24.svg", unlockedImg);
3797
3798 imgBox.css("background-image", 'url(' + newString + ')');
3799 imgBox.attr("data-img-src", newString);
3800 }, function() {
3801
3802 var lockedImg = "Video_24x24.svg";
3803 var imgBox = $(this).find(".ays-pro-features-v2-video-icon");
3804 var imgUrl = imgBox.attr("data-img-src");
3805 var newString = imgUrl.replace("Video_24x24_Hover.svg", lockedImg);
3806
3807 imgBox.css("background-image", 'url(' + newString + ')');
3808 imgBox.attr("data-img-src", newString);
3809 });
3810
3811 $(document).on('click', '.ays-pro-features-v2-video-button,.ays-survey-question-actions-pro-button', function(e){
3812 e.preventDefault();
3813 if($(this).hasClass('ays-survey-question-actions-pro-button')){
3814 var _thisDataParent = $(this);
3815 }
3816 else{
3817 var _thisDataParent = $(this).parents('.ays-pro-features-v2-main-box').find('.ays-pro-pro-features-popup');
3818 }
3819 var popupModal = $(document).find('#pro-features-popup-modal');
3820
3821 // Get option Data
3822 var optionTitle = _thisDataParent.attr('data-option-title');
3823 var optionDesc = _thisDataParent.attr('data-option-text');
3824 var optionVideoUrl = _thisDataParent.attr('data-video-url');
3825
3826 var popupModalTitleBox = popupModal.find('.pro-features-popup-modal-right-box-title');
3827 var popupModalTitleContent = popupModal.find('.pro-features-popup-modal-right-box-content');
3828 popupModalTitleBox.html(optionTitle);
3829 popupModalTitleContent.html(optionDesc);
3830
3831
3832 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3833
3834 if ( typeof optionVideoUrl != "undefined" && optionVideoUrl != "") {
3835 var videoID = ays_youtube_parser(optionVideoUrl);
3836 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>';
3837
3838 leftSection.html(iframeHTML);
3839 }
3840
3841 popupModal.aysModal('show_flex');
3842 });
3843
3844 $(document).on('click', '.ays-survey-question-actions-pro-redirect-button', function(e){
3845 e.preventDefault();
3846
3847 var href = $(this).attr("data-href");
3848 if (href) {
3849 window.open(href, '_blank');
3850 }
3851 });
3852
3853 // Pro features end
3854
3855 // Check new added Survey start
3856 var createdNewSurvey = getCookie('ays_survey_created_new');
3857 if(createdNewSurvey && createdNewSurvey > 1){
3858 var url = new URL(window.location.href);
3859
3860 // Get a specific GET parameter by name
3861 var parameterValue = url.searchParams.get("action");
3862 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>';
3863
3864 var getCustomPostId = getCookie('ays_survey_created_new_'+createdNewSurvey+'_post_id');
3865 var htmlCustomPostMessage = '';
3866
3867 var link = "#";
3868 if(getCustomPostId){
3869 link = getCustomPostId;
3870 }
3871 var htmlContent = parameterValue && parameterValue == 'edit' ? '' : htmlDefaultText;
3872 htmlContent += htmlCustomPostMessage;
3873
3874 var previewButtonSvgIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">'+
3875 '<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"/>'+
3876 '</svg>';
3877
3878 swal({
3879 title: '<strong>Great job</strong>',
3880 type: 'success',
3881 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,
3882 showCancelButton: true,
3883 showCloseButton: true,
3884 focusConfirm: false,
3885 cancelButtonClass: "ays-survey-preview-popup-cancel-button",
3886 confirmButtonText: '<i class="ays_fa ays_fa_thumbs_up"></i> Done',
3887 cancelButtonText: '<a href="'+ link +'" target="_blank">'+ SurveyMakerAdmin.preivewSurvey + ' ' + previewButtonSvgIcon +'</a>',
3888 confirmButtonAriaLabel: 'Thumbs up, great!',
3889 });
3890 deleteCookie('ays_survey_created_new');
3891 deleteCookie('ays_survey_created_new_'+createdNewSurvey+'_post_id');
3892 }
3893 // Check new added Survey end
3894
3895 $(document).find('input[type="submit"]#doaction, input[type="submit"]#doaction2').on('click', function(e) {
3896 showConfirmationIfDelete(e);
3897 });
3898
3899 $(document).on('mouseover', '.ays-dashicons', function(){
3900 var allRateStars = $(document).find('.ays-dashicons');
3901 var index = allRateStars.index(this);
3902 allRateStars.removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3903 for (var i = 0; i <= index; i++) {
3904 allRateStars.eq(i).removeClass('ays-dashicons-star-empty').addClass('ays-dashicons-star-filled');
3905 }
3906 });
3907
3908 $(document).on('mouseleave', '.ays-rated-link', function(){
3909 $(document).find('.ays-dashicons').removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3910 });
3911
3912 $(document).on('click', '.ays-survey-collapse-options', function(){
3913 var $this = $(this);
3914 var $thisRotateButton = $(this).find('.ays-survey-collapse-options-button');
3915 var $collapsibleOptions = $this.siblings('.ays-survey-collapsible-options');
3916 var newRotation = 0;
3917
3918 $collapsibleOptions.toggle();
3919
3920 var currentRotation = $thisRotateButton.data('rotation') || 0;
3921
3922 if(currentRotation === 0){
3923 newRotation = -90;
3924 $thisRotateButton.css('color' , '#c4c4c4')
3925 }
3926 else{
3927 newRotation = 0;
3928 $thisRotateButton.css('color' , '#008cff')
3929 }
3930
3931 $thisRotateButton.css('transform', `rotate(${newRotation}deg)`).data('rotation', newRotation);
3932 });
3933
3934 $(document).on('click', '.ays-survey-collapse-all-options', function(){
3935 var $thisMainParent = $(this).parents('.ays-survey-tab-content');
3936 var $thisRotateButtons = $thisMainParent.find('.ays-survey-collapse-options-button');
3937 var $collapsibleAllOptions = $thisMainParent.find('.ays-survey-collapsible-options');
3938 $collapsibleAllOptions.hide();
3939 $thisRotateButtons.css('color' , '#c4c4c4');
3940 $thisRotateButtons.css('transform', `rotate(-90deg)`).data('rotation', -90);
3941 });
3942
3943 $(document).on('click', '.ays-survey-expand-all-options', function(){
3944 var $thisMainParent = $(this).parents('.ays-survey-tab-content');
3945 var $thisRotateButtons = $thisMainParent.find('.ays-survey-collapse-options-button');
3946 var $collapsibleAllOptions = $thisMainParent.find('.ays-survey-collapsible-options');
3947 $collapsibleAllOptions.show();
3948 $thisRotateButtons.css('color' , '#008cff');
3949 $thisRotateButtons.css('transform', `rotate(0deg)`).data('rotation', 0);
3950 });
3951
3952 // Replace image to YouTube embed video
3953 $(document).on('click', '.ays-survey-youtube-placeholder', function() {
3954 var videoId = $(this).data('video-id');
3955 var iframe = $('<iframe>', {
3956 src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1',
3957 class: '',
3958 width: 560,
3959 height: 315,
3960 frameborder: 0,
3961 allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
3962 allowfullscreen: true,
3963 });
3964 $(this).replaceWith(iframe);
3965 });
3966
3967 $(document).on('click', 'body', function(e){
3968 if($(e.target).hasClass('ays-modal')){
3969 $(e.target).find(".ays-close").trigger("click");
3970 $(e.target).find(".ays-close-editor-popup").trigger("click");
3971 }
3972 });
3973
3974 $(document).on("click", '#ays-survey-add-question-filter', function (e) {
3975 var filterBox = $(document).find('.ays-survey-add-question-filter-option-box');
3976
3977 if( filterBox.hasClass('display_none') ){
3978 filterBox.show(250);
3979 filterBox.removeClass('display_none');
3980 } else {
3981 filterBox.hide(250);
3982 filterBox.addClass('display_none');
3983 }
3984 });
3985
3986 $(document).on('click', '.ays-survey-save-publish-link', function(e){
3987 e.preventDefault();
3988 var saveButton = $(document).find('#ays-button-apply-top.button, #ays-button-apply.button').first();
3989
3990 if (saveButton.length) {
3991 saveButton.trigger('click');
3992 }
3993 });
3994
3995 $(document).on('click', '.ays-survey-copy-shortcode-btn', function(e){
3996 e.preventDefault();
3997 var $this = $(this);
3998 var shortcode = $this.attr('data-shortcode');
3999 var tooltip = $this.parents('.ays-survey-copy-wrapper').find('.ays-survey-copy-tooltip');
4000
4001 if (!shortcode) {
4002 return;
4003 }
4004
4005 if (navigator.clipboard && window.isSecureContext) {
4006 navigator.clipboard.writeText(shortcode);
4007 } else {
4008 var textField = document.createElement('textarea');
4009 textField.value = shortcode;
4010 document.body.appendChild(textField);
4011 textField.select();
4012 document.execCommand('copy');
4013 textField.remove();
4014 }
4015
4016 tooltip.addClass('ays-survey-show');
4017 setTimeout(function(){
4018 tooltip.removeClass('ays-survey-show');
4019 }, 1200);
4020 });
4021
4022 function showConfirmationIfDelete(e) {
4023 var $el = $(e.target);
4024 var elParent = $el.parent();
4025 var actionSelect = elParent.find('select[name="action"]');
4026 var action = actionSelect.val();
4027
4028 if (action === 'bulk-delete') {
4029 e.preventDefault();
4030 var confirmDelete = confirm(SurveyMakerAdmin.deleteElementFromListTable);
4031
4032 if (confirmDelete) {
4033 var form = $el.closest('form');
4034 form.submit();
4035 }
4036 }
4037 }
4038
4039 function getCookie(cname) {
4040 let name = cname + "=";
4041 let decodedCookie = decodeURIComponent(document.cookie);
4042 let ca = decodedCookie.split(';');
4043 for(let i = 0; i <ca.length; i++) {
4044 let c = ca[i];
4045 while (c.charAt(0) == ' ') {
4046 c = c.substring(1);
4047 }
4048 if (c.indexOf(name) == 0) {
4049 return c.substring(name.length, c.length);
4050 }
4051 }
4052 return "";
4053 }
4054
4055 function ays_youtube_parser(url){
4056 var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
4057 var match = url.match(regExp);
4058 return (match&&match[7].length==11)? match[7] : false;
4059 }
4060
4061
4062 function deleteCookie(name) {
4063 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
4064 }
4065
4066 });
4067
4068 })( jQuery );
4069
4070 document.addEventListener("DOMContentLoaded", function() {
4071 var startDate = new Date("2025-09-21");
4072 var endDate = new Date("2025-10-21");
4073 var totalLicenses = 50;
4074 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);
4075 function getCurrentProgress() {
4076 var today = new Date();
4077 // today.setDate(today.getDate() + 1);
4078 var daysPassed = Math.floor((today - startDate) / (1000 * 60 * 60 * 24));
4079 var usedLicenses = 0;
4080 for (var i = 0; i < Math.min(daysPassed, progressionPattern.length); i++) {
4081 usedLicenses += progressionPattern[i];
4082 }
4083 return Math.min(usedLicenses, totalLicenses);
4084 }
4085 function updateProgress() {
4086 var usedLicenses = getCurrentProgress();
4087 var remainingLicenses = totalLicenses - usedLicenses;
4088 var progressPercentage = (usedLicenses / totalLicenses) * 100;
4089 var remainingElement = document.getElementById("remaining-licenses");
4090 var progressElement = document.getElementById("progress-fill");
4091 if (remainingElement) remainingElement.textContent = remainingLicenses;
4092 if (progressElement) progressElement.style.width = progressPercentage + "%";
4093 }
4094 updateProgress();
4095 });
4096
4097 // Copy to clipboard function
4098 function surveyCopyToClipboard(text) {
4099 if (navigator.clipboard && window.isSecureContext) {
4100 navigator.clipboard.writeText(text).then(function() {
4101 surveyShowCopyNotification(SurveyMakerAdmin.successCopyCoupon);
4102 }).catch(function() {
4103 fallbackCopyTextToClipboard(text);
4104 });
4105 } else {
4106 fallbackCopyTextToClipboard(text);
4107 }
4108 }
4109
4110 function fallbackCopyTextToClipboard(text) {
4111 var textArea = document.createElement("textarea");
4112 textArea.value = text;
4113 textArea.style.position = "fixed";
4114 textArea.style.top = "-9999px";
4115 textArea.style.left = "-9999px";
4116 document.body.appendChild(textArea);
4117 textArea.focus();
4118 textArea.select();
4119 try {
4120 var successful = document.execCommand("copy");
4121 if (successful) {
4122 surveyShowCopyNotification(SurveyMakerAdmin.successCopyCoupon);
4123 } else {
4124 surveyShowCopyNotification(SurveyMakerAdmin.failedCopyCoupon);
4125 }
4126 } catch (err) {
4127 surveyShowCopyNotification(SurveyMakerAdmin.failedCopyCoupon);
4128 }
4129 document.body.removeChild(textArea);
4130 }
4131
4132 function surveyShowCopyNotification(message) {
4133 var notification = document.createElement("div");
4134 notification.className = "ays-survey-copy-notification show";
4135 console.log(notification);
4136 notification.textContent = message;
4137 document.body.appendChild(notification);
4138 setTimeout(function() {
4139 notification.classList.remove("show");
4140 setTimeout(function() {
4141 document.body.removeChild(notification);
4142 }, 300);
4143 }, 2000);
4144 }