1jQuery( document ).ready(function($) { 2 const overlay = jQuery('<div id="gfb-cal-top-overlay"> </div>'); 3 const overlay_inside = jQuery('<div id="gfb-cal-overlay"> </div>'); 4 5 $(document).on('click', '#gfb-fancy-calendar a.gfb-month-changer', function(e) { 6 e.preventDefault(); 7 8 var is_admin = 'false'; 9 var location_id = ''; 10 var service_id = ''; 11 var staff_id = ''; 12 var form_id = ''; 13 var month = $(this).data('month'); 14 var prior_months = gfb_calendar.prior_months; 15 16 if ( $('body').hasClass('gravity-booking_page_gfb-calendar') ) { 17 is_admin = '1'; 18 } 19 20 if ( $('.gfb_location').length > 0 ) { 21 location_id = $('.gfb_location').val(); 22 } 23 24 if ( $('.gfb_service').length > 0 ) { 25 service_id = $('.gfb_service').val(); 26 } 27 28 if ( $('.gfb_staff').length > 0 ) { 29 staff_id = $('.gfb_staff').val(); 30 } 31 32 if ( $('.gfb_form_id').length > 0 ) { 33 form_id = $('.gfb_form_id').val(); 34 } 35 36 37 var data = { 38 action: 'gfb_month_changer', 39 nonce: gfb_calendar.nonce, 40 date: month, 41 is_admin: is_admin, 42 location_id: location_id, 43 service_id: service_id, 44 staff_id: staff_id, 45 form_id: form_id, 46 prior_months: prior_months 47 } 48 49 $.ajax({ 50 url: gfb_calendar.ajaxurl, 51 async: true, 52 type: 'POST', 53 data:data, 54 dataType: 'HTML', 55 beforeSend: function() { 56 overlay.appendTo(document.body); 57 overlay_inside.appendTo('div.gfb-cal-container'); 58 }, 59 success: function(response) { 60 $('#gfb-fancy-calendar').html(response); 61 }, 62 error: function(jqXHR, status, error) { 63 if (jqXHR.status == 500) { 64 alert('Internal error: ' + jqXHR.responseText); 65 } else { 66 alert('Unexpected error.'); 67 } 68 }, 69 complete: function() { 70 overlay.remove(); 71 overlay_inside.remove(); 72 gfb_selected_dates(); 73 // gfb_disabled_booked_days(staff_id); 74 } 75 }); 76 }); 77 78 function gfb_selected_dates() { 79 var selected_bookings = $('#gfb_selected_bookings'); 80 selected_bookings.find('.gfb_selected_booking').each(function(){ 81 var date = $(this).find('.gfb_selected_dates').val(); 82 var parent_td = $(`input.gfb-hdn[value="${date}"]`).parent('td'); 83 $(parent_td).addClass('gfb-selected'); 84 }); 85 } 86 87 function gfb_disabled_booked_days(staff_id) { 88 $('#gfb-fancy-calendar tbody tr td.gfb-available').each(function(i, v) { 89 var This = $(this); 90 var d = $(This).find('input[type="hidden"].gfb-hdn').val(); 91 var data = { 92 action: 'gfb_check_booked_slots_per_day', 93 nonce: gfb_calendar.nonce, 94 date: d, 95 staff_id: staff_id 96 }; 97 $.post(gfb_calendar.ajaxurl, data, function( success ) { 98 if ( !success ) { 99 $(This).removeClass('gfb-available').addClass('gfb-not-available'); 100 $(This).find('input[type="hidden"].gfb-hdn').remove(); 101 } 102 }); 103 }); 104 } 105 106 $(document).on('click', 'ul.gfb-slot-list > li:not(.gfb-unavailable) > span', function() { 107 108 var form_id = ''; 109 110 if ( $('.gfb_form_id').length > 0 ) { 111 form_id = $('.gfb_form_id').val(); 112 } 113 114 $('ul.gfb-slot-list > li > span').removeClass('gfb-selected'); 115 $('ul.gfb-slot-list > li > span ~ input.gfb-selected-capacity').removeClass('show'); 116 $('ul.gfb-slot-list > li > span ~ input.gfb-selected-capacity').attr('disabled', true); 117 $(this).parent('li').find('span').addClass('gfb-selected'); 118 if ( $(this).siblings('input.gfb-selected-capacity').length > 0 ) { 119 $(this).siblings('input.gfb-selected-capacity').addClass('show'); 120 $(this).siblings('input.gfb-selected-capacity').removeAttr('disabled'); 121 } 122 123 var time = ''; 124 if ( $(this).siblings('input.gfb-selected-time').length > 0 ) { 125 time = $(this).siblings('input.gfb-selected-time').val(); 126 } 127 128 var cost = 0.00; 129 if ( $(this).siblings('input.gfb-selected-price').length > 0 ) { 130 cost = $(this).siblings('input.gfb-selected-price').val(); 131 } 132 133 var capacity = ''; 134 if ( $(this).siblings('input.gfb-selected-capacity').length > 0 ) { 135 capacity = $(this).siblings('input.gfb-selected-capacity').val(); 136 cost = cost * capacity; 137 } 138 139 var date = ''; 140 if ( $(this).siblings('input.gfb-selected-date').length > 0 ) { 141 date = $(this).siblings('input.gfb-selected-date').val(); 142 } 143 144 $(`#gfb_date_${form_id}`).val(date); 145 $(`#gfb_time_${form_id}`).val(time); 146 $(`#gfb_slot_${form_id}`).val(capacity); 147 $(`#gfb_cost_${form_id}`).val(cost); 148 149 // Trigger gf total 150 if( typeof gformInitPriceFields == 'function' ) { 151 gformInitPriceFields($(`gform_${form_id}`)); // will trigger "gform_product_total" filter 152 } 153 154 }); 155 156 /** 157 * Process Appointment Tax 158 */ 159 if( typeof gformInitPriceFields == 'function' ) { 160 gform.addFilter( 'gform_product_total', function( total, formId ) { 161 162 var costField = $('.gfb_cost_input'); 163 164 if ( $('.gfb_cost_input').length > 0 && $('.gfb_cost_input').val() >= 0 ) { 165 var cost = $('.gfb_cost_input').val(); 166 // Cost Fields 167 total += Math.max( 0, parseFloat( cost ) ); 168 169 if ( jQuery( '#gf_total_no_discount_' + formId ).length > 0 ) { 170 jQuery( '#gf_total_no_discount_' + formId ).val( total ); 171 window['new_total_' + formId] = total; 172 } 173 174 if ( $('.gfb_cost_input').length > 0 ) { 175 $('.gfb_cost_input').val(cost); 176 } 177 178 return total; 179 } 180 181 if ( jQuery( '#gf_total_no_discount_' + formId ).length > 0 ) { 182 jQuery( '#gf_total_no_discount_' + formId ).val( total ); 183 window['new_total_' + formId] = total; 184 } 185 186 return total; 187 }, 40 ); //coupons applied at 50 188 } 189
190 $(document).on('keyup copy paste', '.gfb-selected-capacity', function() { 191 $(this).parent('li').find('span.gfb-selected').trigger('click'); 192 }); 193 194 $(document).on('click', '.gfb_delete_booking', function() { 195 var form_id = $(this).parents('form').find('.gfb_form_id').val(); 196 var date = $(this).data('date'); 197 var price = $(this).data('price'); 198 var parent_td = $(`input.gfb-hdn[value="${date}"]`).parent('td'); 199 $(parent_td).removeClass('gfb-selected'); 200 $(this).parent('.gfb_selected_booking').remove(); 201 var qty = parseInt($(document).find('.gfb_selected_costs').length); 202 var total_cost = price * qty; 203 $(`#gfb_cost_${form_id}`).val(total_cost).trigger('change'); 204 // Trigger gf total 205 if( typeof gformInitPriceFields == 'function' ) { 206 gformInitPriceFields($(`gform_${form_id}`)); // will trigger "gform_product_total" filter 207 } 208 209 if ( $('#gfb_selected_bookings').find('.gfb_selected_booking').length <= 0 ) { 210 $(`#gfb_date_${form_id}`).val(0); 211 $(`#gfb_time_${form_id}`).val(0); 212 $(`#gfb_slot_${form_id}`).val(0); 213 $(`#gfb_cost_${form_id}`).val(0); 214 $(`#gfb_booking_type_${form_id}`).val(''); 215 } 216 }); 217 218 $(document).on('click', 'td.gfb-available:not(.gfb-selected)', function() { 219 var current = $(this); 220 var parent_row = $(this).parent('tr'); 221 var parent_table = $(this).parents('table.gfb-cal-table'); 222 var selected_dates_cont = $('#gfb_selected_bookings'); 223 $('table.gfb-cal-table td').removeClass('gfb-caret-down'); 224 225 //conitnue from here on 26 June 2023 226 if ( ! ($(this).find('input[data-multiple="enabled"]').length > 0) ) { 227 $('table.gfb-cal-table td').removeClass('gfb-selected'); 228 } 229 230 $(this).addClass('gfb-selected'); 231 232 var location_id = ''; 233 var service_id = ''; 234 var staff_id = ''; 235 var form_id = ''; 236 var total_cost = 0; 237 var date = $(this).find('.gfb-hdn').val(); 238 239 if ( $('.gfb_location').length > 0 ) { 240 location_id = $('.gfb_location').val(); 241 } 242 243 if ( $('.gfb_service').length > 0 ) { 244 service_id = $('.gfb_service').val(); 245 } 246 247 if ( $('.gfb_staff').length > 0 ) { 248 staff_id = $('.gfb_staff').val(); 249 } 250 251 if ( $('.gfb_form_id').length > 0 ) { 252 form_id = $('.gfb_form_id').val(); 253 } 254 255 $(`#gfb_date_${form_id}`).val(0); 256 $(`#gfb_time_${form_id}`).val(0); 257 $(`#gfb_slot_${form_id}`).val(0); 258 $(`#gfb_cost_${form_id}`).val(0); 259 $(`#gfb_booking_type_${form_id}`).val(''); 260 // if ( $(`#gfb_booking_type_${form_id}`).length > 0 ) { 261 // $(`#gfb_booking_type_${form_id}`).remove(); 262 // } 263 264 //alert(date); 265 var data = { 266 action: 'gfb_show_slots_by_date', 267 nonce: gfb_calendar.nonce, 268 date: date, 269 location_id: location_id, 270 service_id: service_id, 271 staff_id: staff_id, 272 form_id: form_id 273 } 274 275 $.ajax({ 276 url: gfb_calendar.ajaxurl, 277 type: 'POST', 278 data:data, 279 dataType: 'HTML', 280 beforeSend: function() { 281 overlay.appendTo(document.body); 282 overlay_inside.appendTo('div.gfb-cal-container'); 283 $('#gfb-timeslots-table-container-tr').remove(); 284 $('#gfb-timeslots-table-container').remove(); 285 }, 286 success: function(response) { 287 var is_json = true; 288 289 try { 290 var obj = $.parseJSON(response); 291 //console.log(obj); 292 } catch(err) { 293 is_json = false; 294 } 295 //debugger; 296 //console.log(response); 297 if ( is_json && 'fullday' == obj.booking_type ) { //if booking type is full day 298 // debugger; 299 var multiple = false; 300 if ( obj.multiple_booking ) { 301 multiple = true; 302 } 303 304 if ( multiple ) { 305 if ( $(current).find('input[data-multiple="enabled"]').length > 0 ) { 306 $(selected_dates_cont) 307 .append(` 308 <div class="gfb_selected_booking" style=""> 309 <div class="gfb_delete_booking" data-date="${obj.date}" data-price="${obj.service_price}"> 310 <i class="fa fa-times-circle"></i> 311 </div> 312 <input type="hidden" class="gfb_selected_dates" name="gfb_selected_dates[]" value="${obj.date}" /> 313 <input type="hidden" class="gfb_selected_costs" name="gfb_selected_cost[]" value="${obj.service_price}" /> 314 ${obj.front_formated_date} 315 </div> 316 `); 317 } 318 319 var qty = parseInt($(document).find('.gfb_selected_costs').length); 320 total_cost = obj.service_price * qty; 321 322 $(`#gfb_date_${form_id}`).val(obj.date).trigger('change'); 323 $(`#gfb_time_${form_id}`).val(obj.time).trigger('change'); 324 $(`#gfb_slot_${form_id}`).val(qty).trigger('change'); 325 $(`#gfb_booking_type_${form_id}`).val(obj.booking_type); 326 } else { 327 328 total_cost = obj.service_price; 329 330 $(`#gfb_date_${form_id}`).val(obj.date).trigger('change'); 331 $(`#gfb_time_${form_id}`).val(obj.time).trigger('change'); 332 $(`#gfb_slot_${form_id}`).val(1).trigger('change'); 333 $(`#gfb_booking_type_${form_id}`).val(obj.booking_type); 334 } 335 336 if ( '' == obj.html ) { 337 $(`#gfb_cost_${form_id}`).val(total_cost).trigger('change'); 338 // Trigger gf total 339 if( typeof gformInitPriceFields == 'function' ) { 340 gformInitPriceFields($(`gform_${form_id}`)); // will trigger "gform_product_total" filter 341 } 342 } else { 343 if ( 'right' == gfb_calendar.show_timeslot && ! (window.matchMedia("(max-width: 575px)").matches) ) { 344 $(`<div id="gfb-timeslots-table-container">${obj.html}</div>`).insertAfter(parent_table); 345 } else { 346 $(current).addClass('gfb-caret-down'); 347 $(`<tr id="gfb-timeslots-table-container-tr"><td colspan="7">${obj.html}</td></tr>`).insertAfter(parent_row); 348 } 349 } 350 } else { //if booking type is custom 351 if ( 'right' == gfb_calendar.show_timeslot && ! (window.matchMedia("(max-width: 575px)").matches) ) { 352 $(`<div id="gfb-timeslots-table-container">${response}</div>`).insertAfter(parent_table); 353 } else { 354 $(current).addClass('gfb-caret-down'); 355 $(`<tr id="gfb-timeslots-table-container-tr"><td colspan="7">${response}</td></tr>`).insertAfter(parent_row); 356 } 357 } 358 }, 359 error: function(jqXHR, status, error) { 360 if (jqXHR.status == 500) { 361 alert('Internal error: ' + jqXHR.responseText); 362 } else { 363 alert('Unexpected error.'); 364 } 365 },
366 complete: function() { 367 overlay.remove(); 368 overlay_inside.remove(); 369 } 370 }); 371 }); 372 373 374});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.