| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- 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("<input type=\"hidden\" name=\"ids[]\" value=\"" + locationId + "\" />");
- }
- $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("<input type=\"hidden\" name=\"location_ids\" value=\"" + exportIds.join(", ") + "\" />");
- $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(`<span class="badge badge-warning">Do Not Test</span>`);
- }
- if(location.archived) {
- badges.push(`<span class="badge badge-secondary">Archived</span>`);
- }
- if(location.closed) {
- badges.push(`<span class="badge badge-danger">Closed</span>`);
- }
- 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: `<a href="/account/tests/${location.test.id}" target="_blank">${location.test.id}</a>`});
- 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: `<a href="/account/users/${id}" target="_blank">${name}</a>`});
- }
- if(location.test.pastDue) {
- badges.push(`<span class="badge badge-danger">Past Due</span>`);
- }
- 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 += "<hr />\n";
- }
- if(line.title) {
- const titleHtml = escapeText(line.title);
- let contentHtml = line.html;
- if(line.text) {
- contentHtml = escapeText(line.text);
- }
- linesHtml += `<div class="small"><strong>${titleHtml}:</strong> ${contentHtml}</div>`;
- }
- });
- let exportText = "Select";
- let exportClass = "btn-primary";
- if(index > -1) {
- exportText = "Deselect";
- exportClass = "btn-success";
- }
- const content = `<div class="container-fluid" style="font-size: 1rem; font-weight: normal; min-width: 16rem;">
- <div class="mb-1">
- ${marker.location.name}<br />
- ${badges.join(" ")}
- </div>
- <hr />
- ${linesHtml}
- <hr />
- <div class="form-row">
- <div class="col">
- <a class="btn btn-block ${exportClass}" href="#" data-export-location-id="${marker.location.id}">${exportText}</a>
- </div>
- <div class="col">
- <a class="btn btn-block btn-primary" href="/account/locations/${marker.location.id}" target="_blank">View</a>
- </div>
- </div>
- </div>`;
- infoWindow.setContent(content);
- infoWindow.open(map, marker);
- }
- class AddLocationsToProjectModal {
- constructor() {
- this.$modal = $("#add-locations-to-project-modal");
- this.$modal.on("show.bs.modal", event => this.onShow(event));
- this.$form = this.$modal.find("form");
- this.$form.on("submit", event => this.onSubmit(event));
- this.$projectDropdown = this.$form.find("[name=project_id]");
- }
- onShow() {
- this.$form.find(`input[name="location_ids[]"]`).remove();
- exportIds.forEach(locationId => {
- this.$form.append(`<input type="hidden" name="location_ids[]" value="${locationId}" />`);
- });
- }
- onSubmit(event) {
- event.preventDefault();
- const projectId = this.$projectDropdown.val();
- const data = this.$form.serialize();
- $.post(`/account/projects/${projectId}/add-locations`, data).then(response => {
- if(response.success) {
- if(response.dupeLocations.length > 0) {
- const locationNames = response.dupeLocations.map(location => location.name).join("\n");
- alert(`Locations added to project successfully. The following locations were skipped as there were already active tests:\n\n${locationNames}`);
- }
- else {
- alert("Locations added to project successfully.");
- }
- }
- this.$modal.modal("hide");
- }).catch(error => {
- alert(`An error has occurred: ${error}`);
- });
- }
- }
|