1// Move geolocation stuff to the end of the form 2var source = document.getElementById( 3 "formfield-form-widgets-IGeolocatable-geolocation" 4); 5if (source) { 6 document.getElementById("fieldset-default").appendChild(source); 7 8 // Insert button "search address" 9 // var tpl = _.template(LocationSearchTemplate)({_t: _t}); 10 let geoleaflet = $(".geolocation_wrapper.edit"); 11 // TODO Make coordinates button label translatable 12 let tpl = 13 '<button class="locationsearch btn btn-info">Search address on map</button>'; 14 geoleaflet.prepend(tpl); 15 16 $("button.locationsearch").on("click", function (e) { 17 e.preventDefault(); 18 var form = geoleaflet.closest("form"); 19 var title = $("input#form-widgets-IDublinCore-title", form).val(), 20 street = $( 21 "input#form-widgets-ILocationFinderBehavior-location_street_nr", 22 form 23 ).val(), 24 zip_code = $( 25 "input#form-widgets-ILocationFinderBehavior-location_postal_code", 26 form 27 ).val(), 28 city = $( 29 "input#form-widgets-ILocationFinderBehavior-location_city", 30 form 31 ).val(), 32 country = $( 33 "select#form-widgets-ILocationFinderBehavior-location_country option:selected", 34 form 35 ).text(); 36 37 let params = { 38 title: title, 39 street: street, 40 zip_code: zip_code, 41 city: city, 42 country: country, 43 }; 44 45 let plone_portal_url = $("body").attr("data-portal-url"); 46 var settings = { 47 url: 48 `${plone_portal_url}/@locationfinder-geolocationcoordinates` + 49 "?" + 50 new URLSearchParams(params), 51 method: "GET", 52 headers: { 53 Accept: "application/json", 54 }, 55 }; 56 57 $.ajax(settings).done(function (data) { 58 if (data.latitude && data.longitude) { 59 $("input.latitude", geoleaflet).val(data.latitude).trigger("change"); 60 $("input.longitude", geoleaflet).val(data.longitude).trigger("change"); 61 } else { 62 // TODO translate 63 window.alert("Address not found."); 64 } 65 }); 66 }); 67}
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.