|
|
@@ -1,7 +1,8 @@
|
|
|
-var infoWindow = false;
|
|
|
-var exportIds = [];
|
|
|
-var markerMap = {};
|
|
|
+let infoWindow = false;
|
|
|
+let exportIds = [];
|
|
|
+let markerMap = {};
|
|
|
|
|
|
+// noinspection JSUnusedGlobalSymbols
|
|
|
function initialiseLocations() {
|
|
|
|
|
|
if(!infoWindow) {
|
|
|
@@ -22,6 +23,8 @@ function initialiseLocations() {
|
|
|
|
|
|
for(let i in response.locations) {
|
|
|
|
|
|
+ if(!response.locations.hasOwnProperty(i)) continue;
|
|
|
+
|
|
|
let location = response.locations[i];
|
|
|
let position = {
|
|
|
lat: location.latitude,
|
|
|
@@ -32,7 +35,7 @@ function initialiseLocations() {
|
|
|
map: map,
|
|
|
position: position,
|
|
|
title: location.name
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
if(location.icon) {
|
|
|
options.icon = "/img/markers/building-red.png";
|
|
|
@@ -59,12 +62,12 @@ function initialiseLocations() {
|
|
|
|
|
|
$(document).on("click", "a[data-export-location-id]", function(event) {
|
|
|
|
|
|
- let locationId = parseInt($(this).attr("data-export-location-id"));
|
|
|
+ let locationId = parseInt($(event.currentTarget).attr("data-export-location-id"));
|
|
|
let index = exportIds.indexOf(locationId);
|
|
|
let key = "marker-" + locationId;
|
|
|
let marker = markerMap[key];
|
|
|
|
|
|
- if(index == -1) {
|
|
|
+ if(index === -1) {
|
|
|
exportIds.push(locationId);
|
|
|
marker.setOptions({
|
|
|
icon: "/img/markers/building-green.png"
|
|
|
@@ -78,26 +81,42 @@ function initialiseLocations() {
|
|
|
}
|
|
|
|
|
|
displayInfoWindow(marker);
|
|
|
- });
|
|
|
|
|
|
- $("#export-csv-button, #export-kml-button").click(function(event) {
|
|
|
+ const method = (exportIds.length > 0) ? "removeClass" : "addClass";
|
|
|
|
|
|
- if(exportIds.length > 0) {
|
|
|
- event.preventDefault();
|
|
|
+ $("#location-actions")[method]("d-none");
|
|
|
|
|
|
- let action = $(this).attr("data-action");
|
|
|
+ });
|
|
|
|
|
|
- $("#locations-export-form input[name='ids[]']").remove();
|
|
|
- $("#locations-export-form input[name='action']").val(action);
|
|
|
+ $("#export-csv-button, #export-kml-button").on("click", function(event) {
|
|
|
|
|
|
- for(let i in exportIds) {
|
|
|
- let locationId = exportIds[i];
|
|
|
- $("#locations-export-form").append("<input type=\"hidden\" name=\"ids[]\" value=\"" + locationId + "\" />");
|
|
|
- }
|
|
|
+ event.preventDefault();
|
|
|
+ if(exportIds.length === 0) return;
|
|
|
+
|
|
|
+ const $form = $("#locations-export-form");
|
|
|
+ const action = $(event.currentTarget).attr("data-action");
|
|
|
|
|
|
- $("#locations-export-form").submit();
|
|
|
+ $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");
|
|
|
+ });
|
|
|
+
|
|
|
+ $("#create-project-button").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");
|
|
|
});
|
|
|
|
|
|
}
|
|
|
@@ -107,11 +126,11 @@ function displayInfoWindow(marker) {
|
|
|
let locationId = parseInt(marker.location.id);
|
|
|
let index = exportIds.indexOf(locationId);
|
|
|
|
|
|
- let exportText = "Select for Export";
|
|
|
+ let exportText = "Select";
|
|
|
let exportClass = "btn-primary";
|
|
|
|
|
|
if(index > -1) {
|
|
|
- exportText = "Deselect for Export";
|
|
|
+ exportText = "Deselect";
|
|
|
exportClass = "btn-success";
|
|
|
}
|
|
|
|
|
|
@@ -121,11 +140,11 @@ function displayInfoWindow(marker) {
|
|
|
content += "<div class=\"row\">";
|
|
|
|
|
|
content += "<div class=\"col\"><a class=\"btn btn-block " + exportClass + "\" href=\"#\" data-export-location-id=\"" + marker.location.id + "\">" + exportText + "</a></div>";
|
|
|
- content += "<div class=\"col\"><a class=\"btn btn-block btn-primary\" href=\"/account/locations/" + marker.location.id + "\" target=\"_blank\">View Details</a></div>";
|
|
|
+ content += "<div class=\"col\"><a class=\"btn btn-block btn-primary\" href=\"/account/locations/" + marker.location.id + "\" target=\"_blank\">View</a></div>";
|
|
|
content += "</div>";
|
|
|
content += "</div>";
|
|
|
|
|
|
infoWindow.setContent(content);
|
|
|
infoWindow.open(map, marker);
|
|
|
|
|
|
-}
|
|
|
+}
|