| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- class AddressMap {
- constructor(map) {
- this.element = map;
- this.$latitude = $("input[name=latitude]");
- this.$longitude = $("input[name=longitude]");
- this.map = new google.maps.Map(this.element, {
- center: this.latLng,
- zoom: 17
- });
- this.marker = new google.maps.Marker({
- map: this.map,
- position: this.latLng,
- draggable: true
- });
- this.marker.addListener("dragend", () => {
- const latLng = this.marker.getPosition();
- this.$latitude.val(latLng.lat());
- this.$longitude.val(latLng.lng());
- });
- this.geocoder = new google.maps.Geocoder();
- $("#plot-button").on("click", () => this.plot());
- }
- get latLng() {
- const latitude = this.$latitude.val() * 1;
- const longitude = this.$longitude.val() * 1;
- return {
- lat: latitude,
- lng: longitude
- };
- }
- plot() {
- const addressParts = [
- $("#address-1").val(),
- $("#address-2").val(),
- $("#city").val(),
- $("#county").val(),
- $("#postal-code").val(),
- $("#country").val(),
- ];
- const address = addressParts.filter(value => value.length > 0).join(", ");
- this.geocoder.geocode({
- address
- }, (results, status) => {
- if(status === "OK") {
- const { location } = results[0].geometry;
- this.map.setCenter(location);
- this.marker.setPosition(location);
- this.$latitude.val(location.lat);
- this.$longitude.val(location.lng);
- }
- else {
- alert("Could not plot for address: " + address);
- }
- });
- }
- }
- const DocumentTypes = Object.freeze({
- SalesOrder: 0,
- DeliveryNote: 1,
- GoodsIn: 2,
- AdvancedReplacementUnit: 3,
- CreditNote: 4,
- });
- $(() => {
- const addressMap = document.querySelector("#address-map");
- if(addressMap) {
- new AddressMap(addressMap);
- }
- toastr.options.positionClass = "toast-bottom-right";
- $(window).on("keyup", event => {
- if(event.ctrlKey && event.key === "/") {
- $("#header-search").trigger("focus");
- }
- });
- $(document).on("select2:open", () => {
- document.querySelector(".select2-container--open .select2-search__field").focus()
- });
- const autoClickTarget = $("#auto-click-target").val();
- if(autoClickTarget) {
- setTimeout(() => {
- $(autoClickTarget).trigger("click");
- }, 500);
- }
- });
|