1/** 2 * Thank-you page: nearest points list + map fallback for Blocks checkout + JS map button mode. 3 * 4 * Loaded only when front.js and inpost-pl.js are both skipped (see EasyPack::enqueue_typ_related_points_script). 5 */ 6(function ($) { 7 'use strict'; 8 9 var inpostjsGeowidgetModalTyp; 10 var inpost_pl_is_ajax_get_point_running = false; 11 12 function inpost_pl_typ_get_config() { 13 return window.easypack_typ_map || {}; 14 } 15 16 function inpost_pl_typ_update_locker(orderId, orderKey, lockerId, lockerDesc, onComplete) { 17 var cfg = inpost_pl_typ_get_config(); 18 19 $.ajax({ 20 type: 'POST', 21 url: cfg.ajaxurl, 22 data: { 23 action: 'update_locker_from_typ_page', 24 order_id: orderId, 25 order_key: orderKey || '', 26 inpost_pl_locker: lockerId, 27 inpost_pl_locker_desc: lockerDesc, 28 security: cfg.security, 29 }, 30 dataType: 'json', 31 beforeSend: function () { 32 inpost_pl_is_ajax_get_point_running = true; 33 $('.inpost_pl_geowidget_related_preloader').css('display', 'flex'); 34 $('.inpost_pl_locker_changed').remove(); 35 $('.inpost-pl-related-point-btn').css('background', '#fff'); 36 }, 37 success: function (data) { 38 var message; 39 var isSuccess = data && data.success; 40 41 if (isSuccess) { 42 message = '<div class="inpost_pl_locker_changed" style="color:#26be22; font-weight: bold">' + 43 cfg.updated_text + ': ' + lockerId + '</div>'; 44 } else { 45 message = '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + 46 cfg.error_text + '</div>'; 47 } 48 49 $('#inpost-pl-typ-map-data').before(message); 50 51 if (typeof onComplete === 'function') { 52 onComplete(isSuccess); 53 } 54 }, 55 error: function () { 56 $('#inpost-pl-typ-map-data').before( 57 '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + 58 cfg.error_text + '</div>' 59 ); 60 if (typeof onComplete === 'function') { 61 onComplete(false); 62 } 63 }, 64 complete: function () { 65 inpost_pl_is_ajax_get_point_running = false; 66 $('.inpost-pl-typ-preloader').remove(); 67 $('.inpost_pl_geowidget_related_preloader').css('display', 'none'); 68 }, 69 }); 70 } 71 72 window.inpost_pl_typ_select_point_callback = function (point) { 73 var cfg = inpost_pl_typ_get_config(); 74 var pointName = ''; 75 var parcelMachineAddressDesc = ''; 76 var addressLine1 = ''; 77 var addressLine2 = ''; 78 79 if (!point) { 80 return; 81 } 82 83 if ('name' in point) { 84 pointName = point.name; 85 if (pointName.indexOf('PL_') === 0) { 86 pointName = pointName.slice(3); 87 } 88 } 89 90 if (typeof point.location_description !== 'undefined' && point.location_description !== null) { 91 parcelMachineAddressDesc = point.location_description; 92 } 93 if (typeof point.address.line1 !== 'undefined' && point.address.line1 !== null) { 94 addressLine1 = point.address.line1; 95 } 96 if (typeof point.address.line2 !== 'undefined' && point.address.line2 !== null) { 97 addressLine2 = point.address.line2; 98 } 99 100 if ($('#selected-parcel-locker-pl-id').length) { 101 $('#selected-parcel-locker-pl-id').html(pointName); 102 $('#selected-parcel-machine-desc').html(addressLine1 + '<br>' + addressLine2); 103 $('.hidden-inpost-pl-typ-data').css('display', 'block'); 104 } 105 106 if (inpostjsGeowidgetModalTyp) { 107 inpostjsGeowidgetModalTyp.close(); 108 } 109 110 var typMapData = $('#inpost-pl-typ-map-data'); 111 if (!typMapData.length) { 112 return; 113 } 114 115 var lockerDesc = parcelMachineAddressDesc || (addressLine1 + ' ' + addressLine2).trim(); 116 117 inpost_pl_typ_update_locker( 118 typMapData.attr('data-id'), 119 '', 120 pointName, 121 lockerDesc 122 ); 123 }; 124 125 function inpost_pl_typ_init_geowidget() { 126 var typButton = document.querySelector('.inpost_pl_geowidget_typ'); 127 var cfg = inpost_pl_typ_get_config(); 128 129 if (!typButton || typeof jBox === 'undefined' || !cfg.geowidget_v5_token) { 130 return; 131 } 132 133 var wH = $(window).height() - 80; 134 var mapContent = '<inpost-geowidget id="inpost-geowidget-typ" onpoint="inpost_pl_typ_select_point_callback" token="' + 135 cfg.geowidget_v5_token + '" language="pl" config="parcelCollect"></inpost-geowidget>'; 136 137 inpostjsGeowidgetModalTyp = new jBox( 138 'Modal', 139 window.EasypackGeowidgetModalA11y.getOptions( 140 { 141 width: 800, 142 height: wH, 143 attach: '#easypack_show_geowidget', 144 title: 'Wybierz paczkomat', 145 content: mapContent, 146 } 147 ) 148 ); 149 150 $(document.body).on('click', '.inpost_pl_geowidget_typ', function (e) { 151 e.preventDefault(); 152 if (inpostjsGeowidgetModalTyp && !inpostjsGeowidgetModalTyp.isOpen) { 153 inpostjsGeowidgetModalTyp.open(); 154 } 155 }); 156 } 157 158 function inpost_pl_typ_init_related_points() { 159 $(document.body).on('click', '.inpost-pl-related-point-btn', function (e) { 160 e.preventDefault(); 161 162 var $btn = $(this); 163 var cfg = inpost_pl_typ_get_config(); 164 var orderKey = ''; 165 166 if (inpost_pl_is_ajax_get_point_running) { 167 return false; 168 } 169 170 try { 171 orderKey = new URLSearchParams(window.location.search).get('key') || ''; 172 } catch (err) { 173 orderKey = ''; 174 } 175 176 $('.inpost-pl-related-point-btn').css('background', '#fff'); 177 178 $.ajax({
179 type: 'POST', 180 url: cfg.ajaxurl, 181 data: { 182 action: 'update_locker_from_typ_page', 183 order_id: $('#inpost-pl-related-data-order').val(), 184 order_key: orderKey, 185 inpost_pl_locker: $btn.attr('data-id'), 186 inpost_pl_locker_desc: $btn.attr('data-address-id'), 187 security: cfg.security, 188 }, 189 dataType: 'json', 190 beforeSend: function () { 191 inpost_pl_is_ajax_get_point_running = true; 192 $('.hidden-inpost-pl-typ-data').css('display', 'none'); 193 $btn.find('.inpost-pl-select-from-points-preloader').css('display', 'block'); 194 $('.inpost_pl_locker_changed').remove(); 195 }, 196 success: function (data) { 197 if (data && data.success) { 198 $btn.css('background', '#afeaad'); 199 $btn.find('.inpost-pl-related-locker-info').after( 200 '<div class="inpost_pl_locker_changed" style="color:#26be22; font-weight: bold">' + 201 cfg.updated_text + ': ' + $btn.attr('data-id') + '</div>' 202 ); 203 $('#inpost-pl-typ-map-data').before( 204 '<div class="inpost_pl_locker_changed" style="color:#26be22; font-weight: bold">' + 205 cfg.updated_text + ': ' + $btn.attr('data-id') + '</div>' 206 ); 207 } else { 208 $('#inpost-pl-typ-map-data').before( 209 '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + 210 cfg.error_text + '</div>' 211 ); 212 } 213 }, 214 error: function () { 215 $('#inpost-pl-typ-map-data').before( 216 '<div class="inpost_pl_locker_changed" style="color:#e03636; font-weight: bold">' + 217 cfg.error_text + '</div>' 218 ); 219 }, 220 complete: function () { 221 inpost_pl_is_ajax_get_point_running = false; 222 $btn.find('.inpost-pl-select-from-points-preloader').css('display', 'none'); 223 }, 224 }); 225 226 return false; 227 }); 228 } 229 230 $(function () { 231 if (!$('#inpost-pl-typ-map-data').length && !$('.inpost-pl-related-point-btn').length) { 232 return; 233 } 234 235 inpost_pl_typ_init_related_points(); 236 inpost_pl_typ_init_geowidget(); 237 }); 238}(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.