1(function ($) { 2 3 var Details = function ($container, options) { 4 var obj = this; 5 jQuery.extend(obj.options, options); 6 let $form = $('.bookly-js-staff-details', $container), 7 $staff_full_name = $('#bookly-full-name', $container), 8 $staff_wp_user = $('#bookly-wp-user', $container), 9 $staff_email = $('#bookly-email', $container), 10 $staff_phone = $('#bookly-phone', $container), 11 $staff_locations = $('#bookly-js-locations', $container), 12 $staff_gateways_list = $('#bookly-js-gateways-list', $form), 13 $staff_gateways = $('#bookly-gateways', $container), 14 $staff_color = $('.bookly-js-color-picker', $container); 15 16 if (obj.options.intlTelInput.enabled) { 17 window.booklyIntlTelInput($staff_phone.get(0), { 18 preferredCountries: [obj.options.intlTelInput.country], 19 initialCountry: obj.options.intlTelInput.country, 20 geoIpLookup: function (callback) { 21 $.get('https://ipinfo.io', function () { 22 }, 'jsonp').always(function (resp) { 23 var countryCode = (resp && resp.country) ? resp.country : ''; 24 callback(countryCode); 25 }); 26 } 27 }); 28 } 29 30 $staff_wp_user.on('change', function () { 31 if (this.value && this.value !== 'create') { 32 $staff_full_name.val($staff_wp_user.find(':selected').text()); 33 $staff_email.val($staff_wp_user.find(':selected').data('email')); 34 } 35 }); 36 if ($staff_color.length) { 37 $staff_color.wpColorPicker(); 38 } 39 40 $staff_locations.booklyDropdown(); 41 $staff_gateways_list.booklyDropdown(); 42 43 $container 44 .on('click', '.bookly-thumb label', function (e) { 45 e.preventDefault(); 46 e.stopPropagation(); 47 var frame = wp.media({ 48 library: {type: 'image'}, 49 multiple: false 50 }); 51 frame 52 .on('select', function () { 53 var selection = frame.state().get('selection').toJSON(), 54 img_src; 55 if (selection.length) { 56 if (selection[0].sizes['thumbnail'] !== undefined) { 57 img_src = selection[0].sizes['thumbnail'].url; 58 } else { 59 img_src = selection[0].url; 60 } 61 $('[name=attachment_id]', $form).val(selection[0].id).trigger('change'); 62 $('#bookly-js-staff-avatar', $form).find('.bookly-js-image').css({ 63 'background-image': 'url(' + img_src + ')', 64 'background-size': 'cover' 65 }); 66 $('.bookly-thumb-delete', $form).show(); 67 $('.bookly-thumb', $form).addClass('bookly-thumb-with-image'); 68 $(this).hide(); 69 } 70 }); 71 72 frame.open(); 73 $(document).off('focusin.modal'); 74 }) 75 // Delete staff avatar 76 .on('click', '.bookly-thumb-delete', function () { 77 var $thumb = $(this).parents('.bookly-js-image'); 78 $thumb.attr('style', ''); 79 $('[name=attachment_id]', $form).val('').trigger('change'); 80 $('.bookly-thumb', $form).removeClass('bookly-thumb-with-image'); 81 $('.bookly-thumb-delete', $form).hide(); 82 }) 83 // Save staff member details. 84 .on('click', '#bookly-details-save', function (e) { 85 e.preventDefault(); 86 let ladda = Ladda.create(this), 87 data = booklySerialize.form($form), 88 $staff_phone = $('#bookly-phone', $form); 89 ladda.start(); 90 // for BooklyPro listener in archive.js 91 // When button disabled, listeners don't process 92 $(this).removeAttr('disabled'); 93 94 data.phone = obj.options.intlTelInput.enabled ? booklyGetPhoneNumber($staff_phone.get(0)) : $staff_phone.val(); 95 $.ajax({ 96 type: 'POST', 97 url: ajaxurl, 98 data: booklySerialize.buildRequestData('bookly_update_staff', data), 99 dataType: 'json', 100 xhrFields: {withCredentials: true}, 101 crossDomain: 'withCredentials' in new XMLHttpRequest(), 102 success: function (response) { 103 if (response.success) { 104 obj.options.saving({success: [obj.options.l10n.saved]}, response.data.staff); 105 106 $('.bookly-js-staff-name').text($('#bookly-full-name', $form).val()); 107 } else { 108 obj.options.validation(true, response.data.error); 109 } 110 ladda.stop(); 111 } 112 }); 113 }) 114 .on('click', 'button:reset', function () { 115 setTimeout(function () { 116 $staff_locations.booklyDropdown('reset'); 117 $staff_gateways_list.booklyDropdown('reset'); 118 }, 0); 119 }) 120 .on('input', '#bookly-email', function () { 121 obj.options.validation(this.value == '', ''); 122 }) 123 .on('input', '#bookly-full-name', function () { 124 obj.options.validation(this.value == '', ''); 125 }) 126 .on('change', '[name="gateways"]', function () { 127 if (this.value == 'default') { 128 $staff_gateways_list.closest('.form-group').hide(); 129 } else { 130 $staff_gateways_list.closest('.form-group').show(); 131 } 132 }); 133 $('[name="gateways"]:checked', $form).trigger('change'); 134 }; 135 136 Details.prototype.options = { 137 intlTelInput: {}, 138 l10n: {}, 139 validation: function (has_error, info) { 140 $(document.body).trigger('staff.validation', ['staff-details', has_error, info]); 141 }, 142 saving: function (alerts, data) { 143 $(document.body).trigger('staff.saving', [alerts]); 144 if (alerts.hasOwnProperty('success')) { 145 $(document.body).trigger('staff.saved', ['staff-details', data]); 146 } 147 } 148 }; 149 150 window.BooklyStaffDetails = Details; 151})(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.