let infoWindow = false; let exportIds = []; let markerMap = {}; // noinspection JSUnusedGlobalSymbols function getMarkerKey(locationId) { return `marker-${locationId}`; } function initialiseLocations() { if(!infoWindow) { infoWindow = new google.maps.InfoWindow(); } $.get(`/api/customers/${customerId}/get-locations`, { id: $("#id").val(), internal_id: $("#internal-id").val(), name: $("#name").val(), legal_entity_name: $("#legal-entity-name").val(), brand_name: $("#brand-name").val(), region_name: $("#region-name").val(), area_manager_name: $("#area-manager-name").val(), operations_manager_name: $("#operations-manager-name").val(), gaming_manager_name: $("#gaming-manager-name").val(), senior_gaming_manager_name: $("#senior-gaming-manager-name").val(), include_archived: $("#include-archived").prop("checked") ? 1 : 0, include_closed: $("#include-closed").prop("checked") ? 1 : 0, filter: $("#filter").val(), min_date: $("#min-date").val(), max_date: $("#max-date").val(), }, function(response) { if(!response.success) return false; if(!response.locations) return false; let map = maps["map"]; let bounds = new google.maps.LatLngBounds; let locationCount = response.locations.length; const $markerCountSpan = $("#map-marker-count"); if(locationCount > 0) { $markerCountSpan.text(locationCount); } else { $markerCountSpan.text(""); } response.locations.forEach(location => { let position = { lat: location.latitude, lng: location.longitude }; let options = { map: map, position: position, title: location.name }; if(!location.icon) { options.icon = "/img/markers/building-red.png"; } else { options.icon = "/img/markers/" + location.icon; } bounds.extend(position); let key = getMarkerKey(location.id); let marker = new google.maps.Marker(options); marker.location = location; marker.originalIcon = options.icon; marker.addListener("click", function() { displayInfoWindow(this); }); markerMap[key] = marker; }); map.fitBounds(bounds); }); $(document).on("click", "a[data-export-location-id]", function(event) { event.preventDefault(); let locationId = parseInt($(event.currentTarget).attr("data-export-location-id")); let index = exportIds.indexOf(locationId); let key = getMarkerKey(locationId); let marker = markerMap[key]; if(index === -1) { exportIds.push(locationId); marker.setOptions({ icon: "/img/markers/building-green.png" }); } else { exportIds.splice(index, 1); marker.setOptions({ icon: marker.originalIcon }); } displayInfoWindow(marker); $createProjectButton.prop("disabled", (exportIds.length === 0)); $addLocationsToProjectButton.prop("disabled", (exportIds.length === 0)); }); $("#export-csv-button, #export-kml-button").on("click", function(event) { event.preventDefault(); const $form = $("#locations-export-form"); const action = $(event.currentTarget).attr("data-action"); $form.find("input[name='ids[]']").remove(); $form.find("input[name='action']").val(action); for(const i in exportIds) { if(!exportIds.hasOwnProperty(i)) continue; let locationId = exportIds[i]; $form.append(""); } $form.trigger("submit"); }); const $createProjectButton = $("#create-project-button"); $createProjectButton.on("click", function(event) { event.preventDefault(); if(exportIds.length === 0) return; const $form = $("#locations-create-project-form"); $form.find("input[name='location_ids']").remove(); $form.append(""); $form.trigger("submit"); }); const $addLocationsToProjectButton = $("#add-locations-to-project-button"); new AddLocationsToProjectModal(); $(".btn-map").on("click", event => { const locationId = $(event.currentTarget).data("location-id"); const key = getMarkerKey(locationId); const marker = markerMap[key]; const map = maps.map; const center = marker.getPosition(); map.setCenter(center); map.setZoom(14); displayInfoWindow(markerMap[key]); }); } function displayInfoWindow(marker) { const escapeText = (text) => { const span = document.createElement("span"); span.innerText = text; return span.innerHTML; }; const locationId = parseInt(marker.location.id); const index = exportIds.indexOf(locationId); const location = marker.location; const badges = []; const lines = []; if(location.doNotTest) { badges.push(`Do Not Test`); } if(location.archived) { badges.push(`Archived`); } if(location.closed) { badges.push(`Closed`); } lines.push({title: "Internal ID", text: location.internalId}); lines.push({title: "Location ID", text: location.id}); if(location.test) { lines.push({divider: true}); lines.push({title: "Test ID", html: `${location.test.id}`}); if(location.test.formattedStartDts) { lines.push({title: "Date/Time", text: location.test.formattedStartDts}); } if(location.test.tester) { const { id, name } = location.test.tester; lines.push({title: "Tester ID", text: id}); lines.push({title: "Tester Name", html: `${name}`}); } if(location.test.pastDue) { badges.push(`Past Due`); } if(location.test.formattedDueDts) { lines.push({title: "Due", text: location.test.formattedDueDts}); } if(location.test) { lines.push({title: "Result", text: location.test.resultText}); } } let linesHtml = ""; lines.forEach(line => { if(line.divider) { linesHtml += "