-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp_sugar.js
49 lines (38 loc) · 1.42 KB
/
wp_sugar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
jQuery(function($){
$admin_url = window.location.href.substr(0, window.location.href.search('wp-admin/'));
$ajax_spinner = '<span id="ajax_spinner"><img src="' + $admin_url + '/wp-admin/images/wpspin_light.gif" /></span>';
// test connection
$('#test_connect').click(function(){
$('#ajax_spinner').remove();
$('#wp_sugar_general_settings #test_connect').after($ajax_spinner);
$data = { action: 'wp_sugar' }
$.post(ajaxurl, $data, function(response) {
$('#ajax_spinner')
.html(response)
$('#ajax_spinner').delay(2000)
.fadeOut('slow');
});
});
// load form entries on change
$('form#wp_sugar_form_settings select.wp_sugar_select_form').change(function(){
$select = $(this).val();
$.post(ajaxurl,{action:'wp_sugar_load_gforms', formid:$select}, function(response) {
$('#wp_sugar_ajax_result').html(response);
});
});
// submit form
$('form#wp_sugar_form_settings').submit(function(){
$this = $(this);
$data = 'action=wp_sugar_submit_form&' + $(this).serialize();
$('#ajax_spinner').remove();
$('#wp_sugar_form_settings #submit_form_data').after($ajax_spinner);
$.post(ajaxurl, $data, function(response) {
response_text = (response) ? 'Updated!' : 'Error!';
$('#ajax_spinner')
.html(response_text)
$('#ajax_spinner').delay(2000)
.fadeOut('slow');
});
return false;
})
});