PluginProbe
Booking Calendar / 11.3
Booking Calendar v11.3
11.8.4 11.8.3 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 All 204 releases
booking / includes / page-bookings / _src / bookings__actions.js

bookings__actions.js in Booking Calendar 11.3, at includes/page-bookings/_src/bookings__actions.js

380 lines 15.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 /**
4 * Ajax ----------------------------------------------------------------------------------------------------- */
5 //var is_this_action = false;
6 /**
7 * Send Ajax action request, like approving or cancellation
8 *
9 * @param action_param
10 */
11 function wpbc_ajx_booking_ajax_action_request( action_param = {} ){
12
13 console.groupCollapsed( 'WPBC_AJX_BOOKING_ACTIONS' ); console.log( ' == Ajax Actions :: Params == ', action_param );
14 //is_this_action = true;
15
16 wpbc_admin_show_message_processing( '' );
17
18 wpbc_booking_listing_reload_button__spin_start();
19
20 // Get redefined Locale, if action on single booking !
21 if ( ( undefined != action_param[ 'booking_id' ] ) && ( ! Array.isArray( action_param[ 'booking_id' ] ) ) ){ // Not array
22
23 action_param[ 'locale' ] = wpbc_get_selected_locale( action_param[ 'booking_id' ], wpbc_ajx_booking_listing.get_secure_param( 'locale' ) );
24 }
25
26 var action_post_params = {
27 action : 'WPBC_AJX_BOOKING_ACTIONS',
28 nonce : wpbc_ajx_booking_listing.get_secure_param( 'nonce' ),
29 wpbc_ajx_user_id: ( ( undefined == action_param[ 'user_id' ] ) ? wpbc_ajx_booking_listing.get_secure_param( 'user_id' ) : action_param[ 'user_id' ] ),
30 wpbc_ajx_locale: ( ( undefined == action_param[ 'locale' ] ) ? wpbc_ajx_booking_listing.get_secure_param( 'locale' ) : action_param[ 'locale' ] ),
31
32 action_params : action_param
33 };
34
35 // It's required for CSV export - getting the same list of bookings
36 if ( typeof action_param.search_params !== 'undefined' ){
37 action_post_params[ 'search_params' ] = action_param.search_params;
38 delete action_post_params.action_params.search_params;
39 }
40
41 // Start Ajax
42 jQuery.post( wpbc_url_ajax ,
43
44 action_post_params ,
45
46 /**
47 * S u c c e s s
48 *
49 * @param response_data - its object returned from Ajax - class-live-searcg.php
50 * @param textStatus - 'success'
51 * @param jqXHR - Object
52 */
53 function ( response_data, textStatus, jqXHR ) {
54
55 console.log( ' == Ajax Actions :: Response WPBC_AJX_BOOKING_ACTIONS == ', response_data ); console.groupEnd();
56
57 // Probably Error
58 if ( (typeof response_data !== 'object') || (response_data === null) ){
59 jQuery( '.wpbc_ajx_under_toolbar_row' ).hide(); // FixIn: 9.6.1.5.
60 jQuery( wpbc_ajx_booking_listing.get_other_param( 'listing_container' ) ).html(
61 '<div class="wpbc-settings-notice notice-warning" style="text-align:left">' +
62 response_data +
63 '</div>'
64 );
65 return;
66 }
67
68 wpbc_booking_listing_reload_button__spin_pause();
69
70 wpbc_admin_show_message(
71 response_data[ 'ajx_after_action_message' ].replace( /\n/g, "<br />" )
72 , ( '1' == response_data[ 'ajx_after_action_result' ] ) ? 'success' : 'error'
73 , ( ( 'undefined' === typeof(response_data[ 'ajx_after_action_result_all_params_arr' ][ 'after_action_result_delay' ]) )
74 ? 10000
75 : response_data[ 'ajx_after_action_result_all_params_arr' ][ 'after_action_result_delay' ] )
76 );
77
78 // Success response
79 if ( '1' == response_data[ 'ajx_after_action_result' ] ){
80
81 var is_reload_ajax_listing = true;
82
83 // After Google Calendar import show imported bookings and reload the page for toolbar parameters update
84 if ( false !== response_data[ 'ajx_after_action_result_all_params_arr' ][ 'new_listing_params' ] ){
85
86 wpbc_ajx_booking_send_search_request_with_params( response_data[ 'ajx_after_action_result_all_params_arr' ][ 'new_listing_params' ] );
87
88 var closed_timer = setTimeout( function (){
89
90 if ( wpbc_booking_listing_reload_button__is_spin() ){
91 if ( undefined != response_data[ 'ajx_after_action_result_all_params_arr' ][ 'new_listing_params' ][ 'reload_url_params' ] ){
92 document.location.href = response_data[ 'ajx_after_action_result_all_params_arr' ][ 'new_listing_params' ][ 'reload_url_params' ];
93 } else {
94 document.location.reload();
95 }
96 }
97 }
98 , 2000 );
99 is_reload_ajax_listing = false;
100 }
101
102 // Start download exported CSV file
103 if ( undefined != response_data[ 'ajx_after_action_result_all_params_arr' ][ 'export_csv_url' ] ){
104 wpbc_ajx_booking__export_csv_url__download( response_data[ 'ajx_after_action_result_all_params_arr' ][ 'export_csv_url' ] );
105 is_reload_ajax_listing = false;
106 }
107
108 if ( is_reload_ajax_listing ){
109 wpbc_ajx_booking__actual_listing__show(); // Sending Ajax Request - with parameters that we early defined in "wpbc_ajx_booking_listing" Obj.
110 }
111
112 }
113
114 // Remove spin icon from button and Enable this button.
115 wpbc_button__remove_spin( response_data[ 'ajx_cleaned_params' ][ 'ui_clicked_element_id' ] )
116
117 // Hide modals
118 wpbc_popup_modals__hide();
119
120 jQuery( '#ajax_respond' ).html( response_data ); // For ability to show response, add such DIV element to page
121 }
122 ).fail( function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); }
123 jQuery( '.wpbc_ajx_under_toolbar_row' ).hide(); // FixIn: 9.6.1.5.
124 var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ;
125 if ( jqXHR.responseText ){
126 error_message += jqXHR.responseText;
127 }
128 error_message = error_message.replace( /\n/g, "<br />" );
129
130 wpbc_ajx_booking_show_message( error_message );
131 })
132 // .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } })
133 // .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } })
134 ; // End Ajax
135 }
136
137
138
139 /**
140 * Hide all open modal popups windows
141 */
142 function wpbc_popup_modals__hide(){
143
144 // Hide modals
145 if ( 'function' === typeof (jQuery( '.wpbc_popup_modal' ).wpbc_my_modal) ){
146 jQuery( '.wpbc_popup_modal' ).wpbc_my_modal( 'hide' );
147 }
148 }
149
150
151 /**
152 * Dates Short <-> Wide ----------------------------------------------------------------------------------- */
153
154 function wpbc_ajx_click_on_dates_short(){
155 jQuery( '#booking_dates_small,.booking_dates_full' ).hide();
156 jQuery( '#booking_dates_full,.booking_dates_small' ).show();
157 wpbc_ajx_booking_send_search_request_with_params( {'ui_usr__dates_short_wide': 'short'} );
158 }
159
160 function wpbc_ajx_click_on_dates_wide(){
161 jQuery( '#booking_dates_full,.booking_dates_small' ).hide();
162 jQuery( '#booking_dates_small,.booking_dates_full' ).show();
163 wpbc_ajx_booking_send_search_request_with_params( {'ui_usr__dates_short_wide': 'wide'} );
164 }
165
166 function wpbc_ajx_click_on_dates_toggle(this_date){
167
168 jQuery( this_date ).parents( '.wpbc_col_dates' ).find( '.booking_dates_small' ).toggle();
169 jQuery( this_date ).parents( '.wpbc_col_dates' ).find( '.booking_dates_full' ).toggle();
170
171 /*
172 var visible_section = jQuery( this_date ).parents( '.booking_dates_expand_section' );
173 visible_section.hide();
174 if ( visible_section.hasClass( 'booking_dates_full' ) ){
175 visible_section.parents( '.wpbc_col_dates' ).find( '.booking_dates_small' ).show();
176 } else {
177 visible_section.parents( '.wpbc_col_dates' ).find( '.booking_dates_full' ).show();
178 }*/
179 console.log( 'wpbc_ajx_click_on_dates_toggle', this_date );
180 }
181
182 /**
183 * Locale --------------------------------------------------------------------------------------------------- */
184
185 /**
186 * Select options in select boxes based on attribute "value_of_selected_option" and RED color and hint for LOCALE button -- It's called from wpbc_ajx_booking_define_ui_hooks() each time after Listing loading.
187 */
188 function wpbc_ajx_booking__ui_define__locale(){
189
190 jQuery( '.wpbc__list__table select' ).each( function ( index ){
191
192 var selection = jQuery( this ).attr( "value_of_selected_option" ); // Define selected select boxes
193
194 if ( undefined !== selection ){
195 jQuery( this ).find( 'option[value="' + selection + '"]' ).prop( 'selected', true );
196
197 if ( ('' != selection) && (jQuery( this ).hasClass( 'set_booking_locale_selectbox' )) ){ // Locale
198
199 var booking_locale_button = jQuery( this ).parents( '.ui_element_locale' ).find( '.set_booking_locale_button' )
200
201 //booking_locale_button.css( 'color', '#db4800' ); // Set button red
202 booking_locale_button.addClass( 'wpbc_ui_red' ); // Set button red
203 if ( 'function' === typeof( wpbc_tippy ) ){
204 booking_locale_button.get(0)._tippy.setContent( selection );
205 }
206 }
207 }
208 } );
209 }
210
211 /**
212 * Remark --------------------------------------------------------------------------------------------------- */
213
214 /**
215 * Define content of remark "booking note" button and textarea. -- It's called from wpbc_ajx_booking_define_ui_hooks() each time after Listing loading.
216 */
217 function wpbc_ajx_booking__ui_define__remark(){
218
219 jQuery( '.wpbc__list__table .ui_remark_section textarea' ).each( function ( index ){
220 var text_val = jQuery( this ).val();
221 if ( (undefined !== text_val) && ('' != text_val) ){
222
223 var remark_button = jQuery( this ).parents( '.ui_group' ).find( '.set_booking_note_button' );
224
225 if ( remark_button.length > 0 ){
226
227 remark_button.addClass( 'wpbc_ui_red' ); // Set button red
228 if ( 'function' === typeof (wpbc_tippy) ){
229 //remark_button.get( 0 )._tippy.allowHTML = true;
230 //remark_button.get( 0 )._tippy.setContent( text_val.replace(/[\n\r]/g, '<br>') );
231
232 remark_button.get( 0 )._tippy.setProps( {
233 allowHTML: true,
234 content : text_val.replace( /[\n\r]/g, '<br>' )
235 } );
236 }
237 }
238 }
239 } );
240 }
241
242
243
244
245 function wpbc_ajx_booking__ui_click_save__change_resource( this_el, booking_action, el_id ){
246
247 wpbc_ajx_booking_ajax_action_request( {
248 'booking_action' : booking_action,
249 'booking_id' : jQuery( '#change_booking_resource__booking_id' ).val(),
250 'selected_resource_id' : jQuery( '#change_booking_resource__resource_select' ).val(),
251 'ui_clicked_element_id': el_id
252 } );
253
254 wpbc_button_enable_loading_icon( this_el );
255
256
257 }
258
259
260
261 function wpbc_ajx_booking__ui_click_save__duplicate_booking( this_el, booking_action, el_id ){
262
263 wpbc_ajx_booking_ajax_action_request( {
264 'booking_action' : booking_action,
265 'booking_id' : jQuery( '#duplicate_booking_to_other_resource__booking_id' ).val(),
266 'selected_resource_id' : jQuery( '#duplicate_booking_to_other_resource__resource_select' ).val(),
267 'ui_clicked_element_id': el_id
268 } );
269
270 wpbc_button_enable_loading_icon( this_el );
271
272
273 }
274
275
276
277 //TODO: delete
278
279
280 /**
281 * Change booking cost -------------------------------------------------------------------------------------- */
282
283 function wpbc_ajx_booking__ui_click_save__set_booking_cost( booking_id, this_el, booking_action, el_id ){
284
285 wpbc_ajx_booking_ajax_action_request( {
286 'booking_action' : booking_action,
287 'booking_id' : booking_id,
288 'booking_cost' : jQuery( '#ui_btn_set_booking_cost' + booking_id + '_cost').val(),
289 'ui_clicked_element_id': el_id + '_save'
290 } );
291
292 wpbc_button_enable_loading_icon( this_el );
293
294 jQuery( '#' + el_id + '_cancel').hide();
295 //wpbc_button_enable_loading_icon( jQuery( '#' + el_id + '_cancel').get(0) );
296
297 }
298
299 function wpbc_ajx_booking__ui_click_close__set_booking_cost(){
300 // Hide all change payment status for booking
301 jQuery(".ui__set_booking_cost__section_in_booking").hide();
302 }
303
304
305 /**
306 * Send Payment request -------------------------------------------------------------------------------------- */
307
308 function wpbc_ajx_booking__ui_click__send_payment_request(){
309
310 wpbc_ajx_booking_ajax_action_request( {
311 'booking_action' : 'send_payment_request',
312 'booking_id' : jQuery( '#wpbc_modal__payment_request__booking_id').val(),
313 'reason_of_action' : jQuery( '#wpbc_modal__payment_request__reason_of_action').val(),
314 'ui_clicked_element_id': 'wpbc_modal__payment_request__button_send'
315 } );
316 wpbc_button_enable_loading_icon( jQuery( '#wpbc_modal__payment_request__button_send' ).get( 0 ) );
317 }
318
319
320 /**
321 * Import Google Calendar ------------------------------------------------------------------------------------ */
322
323 function wpbc_ajx_booking__ui_click__import_google_calendar(){
324
325 wpbc_ajx_booking_ajax_action_request( {
326 'booking_action' : 'import_google_calendar',
327 'ui_clicked_element_id': 'wpbc_modal__import_google_calendar__button_send'
328
329 , 'booking_gcal_events_from' : jQuery( '#wpbc_modal__import_google_calendar__section #booking_gcal_events_from option:selected').val()
330 , 'booking_gcal_events_from_offset' : jQuery( '#wpbc_modal__import_google_calendar__section #booking_gcal_events_from_offset' ).val()
331 , 'booking_gcal_events_from_offset_type' : jQuery( '#wpbc_modal__import_google_calendar__section #booking_gcal_events_from_offset_type option:selected').val()
332
333 , 'booking_gcal_events_until' : jQuery( '#wpbc_modal__import_google_calendar__section #booking_gcal_events_until option:selected').val()
334 , 'booking_gcal_events_until_offset' : jQuery( '#wpbc_modal__import_google_calendar__section #booking_gcal_events_until_offset' ).val()
335 , 'booking_gcal_events_until_offset_type' : jQuery( '#wpbc_modal__import_google_calendar__section #booking_gcal_events_until_offset_type option:selected').val()
336
337 , 'booking_gcal_events_max' : jQuery( '#wpbc_modal__import_google_calendar__section #booking_gcal_events_max' ).val()
338 , 'booking_gcal_resource' : jQuery( '#wpbc_modal__import_google_calendar__section #wpbc_booking_resource option:selected').val()
339 } );
340 wpbc_button_enable_loading_icon( jQuery( '#wpbc_modal__import_google_calendar__section #wpbc_modal__import_google_calendar__button_send' ).get( 0 ) );
341 }
342
343
344 /**
345 * Export bookings to CSV ------------------------------------------------------------------------------------ */
346 function wpbc_ajx_booking__ui_click__export_csv( params ){
347
348 var selected_booking_id_arr = wpbc_get_selected_row_id();
349
350 wpbc_ajx_booking_ajax_action_request( {
351 'booking_action' : params[ 'booking_action' ],
352 'ui_clicked_element_id' : params[ 'ui_clicked_element_id' ],
353
354 'export_type' : params[ 'export_type' ],
355 'csv_export_separator' : params[ 'csv_export_separator' ],
356 'csv_export_skip_fields': params[ 'csv_export_skip_fields' ],
357
358 'booking_id' : selected_booking_id_arr.join(','),
359 'search_params' : wpbc_ajx_booking_listing.search_get_all_params()
360 } );
361
362 var this_el = jQuery( '#' + params[ 'ui_clicked_element_id' ] ).get( 0 )
363
364 wpbc_button_enable_loading_icon( this_el );
365 }
366
367 /**
368 * Open URL in new tab - mainly it's used for open CSV link for downloaded exported bookings as CSV
369 *
370 * @param export_csv_url
371 */
372 function wpbc_ajx_booking__export_csv_url__download( export_csv_url ){
373
374 //var selected_booking_id_arr = wpbc_get_selected_row_id();
375
376 document.location.href = export_csv_url;// + '&selected_id=' + selected_booking_id_arr.join(',');
377
378 // It's open additional dialog for asking opening ulr in new tab
379 // window.open( export_csv_url, '_blank').focus();
380 }