|
|
@@ -1,5 +1,13 @@
|
|
|
+var infoWindow = false;
|
|
|
+var exportIds = [];
|
|
|
+var markerMap = {};
|
|
|
+
|
|
|
function initialiseLocations() {
|
|
|
|
|
|
+ if(!infoWindow) {
|
|
|
+ infoWindow = new google.maps.InfoWindow();
|
|
|
+ }
|
|
|
+
|
|
|
$.get("/api/customers/" + customerId + "/get-locations", {
|
|
|
id: $("#id").val(),
|
|
|
internal_id: $("#internal-id").val(),
|
|
|
@@ -27,22 +35,97 @@ function initialiseLocations() {
|
|
|
}
|
|
|
|
|
|
if(location.icon) {
|
|
|
- options.icon = "/img/markers/" + location.icon;
|
|
|
+ options.icon = "/img/markers/building-red.png";
|
|
|
}
|
|
|
|
|
|
bounds.extend(position);
|
|
|
|
|
|
+ let key = "marker-" + location.id;
|
|
|
+
|
|
|
let marker = new google.maps.Marker(options);
|
|
|
- marker.locationId = location.id;
|
|
|
+ marker.location = location;
|
|
|
|
|
|
marker.addListener("click", function() {
|
|
|
- window.open("/account/locations/" + this.locationId, "_blank");
|
|
|
+ displayInfoWindow(this);
|
|
|
});
|
|
|
|
|
|
+ markerMap[key] = marker;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
map.fitBounds(bounds);
|
|
|
|
|
|
});
|
|
|
|
|
|
+ $(document).on("click", "a[data-export-location-id]", function(event) {
|
|
|
+
|
|
|
+ let locationId = parseInt($(this).attr("data-export-location-id"));
|
|
|
+ let index = exportIds.indexOf(locationId);
|
|
|
+ let key = "marker-" + 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: "/img/markers/building-red.png"
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ displayInfoWindow(marker);
|
|
|
+ });
|
|
|
+
|
|
|
+ $("#export-csv-button, #export-kml-button").click(function(event) {
|
|
|
+
|
|
|
+ if(exportIds.length > 0) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ let action = $(this).attr("data-action");
|
|
|
+
|
|
|
+ $("#locations-export-form input[name='ids[]']").remove();
|
|
|
+ $("#locations-export-form input[name='action']").val(action);
|
|
|
+
|
|
|
+ for(let i in exportIds) {
|
|
|
+ let locationId = exportIds[i];
|
|
|
+ $("#locations-export-form").append("<input type=\"hidden\" name=\"ids[]\" value=\"" + locationId + "\" />");
|
|
|
+ }
|
|
|
+
|
|
|
+ $("#locations-export-form").submit();
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function displayInfoWindow(marker) {
|
|
|
+
|
|
|
+ let locationId = parseInt(marker.location.id);
|
|
|
+ let index = exportIds.indexOf(locationId);
|
|
|
+
|
|
|
+ let exportText = "Select for Export";
|
|
|
+ let exportClass = "btn-primary";
|
|
|
+
|
|
|
+ if(index > -1) {
|
|
|
+ exportText = "Deselect for Export";
|
|
|
+ exportClass = "btn-success";
|
|
|
+ }
|
|
|
+
|
|
|
+ let content = "<div class=\"container-fluid\" style=\"font-size: 1rem; font-weight: normal;\">";
|
|
|
+ content += "<p>" + marker.location.name + "</p>\n";
|
|
|
+
|
|
|
+ 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>";
|
|
|
+ content += "</div>";
|
|
|
+
|
|
|
+ infoWindow.setContent(content);
|
|
|
+ infoWindow.open(map, marker);
|
|
|
+
|
|
|
}
|