|
|
@@ -49,6 +49,28 @@ $(function() {
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
+ $("a[data-all-addresses]").click(function(event) {
|
|
|
+
|
|
|
+ let key = "all-addresses";
|
|
|
+ if(typeof markerGroups[key] !== "undefined") {
|
|
|
+ for(let i in markerGroups[key]) {
|
|
|
+ let m = markerGroups[key][i];
|
|
|
+ m.setMap(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let selected = $(this).data("selected");
|
|
|
+ if(selected) {
|
|
|
+ $(this).data("selected", false);
|
|
|
+ $(this).find(".badge").removeClass("badge-success").text("");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ loadAllAddresses();
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
function loadCustomerLocations(customerId) {
|
|
|
@@ -87,7 +109,7 @@ function loadCustomerLocations(customerId) {
|
|
|
infoWindow.setContent("");
|
|
|
|
|
|
let marker = new google.maps.Marker(options);
|
|
|
- addMarkerClickListener(marker, l);
|
|
|
+ addMarkerClickListenerForLocation(marker, l);
|
|
|
|
|
|
markerGroups[key].push(marker);
|
|
|
}
|
|
|
@@ -134,7 +156,7 @@ function loadProjectLocations(projectId) {
|
|
|
if(l.icon) options.icon = l.icon;
|
|
|
|
|
|
let marker = new google.maps.Marker(options);
|
|
|
- addMarkerClickListener(marker, l);
|
|
|
+ addMarkerClickListenerForLocation(marker, l);
|
|
|
|
|
|
markerGroups[key].push(marker);
|
|
|
|
|
|
@@ -146,7 +168,51 @@ function loadProjectLocations(projectId) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function addMarkerClickListener(m, l) {
|
|
|
+function loadAllAddresses() {
|
|
|
+
|
|
|
+ if(infoWindow == false) {
|
|
|
+ infoWindow = new google.maps.InfoWindow();
|
|
|
+ }
|
|
|
+
|
|
|
+ $.get("/api/addresses/get-all", {
|
|
|
+ submit: $("#submit").val()
|
|
|
+ }, function(response) {
|
|
|
+ if(!response.success) return false;
|
|
|
+
|
|
|
+ let map = maps["map"];
|
|
|
+ let key = "all-addresses";
|
|
|
+
|
|
|
+ markerGroups[key] = [];
|
|
|
+
|
|
|
+ for(let i in response.addresses) {
|
|
|
+
|
|
|
+ let a = response.addresses[i];
|
|
|
+
|
|
|
+ let position = {
|
|
|
+ lat: a.latitude,
|
|
|
+ lng: a.longitude
|
|
|
+ };
|
|
|
+
|
|
|
+ var options = {
|
|
|
+ position: position,
|
|
|
+ title: a.name,
|
|
|
+ map: map
|
|
|
+ };
|
|
|
+
|
|
|
+ let marker = new google.maps.Marker(options);
|
|
|
+ addMarkerClickListenerForAddress(marker, a);
|
|
|
+
|
|
|
+ markerGroups[key].push(marker);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $("a[data-all-addresses]").data("selected", true);
|
|
|
+ $("a[data-all-addresses]").find(".badge").addClass("badge-danger").text(response.addresses.length);
|
|
|
+
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function addMarkerClickListenerForLocation(m, l) {
|
|
|
let map = maps["map"];
|
|
|
m.addListener("click", function() {
|
|
|
let content = "<strong><a href=\"/account/locations/" + l.id + "\" target=\"_blank\">" + l.name + "</a></strong><br />";
|
|
|
@@ -159,3 +225,14 @@ function addMarkerClickListener(m, l) {
|
|
|
infoWindow.open(map, m);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+function addMarkerClickListenerForAddress(m, a) {
|
|
|
+ let map = maps["map"];
|
|
|
+ m.addListener("click", function() {
|
|
|
+ let content = "<strong><a href=\"/account/users/" + a.userId + "\" target=\"_blank\">" + a.name + "</a></strong><br />";
|
|
|
+ content += "ID: " + a.userId + "<br />";
|
|
|
+
|
|
|
+ infoWindow.setContent(content);
|
|
|
+ infoWindow.open(map, m);
|
|
|
+ });
|
|
|
+}
|