|
@@ -13,7 +13,7 @@ function initialiseLocations() {
|
|
|
id: $("#id").val(),
|
|
id: $("#id").val(),
|
|
|
internal_id: $("#internal-id").val(),
|
|
internal_id: $("#internal-id").val(),
|
|
|
name: $("#name").val(),
|
|
name: $("#name").val(),
|
|
|
- legal_entity_name: $("#legal-entity-name").val()
|
|
|
|
|
|
|
+ legal_entity_name: $("#legal-entity-name").val(),
|
|
|
}, function(response) {
|
|
}, function(response) {
|
|
|
if(!response.success) return false;
|
|
if(!response.success) return false;
|
|
|
if(!response.locations) return false;
|
|
if(!response.locations) return false;
|
|
@@ -81,6 +81,7 @@ function initialiseLocations() {
|
|
|
displayInfoWindow(marker);
|
|
displayInfoWindow(marker);
|
|
|
|
|
|
|
|
$createProjectButton.prop("disabled", (exportIds.length === 0));
|
|
$createProjectButton.prop("disabled", (exportIds.length === 0));
|
|
|
|
|
+ $addLocationsToProjectButton.prop("disabled", (exportIds.length === 0));
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
$("#export-csv-button, #export-kml-button").on("click", function(event) {
|
|
$("#export-csv-button, #export-kml-button").on("click", function(event) {
|
|
@@ -103,7 +104,6 @@ function initialiseLocations() {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const $createProjectButton = $("#create-project-button");
|
|
const $createProjectButton = $("#create-project-button");
|
|
|
-
|
|
|
|
|
$createProjectButton.on("click", function(event) {
|
|
$createProjectButton.on("click", function(event) {
|
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
|
if(exportIds.length === 0) return;
|
|
if(exportIds.length === 0) return;
|
|
@@ -115,6 +115,10 @@ function initialiseLocations() {
|
|
|
$form.trigger("submit");
|
|
$form.trigger("submit");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ const $addLocationsToProjectButton = $("#add-locations-to-project-button");
|
|
|
|
|
+
|
|
|
|
|
+ new AddLocationsToProjectModal();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function displayInfoWindow(marker) {
|
|
function displayInfoWindow(marker) {
|
|
@@ -156,3 +160,50 @@ function displayInfoWindow(marker) {
|
|
|
infoWindow.open(map, marker);
|
|
infoWindow.open(map, marker);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+class AddLocationsToProjectModal {
|
|
|
|
|
+ constructor() {
|
|
|
|
|
+ this.$modal = $("#add-locations-to-project-modal");
|
|
|
|
|
+ this.$modal.on("show.bs.modal", event => this.onShow(event));
|
|
|
|
|
+
|
|
|
|
|
+ this.$form = this.$modal.find("form");
|
|
|
|
|
+ this.$form.on("submit", event => this.onSubmit(event));
|
|
|
|
|
+
|
|
|
|
|
+ this.$projectDropdown = this.$form.find("[name=project_id]");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onShow(event) {
|
|
|
|
|
+ this.$form.find(`input[name="location_ids[]"]`).remove();
|
|
|
|
|
+
|
|
|
|
|
+ exportIds.forEach(locationId => {
|
|
|
|
|
+ this.$form.append(`<input type="hidden" name="location_ids[]" value="${locationId}" />`);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onSubmit(event) {
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
|
+
|
|
|
|
|
+ const projectId = this.$projectDropdown.val();
|
|
|
|
|
+
|
|
|
|
|
+ const data = this.$form.serialize();
|
|
|
|
|
+
|
|
|
|
|
+ $.post(`/account/projects/${projectId}/add-locations`, data).then(response => {
|
|
|
|
|
+
|
|
|
|
|
+ if(response.success) {
|
|
|
|
|
+ if(response.dupeLocations.length > 0) {
|
|
|
|
|
+ const locationNames = response.dupeLocations.map(location => location.name).join("\n");
|
|
|
|
|
+
|
|
|
|
|
+ alert(`Locations added to project successfully. The following locations were skipped as there were already active tests:\n\n${locationNames}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ alert("Locations added to project successfully.");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log(response);
|
|
|
|
|
+ this.$modal.modal("hide");
|
|
|
|
|
+ }).catch(error => {
|
|
|
|
|
+ console.error(error);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+}
|