mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-12-16 00:53:39 +00:00
Extract "add spot" into its own page
This commit is contained in:
80
webassets/js/add-spot.js
Normal file
80
webassets/js/add-spot.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// Method called to add a spot to the server
|
||||
function addSpot() {
|
||||
try {
|
||||
// Save settings (this will save "your call" for future use)
|
||||
saveSettings();
|
||||
|
||||
// Unpack the user's entered values
|
||||
var dx = $("#dx-call").val().toUpperCase();
|
||||
var freqStr = $("#freq").val();
|
||||
var mode = $("#mode").val().toUpperCase();
|
||||
var comment = $("#comment").val();
|
||||
var de = $("#de-call").val().toUpperCase();
|
||||
|
||||
var spot = {}
|
||||
if (dx != "") {
|
||||
spot["dx_call"] = dx;
|
||||
} else {
|
||||
showAddSpotError("A DX callsign is required in order to spot.");
|
||||
return;
|
||||
}
|
||||
if (freqStr != "") {
|
||||
spot["freq"] = parseFloat(freqStr) * 1000;
|
||||
} else {
|
||||
showAddSpotError("A frequency is required in order to spot.");
|
||||
return;
|
||||
}
|
||||
if (mode != "") {
|
||||
spot["mode"] = mode;
|
||||
}
|
||||
if (comment != "") {
|
||||
spot["comment"] = comment;
|
||||
}
|
||||
if (de != "") {
|
||||
spot["de_call"] = de;
|
||||
}
|
||||
spot["time"] = moment.utc().valueOf() / 1000.0;
|
||||
|
||||
$.ajax("/api/v1/spot", {
|
||||
data : JSON.stringify(spot),
|
||||
contentType : 'application/json',
|
||||
type : 'POST',
|
||||
timeout: 10000,
|
||||
success: async function (result) {
|
||||
$("#result-good").html("<button type='button' class='btn btn-success' style='margin-top: 2em;'><i class='fa-solid fa-check'></i> OK</button>");
|
||||
setTimeout(() => {
|
||||
$("#result-good").hide();
|
||||
window.location.replace("/");
|
||||
}, 1000);
|
||||
},
|
||||
error: function (result) {
|
||||
showAddSpotError(result.responseText);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
showAddSpotError(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Show an "add spot" error.
|
||||
function showAddSpotError(text) {
|
||||
$("#result-bad").html("<div class='alert alert-danger alert-dismissible fade show mb-0 mt-4' role='alert'><i class='fa-solid fa-triangle-exclamation'></i> " + text + "<button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button></div>");
|
||||
}
|
||||
|
||||
// Force callsign and mode capitalisation
|
||||
$("#dx-call").change(function () {
|
||||
$(this).val($(this).val().trim().toUpperCase());
|
||||
});
|
||||
$("#de-call").change(function () {
|
||||
$(this).val($(this).val().trim().toUpperCase());
|
||||
});
|
||||
$("#mode").change(function () {
|
||||
$(this).val($(this).val().trim().toUpperCase());
|
||||
});
|
||||
|
||||
// Startup
|
||||
$(document).ready(function() {
|
||||
// Load settings from settings storage
|
||||
loadSettings();
|
||||
});
|
||||
@@ -330,64 +330,6 @@ function userGridUpdated() {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
// Method called to add a spot to the server
|
||||
function addSpot() {
|
||||
try {
|
||||
var dx = $("#add-spot-dx-call").val().toUpperCase();
|
||||
var freqStr = $("#add-spot-freq").val();
|
||||
var mode = $("#add-spot-mode").val().toUpperCase();
|
||||
var comment = $("#add-spot-comment").val();
|
||||
var de = $("#add-spot-de-call").val().toUpperCase();
|
||||
|
||||
var spot = {}
|
||||
if (dx != "") {
|
||||
spot["dx_call"] = dx;
|
||||
} else {
|
||||
showAddSpotError("A DX callsign is required in order to spot.");
|
||||
return;
|
||||
}
|
||||
if (freqStr != "") {
|
||||
spot["freq"] = parseFloat(freqStr) * 1000;
|
||||
} else {
|
||||
showAddSpotError("A frequency is required in order to spot.");
|
||||
return;
|
||||
}
|
||||
if (mode != "") {
|
||||
spot["mode"] = mode;
|
||||
}
|
||||
if (comment != "") {
|
||||
spot["comment"] = comment;
|
||||
}
|
||||
if (de != "") {
|
||||
spot["de_call"] = de;
|
||||
}
|
||||
spot["time"] = moment.utc().valueOf() / 1000.0;
|
||||
|
||||
$.ajax("/api/v1/spot", {
|
||||
data : JSON.stringify(spot),
|
||||
contentType : 'application/json',
|
||||
type : 'POST',
|
||||
timeout: 10000,
|
||||
success: async function (result) {
|
||||
$("#post-spot-result-good").html("<button type='button' class='btn btn-success' style='margin-top: 2em;'><i class='fa-solid fa-check'></i> OK</button>");
|
||||
setTimeout(() => $("#post-spot-result-good").hide(), 2000);
|
||||
loadSpots();
|
||||
},
|
||||
error: function (result) {
|
||||
showAddSpotError(result.responseText);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
showAddSpotError(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Show an "add spot" error.
|
||||
function showAddSpotError(text) {
|
||||
$("#post-spot-result-bad").html("<div class='alert alert-danger alert-dismissible fade show mb-0 mt-4' role='alert'><i class='fa-solid fa-triangle-exclamation'></i> " + text + "<button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button></div>");
|
||||
}
|
||||
|
||||
// React to toggling/closing panels
|
||||
function toggleFiltersPanel() {
|
||||
// If we are going to show the filters panel, hide the display and add spot panels
|
||||
@@ -395,10 +337,6 @@ function toggleFiltersPanel() {
|
||||
$("#display-area").hide();
|
||||
$("#display-button").button("toggle");
|
||||
}
|
||||
if (!$("#filters-area").is(":visible") && $("#add-spot-area").is(":visible")) {
|
||||
$("#add-spot-area").hide();
|
||||
$("#add-spot-button").button("toggle");
|
||||
}
|
||||
$("#filters-area").toggle();
|
||||
}
|
||||
function closeFiltersPanel() {
|
||||
@@ -412,10 +350,6 @@ function toggleDisplayPanel() {
|
||||
$("#filters-area").hide();
|
||||
$("#filters-button").button("toggle");
|
||||
}
|
||||
if (!$("#display-area").is(":visible") && $("#add-spot-area").is(":visible")) {
|
||||
$("#add-spot-area").hide();
|
||||
$("#add-spot-button").button("toggle");
|
||||
}
|
||||
$("#display-area").toggle();
|
||||
}
|
||||
function closeDisplayPanel() {
|
||||
@@ -423,23 +357,6 @@ function closeDisplayPanel() {
|
||||
$("#display-area").hide();
|
||||
}
|
||||
|
||||
function toggleAddSpotPanel() {
|
||||
// If we are going to show the add spot panel, hide the filters and display panels
|
||||
if (!$("#add-spot-area").is(":visible") && $("#filters-area").is(":visible")) {
|
||||
$("#filters-area").hide();
|
||||
$("#filters-button").button("toggle");
|
||||
}
|
||||
if (!$("#add-spot-area").is(":visible") && $("#display-area").is(":visible")) {
|
||||
$("#display-area").hide();
|
||||
$("#display-button").button("toggle");
|
||||
}
|
||||
$("#add-spot-area").toggle();
|
||||
}
|
||||
function closeAddSpotPanel() {
|
||||
$("#add-spot-button").button("toggle");
|
||||
$("#add-spot-area").hide();
|
||||
}
|
||||
|
||||
// Display the intro box, unless the user has already dismissed it once.
|
||||
function displayIntroBox() {
|
||||
if (localStorage.getItem("intro-box-dismissed") == null) {
|
||||
|
||||
Reference in New Issue
Block a user