1(function($) 2{ 3 4 bookneticHooks.addAction('booking_panel_loaded', function ( booknetic ) 5 { 6 let booking_panel_js = booknetic.panel_js; 7 8 booking_panel_js.on('change', '.booknetic_day_of_week_checkbox', function () 9 { 10 var activeFirstDay = booking_panel_js.find(".booknetic_times_days_of_week_area .booknetic_active_day").attr('data-day'); 11 12 var dayNum = $(this).attr('id').replace('booknetic_day_of_week_checkbox_', ''), 13 dayDIv = booking_panel_js.find(".booknetic_times_days_of_week_area > [data-day='" + dayNum + "']"); 14 15 if( $(this).is(':checked') ) 16 { 17 dayDIv.removeClass('booknetic_hidden').hide().slideDown(200, function () 18 { 19 booknetic.handleScroll(); 20 }).addClass('booknetic_active_day'); 21 22 if( booknetic.dateBasedService ) 23 { 24 dayDIv.find('.booknetic_wd_input_time').append('<option>00:00</option>').val('00:00'); 25 } 26 } 27 else 28 { 29 dayDIv.slideUp(200, function () 30 { 31 booknetic.handleScroll(); 32 }).removeClass('booknetic_active_day'); 33 } 34 35 booking_panel_js.find(".booknetic_times_days_of_week_area .booknetic_active_day .booknetic_copy_time_to_all").fadeOut( activeFirstDay > dayNum ? 100 : 0 ); 36 booking_panel_js.find(".booknetic_times_days_of_week_area .booknetic_active_day .booknetic_copy_time_to_all:first").fadeIn( activeFirstDay > dayNum ? 100 : 0 ); 37 38 if( booking_panel_js.find('.booknetic_day_of_week_checkbox:checked').length > 0 && !booknetic.dateBasedService ) 39 { 40 booking_panel_js.find('.booknetic_times_days_of_week_area').slideDown(200); 41 } 42 else 43 { 44 booking_panel_js.find('.booknetic_times_days_of_week_area').slideUp(200); 45 } 46 47 booknetic.calcRecurringTimes(); 48 }).on('click', '.booknetic_date_edit_btn', function() 49 { 50 if( $(this).attr('data-type') === '1') 51 { 52 let date_format = $(this).attr('data-date-format'); 53 let date = $(this).attr('data-date'); 54 let _this = $(this); 55 let textElement = $(this).closest('tr').find('td:eq(1) span.date_text'); 56 let input = $(this).closest('tr').find('td:eq(1) .booknetic_recurring_info_edit_date'); 57 textElement.hide(); 58 let recurringStartDate = booknetic.convertDate(booknetic.cartArr[booknetic.cartCurrentIndex]['recurring_start_date'],'Y-m-d',date_format) 59 let recurringEndDate = booknetic.convertDate(booknetic.cartArr[booknetic.cartCurrentIndex]['recurring_end_date'],'Y-m-d',date_format) 60 61 input.flatpickr( 62 { 63 altInput: true, 64 altFormat: date_format, 65 dateFormat: date_format, 66 monthSelectorType: 'static', 67 locale: { 68 firstDayOfWeek: BookneticData.week_starts_on === 'sunday' ? 0 : 1 69 }, 70 minDate: recurringStartDate, 71 maxDate: recurringEndDate, 72 defaultDate: date, 73 onMonthChange : (selectedDates, dateStr, instance)=>{ 74 booknetic.loadAvailableDate(instance , booknetic.ajaxParameters() ); 75 }, 76 onOpen : (selectedDates, dateStr, instance)=>{ 77 booknetic.loadAvailableDate(instance , booknetic.ajaxParameters() ); 78 }, 79 onChange: function(selectedDates, dateStr, instance) { 80 _this.closest('tr').find('td:eq(1)').attr('data-date',booknetic.convertDate( 81 dateStr,date_format,'Y-m-d' 82 )); 83 textElement.text(dateStr); 84 textElement.show(); 85 _this.parent().find('.booknetic_recurring_info_edit_date').hide(); 86 _this.prev('.booknetic_data_has_error').remove(); 87 booknetic.stepManager.saveData(); 88 }, 89 } ); 90 return ; 91 } 92 var tr = $(this).closest('tr'), 93 timeTd = tr.children('td[data-time]'), 94 time = timeTd.data('time'), 95 date1 = tr.children('td[data-date]').data('date'); 96 97 timeTd.children('.booknetic_time_span').html('<select class="form-control booknetic_time_select"></select>').css({'float': 'right', 'margin-right': '25px', 'width': '120px'}).parent('td').css({'padding-top': '7px', 'padding-bottom': '14px'}); 98 99 booknetic.select2Ajax( timeTd.find('.booknetic_time_select'), 'get_available_times', function() 100 { 101 return booknetic.formDataToObject( booknetic.ajaxParameters({date: date1}) ); 102 }); 103 104 $(this).parent().prev().children('.booknetic_data_has_error').remove(); 105 $(this).remove(); 106 107 booknetic.handleScroll(); 108 109 }).on('click', '.booknetic_copy_time_to_all', function () 110 { 111 var time = $(this).closest('.booknetic_active_day').find('.booknetic_wd_input_time').select2('data')[0]; 112 113 if( time ) 114 { 115 var timeId = time['id'], 116 timeText = time['text']; 117 118 booking_panel_js.find(".booknetic_active_day:not(:first)").each(function () 119 { 120 $(this).find(".booknetic_wd_input_time").append( $('<option></option>').val( timeId ).text( timeText ) ).val( timeId ).trigger('change'); 121 }); 122 } 123 124 }).on('keyup', '#booknetic_recurring_times', function() 125 { 126 var serviceData = booknetic.serviceData; 127 128 if( !serviceData ) 129 return; 130 131 var repeatType = serviceData['repeat_type'],
132 start = booknetic.getSelected.recurringStartDate(), 133 times = $(this).val(); 134 135 if( start == '' || times == '' || times <= 0 ) 136 return; 137 138 var frequency = (repeatType == 'daily') ? booking_panel_js.find('#booknetic_daily_recurring_frequency').val() : 1; 139 140 if( !( frequency >= 1 ) ) 141 { 142 frequency = 1; 143 if( repeatType == 'daily' ) 144 { 145 booking_panel_js.find('#booknetic_daily_recurring_frequency').val('1'); 146 } 147 } 148 149 var activeDays = {}; 150 if( repeatType == 'weekly' ) 151 { 152 booking_panel_js.find(".booknetic_times_days_of_week_area > .booknetic_active_day").each(function() 153 { 154 activeDays[ $(this).data('day') ] = true; 155 }); 156 157 if( $.isEmptyObject( activeDays ) ) 158 { 159 return; 160 } 161 } 162 else if( repeatType == 'monthly' ) 163 { 164 var monthlyRecurringType = booking_panel_js.find("#booknetic_monthly_recurring_type").val(); 165 var monthlyDayOfWeek = booking_panel_js.find("#booknetic_monthly_recurring_day_of_week").val(); 166 167 var selectedDays = booking_panel_js.find("#booknetic_monthly_recurring_day_of_month").select2('val'); 168 169 if( monthlyRecurringType == 'specific_day'){ 170 monthlyDayOfWeek = ''; 171 }else { 172 selectedDays = []; 173 } 174 175 if( selectedDays ) 176 { 177 for( var i = 0; i < selectedDays.length; i++ ) 178 { 179 activeDays[ selectedDays[i] ] = true; 180 } 181 } 182 183 if( monthlyDayOfWeek.length > 0) 184 { 185 activeDays[ monthlyDayOfWeek ] = monthlyDayOfWeek; 186 } 187 } 188 189 var c_times = 0; 190 var cursor = booknetic.getDateWithUTC( start ); 191 192 while( (!$.isEmptyObject( activeDays ) || repeatType == 'daily') && c_times < times ) 193 { 194 var weekNum = cursor.getDay(); 195 var dayNumber = parseInt( cursor.getDate() ); 196 weekNum = weekNum > 0 ? weekNum : 7;
197 var dateFormat = cursor.getFullYear() + '-' + booknetic.zeroPad( cursor.getMonth() + 1 ) + '-' + booknetic.zeroPad( cursor.getDate() ); 198 199 if( repeatType == 'monthly' ) 200 { 201 if( ( monthlyRecurringType == 'specific_day' && typeof activeDays[ dayNumber ] != 'undefined' ) || booknetic.getMonthWeekInfo(cursor, monthlyRecurringType, monthlyDayOfWeek) ) 202 { 203 if 204 ( 205 // if is not off day for staff or service 206 !( typeof booknetic.globalTimesheet[ weekNum-1 ] != 'undefined' && booknetic.globalTimesheet[ weekNum-1 ]['day_off'] ) && 207 // if is not holiday for staff or service 208 typeof booknetic.globalDayOffs[ dateFormat ] == 'undefined' 209 ) 210 { 211 c_times++; 212 } 213 } 214 } 215 else if 216 ( 217 // if weekly repeat type then only selected days of week... 218 ( typeof activeDays[ weekNum ] != 'undefined' || repeatType == 'daily' ) && 219 // if is not off day for staff or service 220 !( typeof booknetic.globalTimesheet[ weekNum-1 ] != 'undefined' && booknetic.globalTimesheet[ weekNum-1 ]['day_off'] ) && 221 // if is not holiday for staff or service 222 typeof booknetic.globalDayOffs[ dateFormat ] == 'undefined' 223 ) 224 { 225 c_times++; 226 } 227 228 cursor = new Date( cursor.getTime() + 1000 * 24 * 3600 * frequency ); 229 } 230 231 cursor = new Date( cursor.getTime() - 1000 * 24 * 3600 * frequency ); 232 var end = cursor.getFullYear() + '-' + booknetic.zeroPad( cursor.getMonth() + 1 ) + '-' + booknetic.zeroPad( cursor.getDate() ); 233 234 if( !isNaN( cursor.getFullYear() ) ) 235 { 236 booking_panel_js.find('#booknetic_recurring_end').val( booknetic.convertDate( end, 'Y-m-d' ) ); 237 } 238 }).on('keyup', '#booknetic_daily_recurring_frequency', booknetic.calcRecurringTimes 239 ).on('change', '#booknetic_monthly_recurring_type, #booknetic_monthly_recurring_day_of_week, #booknetic_monthly_recurring_day_of_month', booknetic.calcRecurringTimes 240 ).on('change', '#booknetic_monthly_recurring_type', function () 241 { 242 if( $(this).val() == 'specific_day' ) 243 { 244 booking_panel_js.find("#booknetic_monthly_recurring_day_of_month").next('.select2').show(); 245 booking_panel_js.find("#booknetic_monthly_recurring_day_of_week").next('.select2').hide(); 246 } 247 else 248 { 249 booking_panel_js.find("#booknetic_monthly_recurring_day_of_month").next('.select2').hide(); 250 booking_panel_js.find("#booknetic_monthly_recurring_day_of_week").next('.select2').show(); 251 } 252 }).on('change', '#booknetic_recurring_start, #booknetic_recurring_end', function () 253 { 254 booknetic.calcRecurringTimes(); 255 256 const recurringProps = { 257 'recurring_start_date' : booknetic.getSelected.recurringStartDate(), 258 'recurring_end_date' : booknetic.getSelected.recurringEndDate(), 259 'recurring_times' : booknetic.getSelected.recurringTimesArr(), 260 'appointments' : booknetic.getSelected.recurringTimesArrFinish(), 261 } 262 263 if (recurringProps['recurring_start_date'] === '' || (!$('#booknetic_recurring_end').is(':disabled') && recurringProps['recurring_start_date'] === '')) { 264 return; 265 } 266 267 const params = booknetic.ajaxParameters(undefined, false); 268 const newCartArr = Object.assign({}, booknetic.cartArr); 269 270 newCartArr[ booknetic.cartCurrentIndex ] = { 271 ...newCartArr[ booknetic.cartCurrentIndex ], ...recurringProps 272 } 273 274 params.set('cart', JSON.stringify(newCartArr) ); 275 276 booknetic.ajax('get_day_offs', params , function( result ) 277 { 278 booknetic.globalDayOffs = result['day_offs']; 279 booknetic.globalTimesheet = result['timesheet']; 280 281 result['disabled_days_of_week'].forEach(function( value, key ) 282 { 283 booking_panel_js.find('#booknetic_day_of_week_checkbox_' + (parseInt(key)+1)).attr('disabled', value); 284 }); 285 286 booknetic.calcRecurringTimes(); 287 }); 288 }); 289 290 }); 291 292 bookneticHooks.addFilter('step_validation_recurring_info' , function ( result , booknetic ) 293 { 294 var dateEditPending = false;
295 var timeEditPending = false; 296 297 booknetic.panel_js.find("#booknetic_recurring_dates > tr").each(function() 298 { 299 var dateText = $(this).find('span.date_text'); 300 if( dateText.length && !dateText.is(':visible') ) 301 { 302 dateEditPending = true; 303 } 304 305 var timeSelect = $(this).find('.booknetic_time_select'); 306 if( timeSelect.length && !timeSelect.val() ) 307 { 308 timeEditPending = true; 309 } 310 }); 311 312 if( dateEditPending ) 313 { 314 return { 315 status: false, 316 errorMsg: booknetic.__('select_available_date') 317 }; 318 } 319 320 if( timeEditPending ) 321 { 322 return { 323 status: false, 324 errorMsg: booknetic.__('select_available_time') 325 }; 326 } 327 328 if( booknetic.getSelected.recurringTimesArrFinish() === false ) 329 { 330 return { 331 status: false, 332 errorMsg: booknetic.__('select_available_time') 333 }; 334 } 335 336 if( booknetic.getSelected.recurringDateValidate() === false) 337 { 338 return { 339 status: false, 340 errorMsg: booknetic.__('select_available_date') 341 }; 342 } 343 344 return result 345 }); 346 347 bookneticHooks.addAction('before_step_loading', function( booknetic, new_step_id, old_step_id ) 348 { 349 if( new_step_id !== 'recurring_info' ) 350 return; 351 352 booknetic.stepManager.loadStandartSteps( new_step_id, old_step_id ); 353 }); 354 355})(jQuery);
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.