Просмотр исходного кода

Add marker count badge to locations page

Alan Lam 4 лет назад
Родитель
Сommit
258edaf2cd
2 измененных файлов с 15 добавлено и 0 удалено
  1. 10 0
      public/js/app-locations.js
  2. 5 0
      views/locations.php

+ 10 - 0
public/js/app-locations.js

@@ -31,6 +31,16 @@ function initialiseLocations() {
 
 		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 = {

+ 5 - 0
views/locations.php

@@ -166,6 +166,11 @@ var customerId = <?=$customer->id?>;
 	<?php
 	if(!empty($locations)) {
 		?>
+		<h3>
+			<?=htmlspecialchars(__("Map"))?>
+			<span id="map-marker-count" class="badge badge-pill badge-primary"></span>
+		</h3>
+
 		<div class="mb-3" id="map" data-maps data-lat="0" data-lng="0" data-zoom="7" style="height: 480px;" data-callback="initialiseLocations">
 		</div>
 		<?php