PluginProbe
Booking Calendar / 11.8
Booking Calendar v11.8
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / includes / _feedback_deactivation / _src / feedback.js

feedback.js in Booking Calendar 11.8, at includes/_feedback_deactivation/_src/feedback.js

201 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 _that.set_more_details_state( jQuery( "form.wpbc_deactivate-feedback-form" ) );
62 }
63 );
64
65 $( '#wpbc_deactivate-feedback-popup-wrapper' ).on(
66 'input',
67 '.feedback-textarea',
68 function () {
69 if ( '' !== jQuery.trim( jQuery( this ).val() ) ) {
70 _that.clear_more_details_error( jQuery( this ).closest( 'form.wpbc_deactivate-feedback-form' ) );
71 }
72 }
73 );
74 },
75 set_more_details_state: function (form) {
76 var has_selected_reason = form.find( 'input[name="reason_slug"]:checked' ).length > 0;
77 var details_wrap = form.find( '.wpbc_deactivate-feedback-popup-form-more-details' );
78 var details_field = details_wrap.find( '.feedback-textarea' );
79
80 if ( has_selected_reason ) {
81 details_wrap.show();
82 details_field.prop( 'required', true );
83 form.find( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).hide();
84 } else {
85 details_wrap.hide();
86 details_field.prop( 'required', false ).val( '' );
87 form.find( '.wpbc_deactivate-feedback-popup-form-footer .skip' ).show();
88 this.clear_more_details_error( form );
89 }
90 },
91 clear_more_details_error: function (form) {
92 form.find( '.feedback-textarea' ).attr( 'aria-invalid', 'false' );
93 form.find( '.wpbc_deactivate-feedback-more-details-error' ).hide();
94 },
95 show_more_details_error: function (form, message) {
96 var details_field = form.find( '.feedback-textarea' );
97 form.find( '.wpbc_deactivate-feedback-more-details-error' ).text( message ).show();
98 details_field.attr( 'aria-invalid', 'true' ).trigger( 'focus' );
99 },
100 validate_more_details: function (form) {
101 var details_wrap = form.find( '.wpbc_deactivate-feedback-popup-form-more-details' );
102 var details_field = details_wrap.find( '.feedback-textarea' );
103 var message = (
104 'undefined' !== typeof wpbc_plugins_params &&
105 'undefined' !== typeof wpbc_plugins_params.more_details_required_text
106 ) ? wpbc_plugins_params.more_details_required_text : 'Please share more details before submitting.';
107
108 if ( details_wrap.is( ':visible' ) && '' === jQuery.trim( details_field.val() ) ) {
109 this.show_more_details_error( form, message );
110 return false;
111 }
112
113 this.clear_more_details_error( form );
114 return true;
115 },
116 enable_submit: function (form) {
117 form.find( "button.submit" ).removeClass( "button-disabled button updating-message" );
118 },
119 send_data: function (form) {
120 var reason_slug = form.find( 'input[name="reason_slug"]:checked' ).map(
121 function () {
122 return jQuery( this ).val();
123 }
124 ).get().join( ' | ' );
125
126 if ( 0 === jQuery( "form.wpbc_deactivate-feedback-form" ).find( 'input[name="reason_slug"]:checked' ).length ) {
127 alert( "Please select at least one option from the list" );
128 return;
129 }
130
131 if ( ! this.validate_more_details( form ) ) {
132 return;
133 }
134
135 if ( form.find( "button.submit" ).hasClass( "button-disabled" ) ) {
136 return;
137 }
138
139 var reason_text = '';
140 var reason_text_el = form.find(
141 'input[name="reason_' + reason_slug + '"]'
142 );
143
144 if (reason_text_el.length > 0) {
145 reason_text = reason_text_el.val();
146 }
147
148 var data = {
149 reason_slug: "user_registration_deactivation_notice",
150 };
151
152 data["reason_" + reason_slug] = reason_text;
153
154 var values_arr = {};
155 jQuery.each(
156 form.serializeArray(),
157 function (i, field) {
158 if ( 'undefined' === typeof (values_arr[field.name]) ) {
159 values_arr[field.name] = field.value;
160 } else {
161 values_arr[field.name] += ' | ' + field.value;
162 }
163 }
164 );
165
166 $.ajax(
167 {
168 url : wpbc_plugins_params.ajax_url,
169 data : values_arr,
170 type : "post",
171 beforeSend: function () {
172 form.find( "button.submit" ).addClass(
173 "button-disabled button updating-message"
174 );
175 },
176 }
177 ).done(
178 function (response) {
179 if ( response && response.success ) {
180 window.location = form.find( "a.skip" ).attr( "href" );
181 return;
182 }
183
184 _that.enable_submit( form );
185 _that.show_more_details_error(
186 form,
187 response && response.data && response.data.message ? response.data.message : 'Please share more details before submitting.'
188 );
189 }
190 ).fail(
191 function () {
192 _that.enable_submit( form );
193 }
194 );
195 },
196 };
197
198 wpbc_deactivation_feedback.init();
199 }
200 );
201