| 1 |
jQuery(function($){ |
| 2 |
|
| 3 |
function get_tinymce_content(name){ |
| 4 |
if (jQuery("#"+name+" .wp-editor-wrap").hasClass("tmce-active")){ |
| 5 |
return tinyMCE.get(name+'_textarea').getContent(); |
| 6 |
} else |
| 7 |
{ |
| 8 |
return jQuery("#" +name+ "_textarea").val(); |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
var save_button = $('.accua_form_save_settings_button'); |
| 13 |
var save_status = $(".accua_form_save_settings_status"); |
| 14 |
$('.accua_form_save_settings_button').click(function(){ |
| 15 |
save_button.attr('disabled', 'disabled') |
| 16 |
save_status.empty(); |
| 17 |
save_status.append("<span class='accua_form_api_throbbler'></span>"); |
| 18 |
|
| 19 |
var form_id = $('#accua_form_save_settings_id').val(); |
| 20 |
|
| 21 |
var data = { |
| 22 |
'action': 'accua-save-form-settings', |
| 23 |
'form-id': form_id, |
| 24 |
'title': $('#title').val(), |
| 25 |
'use_ajax': ($('#accua_form_use_ajax .accua_form_value').is(':checked') ? 1 : 0) |
| 26 |
}; |
| 27 |
|
| 28 |
var layout = $('#accua_form_layout .accua_form_value').val(); |
| 29 |
if (layout == 'toplabel' || layout == 'sidebyside') { |
| 30 |
data.layout = layout; |
| 31 |
} |
| 32 |
|
| 33 |
$.each( |
| 34 |
['success_message','error_message','emails_from','admin_emails_to','emails_bcc','admin_emails_subject','admin_emails_message','confirmation_emails_subject','confirmation_emails_message'], |
| 35 |
function(i,key){ |
| 36 |
var value = $('#accua_form_'+key+' .accua_form_check_override:checked').val(); |
| 37 |
if(value!=undefined && value!=0) { |
| 38 |
if(value==-1) |
| 39 |
{ |
| 40 |
data[key] =''; |
| 41 |
data[key+"_no_message"] = 1; |
| 42 |
} |
| 43 |
else { |
| 44 |
var element = $('#accua_form_'+key+' .accua_form_value'); |
| 45 |
if(element.is('input')){ |
| 46 |
data[key] = $('#accua_form_'+key+' .accua_form_value').val(); |
| 47 |
} |
| 48 |
else if(element.is('textarea')) { |
| 49 |
data[key] = get_tinymce_content('accua_form_'+key); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
); |
| 55 |
|
| 56 |
/* |
| 57 |
$.post( |
| 58 |
ajaxurl, |
| 59 |
data, |
| 60 |
function(){}, |
| 61 |
'json' |
| 62 |
) |
| 63 |
*/ |
| 64 |
|
| 65 |
$.ajax(ajaxurl, { |
| 66 |
'type': 'POST', |
| 67 |
'data': data, |
| 68 |
'success': function(){ |
| 69 |
document.getElementById('accua_form_preview_area').src = 'admin-ajax.php?action=accua_forms_preview&fid=' + form_id; |
| 70 |
try { |
| 71 |
if (history.pushState && window.location.search.search('page=accua_forms_list') == -1) { |
| 72 |
history.pushState('', document.title, 'admin.php?page=accua_forms_list&fid=' + form_id); |
| 73 |
window.onpopstate = function(event) { |
| 74 |
location.reload(); |
| 75 |
} |
| 76 |
} |
| 77 |
} catch (e) {} |
| 78 |
|
| 79 |
var success_message = $("<span style='color:#0C0'>Settings saved</span>"); |
| 80 |
save_status.empty(); |
| 81 |
save_status.append(success_message); |
| 82 |
var success_fadeout = function(){ |
| 83 |
success_message.fadeOut(5000); |
| 84 |
} |
| 85 |
setTimeout(success_fadeout, 15000); |
| 86 |
save_button.removeAttr('disabled'); |
| 87 |
}, |
| 88 |
'error': function(){ |
| 89 |
save_status.empty(); |
| 90 |
save_status.append("<span style='color:#c00'>Error saving settings, please retry</span>"); |
| 91 |
save_button.removeAttr('disabled'); |
| 92 |
} |
| 93 |
}); |
| 94 |
|
| 95 |
}); |
| 96 |
}); |
| 97 |
|