|
@@ -0,0 +1,170 @@
|
|
|
|
|
+$(function() {
|
|
|
|
|
+
|
|
|
|
|
+ $(".btn[data-test-id]").click(function() {
|
|
|
|
|
+ let testId = $(this).data("test-id");
|
|
|
|
|
+ toggleTest(testId);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $("#modal-test-claim").on("shown.bs.modal", function() {
|
|
|
|
|
+
|
|
|
|
|
+ $("#modal-confirm-button").removeClass("disabled");
|
|
|
|
|
+
|
|
|
|
|
+ let listGroup = $(this).find(".list-group");
|
|
|
|
|
+ $(listGroup).empty();
|
|
|
|
|
+
|
|
|
|
|
+ for(let i in selectedTests) {
|
|
|
|
|
+ let test = selectedTests[i];
|
|
|
|
|
+ let location = test.location;
|
|
|
|
|
+
|
|
|
|
|
+ $(listGroup).append('<div class="list-group-item d-flex justify-content-between" data-test-id="' + test.id + '">\
|
|
|
|
|
+ <div>\
|
|
|
|
|
+ ' + location.name + '<br />\
|
|
|
|
|
+ <small class="text-danger" data-fail-message></small>\
|
|
|
|
|
+ </div>\
|
|
|
|
|
+ <span class="badge badge-lg badge-secondary align-self-center">Unclaimed</span>\
|
|
|
|
|
+ </div>');
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $("#claim-confirm-button").click(function() {
|
|
|
|
|
+ if(queueInProgress) return;
|
|
|
|
|
+
|
|
|
|
|
+ $("#claim-cancel-button").hide();
|
|
|
|
|
+ $("#modal-close-button").hide();
|
|
|
|
|
+
|
|
|
|
|
+ $(this).addClass("disabled").text("Please wait...");
|
|
|
|
|
+ queuedTests = selectedTests.slice(0); // Clone
|
|
|
|
|
+ queueInProgress = true;
|
|
|
|
|
+ claimTests();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+var markers = [];
|
|
|
|
|
+var selectedTests = [];
|
|
|
|
|
+var queuedTests = [];
|
|
|
|
|
+var queueInProgress = false;
|
|
|
|
|
+var tests = [];
|
|
|
|
|
+
|
|
|
|
|
+function getTests() {
|
|
|
|
|
+ $.get(window.location, {
|
|
|
|
|
+ action: "get-tests"
|
|
|
|
|
+ }, function(response) {
|
|
|
|
|
+ if(!response.success) return false;
|
|
|
|
|
+
|
|
|
|
|
+ let map = maps["map"];
|
|
|
|
|
+
|
|
|
|
|
+ for(var i in response.tests) {
|
|
|
|
|
+ let test = response.tests[i];
|
|
|
|
|
+ let location = test.location;
|
|
|
|
|
+
|
|
|
|
|
+ let latLng = {
|
|
|
|
|
+ lat: location.geolocation[0],
|
|
|
|
|
+ lng: location.geolocation[1],
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let markerOptions = {
|
|
|
|
|
+ position: latLng,
|
|
|
|
|
+ map: map,
|
|
|
|
|
+ title: location.name,
|
|
|
|
|
+ icon: "/img/markers/building-grey.png"
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let marker = new google.maps.Marker(markerOptions);
|
|
|
|
|
+ marker.testId = test.id;
|
|
|
|
|
+
|
|
|
|
|
+ tests[test.id] = test;
|
|
|
|
|
+
|
|
|
|
|
+ markers.push(marker);
|
|
|
|
|
+
|
|
|
|
|
+ marker.addListener("click", function() {
|
|
|
|
|
+ let testId = this.testId;
|
|
|
|
|
+ toggleTest(testId);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function toggleTest(id) {
|
|
|
|
|
+ let test = tests[id];
|
|
|
|
|
+ let index = selectedTests.indexOf(test);
|
|
|
|
|
+
|
|
|
|
|
+ if(index == -1) {
|
|
|
|
|
+ var icon = "building-green";
|
|
|
|
|
+ var btnFromClass = "btn-primary";
|
|
|
|
|
+ var btnToClass = "btn-danger";
|
|
|
|
|
+ var btnText = "Deselect";
|
|
|
|
|
+ selectedTests.push(test);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ var icon = "building-grey";
|
|
|
|
|
+ var btnFromClass = "btn-danger";
|
|
|
|
|
+ var btnToClass = "btn-primary";
|
|
|
|
|
+ var btnText = "Select";
|
|
|
|
|
+ selectedTests.splice(index, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for(var i in markers) {
|
|
|
|
|
+ let marker = markers[i];
|
|
|
|
|
+ if(marker.testId == id) {
|
|
|
|
|
+ marker.setIcon("/img/markers/" + icon + ".png");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let selectedCount = selectedTests.length;
|
|
|
|
|
+
|
|
|
|
|
+ $(".btn[data-test-id=" + id + "]").removeClass(btnFromClass).addClass(btnToClass).text(btnText);
|
|
|
|
|
+ $("#claim-number").text(selectedCount);
|
|
|
|
|
+
|
|
|
|
|
+ if(selectedCount > 0) {
|
|
|
|
|
+ $("#claim-tests-button").removeClass("disabled");
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ $("#claim-tests-button").addClass("disabled");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function claimTests() {
|
|
|
|
|
+ if(queuedTests.length > 0) {
|
|
|
|
|
+ let test = queuedTests.shift();
|
|
|
|
|
+ claimTest(test);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ $("#claim-confirm-button").hide();
|
|
|
|
|
+ $("#claim-finish-button").show();
|
|
|
|
|
+ queueInProgress = false;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function claimTest(test) {
|
|
|
|
|
+
|
|
|
|
|
+ let testId = test.id;
|
|
|
|
|
+ let listGroupItem = $("#modal-test-claim").find(".list-group-item[data-test-id=" + testId + "]");
|
|
|
|
|
+ let badge = $(listGroupItem).find(".badge");
|
|
|
|
|
+ let failMessage = $(listGroupItem).find("small[data-fail-message]");
|
|
|
|
|
+
|
|
|
|
|
+ badge.removeClass("badge-secondary").addClass("badge-warning").html("<i class=\"far fa-sync fa-pulse\"></i> Claiming...");
|
|
|
|
|
+
|
|
|
|
|
+ $.post(window.location, {
|
|
|
|
|
+ action: "claim-test",
|
|
|
|
|
+ id: test.id
|
|
|
|
|
+ }, function(response) {
|
|
|
|
|
+ if(response.success) {
|
|
|
|
|
+ badge.removeClass("badge-warning").addClass("badge-success").html("<i class=\"far fa-check\"></i> Claimed");
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ badge.removeClass("badge-warning").addClass("badge-danger").html("<i class=\"far fa-times\"></i> Failed");
|
|
|
|
|
+ failMessage.text(response.message);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Next
|
|
|
|
|
+ claimTests();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+}
|