app-tests-tester-list.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. $(function() {
  2. const $testsList = $("#tests-list");
  3. $(document).on("click", "[data-jump-button]", event => {
  4. $("#tests-list > .list-group-item").removeClass("list-group-item-primary");
  5. event.preventDefault();
  6. const $button = $(event.currentTarget);
  7. const id = $button.data("id");
  8. const target = `#test-${id}`;
  9. const $listGroupItem = $(target);
  10. $listGroupItem.addClass("list-group-item-primary");
  11. const top = $listGroupItem.offset().top - 56 - 45;
  12. $("html, body").animate({
  13. scrollTop: top
  14. }, "fast")
  15. });
  16. });
  17. var infoWindow = false;
  18. function initialiseMarkers() {
  19. if(infoWindow === false) {
  20. infoWindow = new google.maps.InfoWindow();
  21. }
  22. $.get(window.location, {
  23. action: "get-tests"
  24. }, function(response) {
  25. if(!response.success) return;
  26. let tests = response.tests;
  27. let map = maps["map"];
  28. let bounds = new google.maps.LatLngBounds();
  29. for(let i in tests) {
  30. if(!tests.hasOwnProperty(i)) continue;
  31. let test = tests[i];
  32. let latLng = {
  33. lat: test.geolocation[0],
  34. lng: test.geolocation[1]
  35. };
  36. bounds.extend(latLng);
  37. let markerOptions = {
  38. position: latLng,
  39. map: map,
  40. title: test.name
  41. };
  42. if(test.icon) {
  43. markerOptions.icon = `/img/markers/${test.icon}.png`;
  44. }
  45. let marker = new google.maps.Marker(markerOptions);
  46. marker.addListener("click", function() {
  47. infoWindow.setContent(`<strong>${test.name}</strong> <span class="badge badge-${test.statusClass}">${test.status}</span><br />
  48. <small>${test.address}</small><br />
  49. <a data-jump-button data-id="${test.id}" class="btn btn-primary btn-block btn-sm mt-2" href="#">Find in List</a>`
  50. );
  51. infoWindow.open(map, marker);
  52. });
  53. }
  54. map.fitBounds(bounds);
  55. });
  56. }