| 1 |
/** |
| 2 |
* global wpbc_plugins_params |
| 3 |
*/ |
| 4 |
jQuery( |
| 5 |
function ($) { |
| 6 |
var wpbc_deactivation_feedback = { |
| 7 |
init: function () { |
| 8 |
this.event_init(); |
| 9 |
}, |
| 10 |
event_init: function () { |
| 11 |
var _that = this; |
| 12 |
|
| 13 |
$( document.body ).on( |
| 14 |
"click", |
| 15 |
'tr[data-plugin="booking/wpdev-booking.php"] span.deactivate a', |
| 16 |
function (e) { |
| 17 |
e.preventDefault(); |
| 18 |
$( "#wpbc_deactivate-feedback-popup-wrapper" ).addClass( 'active' ); |
| 19 |
} |
| 20 |
); |
| 21 |
|
| 22 |
$( document.body ).on( |
| 23 |
"click", |
| 24 |
'tr[data-plugin="booking-calendar-com/booking-calendar-com.php"] span.deactivate a', |
| 25 |
function (e) { |
| 26 |
e.preventDefault(); |
| 27 |
$( '#wpbc_deactivate-feedback-popup-wrapper' ).addClass( 'active' ); |
| 28 |
} |
| 29 |
); |
| 30 |
|
| 31 |
$( "#wpbc_deactivate-feedback-popup-wrapper" ).click( |
| 32 |
function (event) { |
| 33 |
var $target = $( event.target ); |
| 34 |
if ( ! $target.closest( ".wpbc_deactivate-feedback-popup-inner" ).length ) { |
| 35 |
$( "#wpbc_deactivate-feedback-popup-wrapper" ).removeClass( |
| 36 |
"active" |
| 37 |
); |
| 38 |
} |
| 39 |
} |
| 40 |
); |
| 41 |
|
| 42 |
$( "form.wpbc_deactivate-feedback-form" ).on( |
| 43 |
'submit', |
| 44 |
function (e) { |
| 45 |
e.preventDefault(); |
| 46 |
_that.send_data( $( this ) ); |
| 47 |
} |
| 48 |
); |
| 49 |
|
| 50 |
$( '#wpbc_deactivate-feedback-popup-wrapper' ).on( |
| 51 |
'click', |
| 52 |
'.close-deactivate-feedback-popup', |
| 53 |
function () { |
| 54 |
$( '#wpbc_deactivate-feedback-popup-wrapper' ).removeClass( 'active' ); |
| 55 |
} |
| 56 |
); |
| 57 |
|
| 58 |
$( 'input.wpbc_deactivate-feedback-input' ).on( |
| 59 |
'click', |
| 60 |
function () { |
| 61 |
if ( jQuery( "form.wpbc_deactivate-feedback-form" ).find( 'input[name="reason_slug"]:checked' ).length ) { |
| 62 |
jQuery( '.wpbc_deactivate-feedback-popup-form-more-details' ).show(); |
| 63 |
jQuery( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).hide(); |
| 64 |
} else { |
| 65 |
jQuery( '.wpbc_deactivate-feedback-popup-form-more-details' ).hide(); |
| 66 |
jQuery( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).show(); |
| 67 |
} |
| 68 |
} |
| 69 |
); |
| 70 |
}, |
| 71 |
send_data: function (form) { |
| 72 |
var reason_slug = form.find( 'input[name="reason_slug"]:checked' ).map( |
| 73 |
function () { |
| 74 |
return jQuery( this ).val(); |
| 75 |
} |
| 76 |
).get().join( ' | ' ); |
| 77 |
|
| 78 |
if ( 0 === jQuery( "form.wpbc_deactivate-feedback-form" ).find( 'input[name="reason_slug"]:checked' ).length ) { |
| 79 |
alert( "Please select at least one option from the list" ); |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
if ( form.find( "button.submit" ).hasClass( "button-disabled" ) ) { |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
var reason_text = ''; |
| 88 |
var reason_text_el = form.find( |
| 89 |
'input[name="reason_' + reason_slug + '"]' |
| 90 |
); |
| 91 |
|
| 92 |
if (reason_text_el.length > 0) { |
| 93 |
reason_text = reason_text_el.val(); |
| 94 |
} |
| 95 |
|
| 96 |
var data = { |
| 97 |
reason_slug: "user_registration_deactivation_notice", |
| 98 |
}; |
| 99 |
|
| 100 |
data["reason_" + reason_slug] = reason_text; |
| 101 |
|
| 102 |
var values_arr = {}; |
| 103 |
jQuery.each( |
| 104 |
form.serializeArray(), |
| 105 |
function (i, field) { |
| 106 |
if ( 'undefined' === typeof (values_arr[field.name]) ) { |
| 107 |
values_arr[field.name] = field.value; |
| 108 |
} else { |
| 109 |
values_arr[field.name] += ' | ' + field.value; |
| 110 |
} |
| 111 |
} |
| 112 |
); |
| 113 |
|
| 114 |
$.ajax( |
| 115 |
{ |
| 116 |
url : wpbc_plugins_params.ajax_url, |
| 117 |
data : values_arr, |
| 118 |
type : "post", |
| 119 |
beforeSend: function () { |
| 120 |
form.find( "button.submit" ).addClass( |
| 121 |
"button-disabled button updating-message" |
| 122 |
); |
| 123 |
}, |
| 124 |
} |
| 125 |
).done( |
| 126 |
function () { |
| 127 |
window.location = form.find( "a.skip" ).attr( "href" ); |
| 128 |
} |
| 129 |
); |
| 130 |
}, |
| 131 |
}; |
| 132 |
|
| 133 |
wpbc_deactivation_feedback.init(); |
| 134 |
} |
| 135 |
); |
| 136 |
|