|
|
@@ -5,9 +5,13 @@ var selectedLocation;
|
|
|
|
|
|
var map = null;
|
|
|
|
|
|
+var locations = [];
|
|
|
+var testers = [];
|
|
|
+
|
|
|
$(function() {
|
|
|
- $(document).on("click", "button[data-assign-button]", handleAssignButtonClick);
|
|
|
$(document).on("click", "button[data-find-testers-button]", handleFindTestersButtonClick);
|
|
|
+ $(document).on("click", "button[data-assign-button]", handleAssignButtonClick);
|
|
|
+ $(document).on("click", "#assign-confirm-button", handleConfirmAssignButtonClick);
|
|
|
});
|
|
|
|
|
|
function initialiseLocations() {
|
|
|
@@ -25,6 +29,8 @@ function initialiseLocations() {
|
|
|
}, function(response) {
|
|
|
if(!response.locations) return;
|
|
|
|
|
|
+ locations = response.locations;
|
|
|
+
|
|
|
$("#tests-tbody").empty();
|
|
|
|
|
|
for(let i in response.locations) {
|
|
|
@@ -101,8 +107,6 @@ function handleFindTestersButtonClick() {
|
|
|
id: locationId
|
|
|
};
|
|
|
|
|
|
- console.log(container);
|
|
|
-
|
|
|
var latLng = {
|
|
|
lat: lat,
|
|
|
lng: lng
|
|
|
@@ -135,7 +139,6 @@ function clearTesters() {
|
|
|
testerMarkers = [];
|
|
|
|
|
|
$("#tester-list-loading-container").text("Please select a location with a pending test.");
|
|
|
- $("#tester-list-group").empty();
|
|
|
$("#testers-tbody").empty();
|
|
|
}
|
|
|
|
|
|
@@ -155,6 +158,8 @@ function initialiseTesters() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ testers = response.testers;
|
|
|
+
|
|
|
$("#tester-list-loading-container").text(response.testers.length + " tester addresses found in the vicinity.");
|
|
|
|
|
|
for(let i in response.testers) {
|
|
|
@@ -180,7 +185,7 @@ function initialiseTesters() {
|
|
|
|
|
|
testerMarkers.push(marker);
|
|
|
|
|
|
- var tr = $("<tr data-address-id=\"" + tester.addressId + "\"></tr>");
|
|
|
+ var tr = $("<tr data-tester-id=\"" + tester.id + "\" data-address-id=\"" + tester.addressId + "\"></tr>");
|
|
|
|
|
|
var td = $("<td></td>");
|
|
|
td.append("<a href=\"/account/users/" + tester.id + "\" target=\"_blank\">" + tester.name + "</a>");
|
|
|
@@ -209,7 +214,7 @@ function initialiseTesters() {
|
|
|
|
|
|
td = $("<td class=\"text-right align-middle\"></td>");
|
|
|
if(!tester.isCurrentTester) {
|
|
|
- td.append("<button class=\"btn btn-outline-primary\" data-assign-button>Assign</button>");
|
|
|
+ td.append("<button class=\"btn btn-outline-primary\" data-assign-button>Assign...</button>");
|
|
|
}
|
|
|
tr.append(td);
|
|
|
|
|
|
@@ -219,23 +224,82 @@ function initialiseTesters() {
|
|
|
}
|
|
|
|
|
|
function handleAssignButtonClick(event) {
|
|
|
- event.preventDefault();
|
|
|
let container = $(this).closest("[data-address-id]");
|
|
|
|
|
|
- var addressId = $(container).data("address-id");
|
|
|
+ let addressId = parseInt($(container).data("address-id"));
|
|
|
+ let testerId = parseInt($(container).data("tester-id"));
|
|
|
|
|
|
- $.post("/account/projects/" + projectID + "/assign-tester", {
|
|
|
- submit: $("#submit").val(),
|
|
|
- location_id: selectedLocation.id,
|
|
|
- address_id: addressId
|
|
|
- }, function(response) {
|
|
|
- if(!response.success) return;
|
|
|
+ // Find location
|
|
|
+ var location = false;
|
|
|
+ for(var i in locations) {
|
|
|
+ if(locations[i].id == selectedLocation.id) {
|
|
|
+ location = locations[i];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(location) {
|
|
|
+ $("#modal-assign-tester").find("[data-location-photo]").css("background-image", "url(/account/locations/" + location.id + "/photo)");
|
|
|
+ $("#modal-assign-tester").find("[data-location-name]").text(location.name);
|
|
|
+ $("#modal-assign-tester").find("[data-location-address]").text(location.address);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Find tester
|
|
|
+ var tester = false;
|
|
|
+ for(var i in testers) {
|
|
|
+ if(testers[i].id == testerId) {
|
|
|
+ tester = testers[i];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(tester) {
|
|
|
+ $("#modal-assign-tester").find("[data-tester-photo]").css("background-image", "url(/account/users/" + tester.id + "/photo)");
|
|
|
+ $("#modal-assign-tester").find("[data-tester-name]").text(tester.name);
|
|
|
+ $("#modal-assign-tester").find("[data-tester-age]").text(tester.age);
|
|
|
+ $("#modal-assign-tester").find("[data-tester-level] span").attr("class", "badge badge-lg badge-" + tester.levelClass).text(tester.levelText);
|
|
|
+ $("#modal-assign-tester").find("[data-tester-score]").text(tester.score);
|
|
|
+ }
|
|
|
|
|
|
- selectedLocation.status = "assigned";
|
|
|
+ $("#modal-assign-tester").modal("show");
|
|
|
+
|
|
|
+ $("#assign-location-id").val(selectedLocation.id);
|
|
|
+ $("#assign-address-id").val(addressId);
|
|
|
+}
|
|
|
+
|
|
|
+function handleConfirmAssignButtonClick(event) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ var assignButton = this;
|
|
|
+ var assignProgressContainer = $("#assign-progress-container").get(0);
|
|
|
+
|
|
|
+ $(assignButton).attr("disabled", "");
|
|
|
+ $(assignProgressContainer).removeClass("d-none");
|
|
|
+ $(assignProgressContainer).removeClass("text-danger");
|
|
|
+ $(assignProgressContainer).find("svg").addClass("fa-pulse");
|
|
|
+ $(assignProgressContainer).find("span").text("Please wait...");
|
|
|
+
|
|
|
+ let form = $(this).closest("form");
|
|
|
+
|
|
|
+ let data = $(form).serialize() + "&submit=" + $("#submit").val();
|
|
|
+
|
|
|
+ $.post("/account/projects/" + projectID + "/assign-tester", data, function(response) {
|
|
|
+
|
|
|
+ $(assignButton).removeAttr("disabled");
|
|
|
+
|
|
|
+ $(assignProgressContainer).find("svg").removeClass("fa-pulse");
|
|
|
+
|
|
|
+ if(!response.success) {
|
|
|
+ $(assignProgressContainer).addClass("text-danger");
|
|
|
+ $(assignProgressContainer).find("span").text("Failed to assign tester.");
|
|
|
+ $(assignProgressContainer).find("span").text(response.message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $(assignProgressContainer).addClass("d-none");
|
|
|
+
|
|
|
+ $("#modal-assign-tester").modal("hide");
|
|
|
|
|
|
clearTesters();
|
|
|
initialiseLocations();
|
|
|
-
|
|
|
});
|
|
|
-
|
|
|
}
|