+function uploadTrack() {
+ // Hide all areas in the dialog.
+ var dia = document.getElementById("trackDialogArea");
+ var areas = dia.children;
+ for (var i = 0; i <= areas.length - 1; i++) {
+ areas[i].style.display = "none";
+ }
+ // Reset all the fields in the status area.
+ document.getElementById("uploadStatusCloseButton").disabled = true;
+ document.getElementById("uploadInProgress").style.display = "block";
+ document.getElementById("uploadSuccess").style.display = "none";
+ document.getElementById("uploadFailed").style.display = "none";
+ document.getElementById("uploadError").style.display = "none";
+ document.getElementById("uploadErrorMsg").textContent = "";
+ // Now show the status area.
+ document.getElementById("uploadStatus").style.display = "block";
+
+ // Assemble field to post to the backend.
+ var formData = new FormData();
+ formData.append("jsondata", convertTrack("json"));
+ var desc = document.getElementById("uploadDesc").value;
+ formData.append("comment",
+ desc.length ? desc : "Track recorded via Lantea Maps");
+ formData.append("devicename",
+ document.getElementById("uploadDevName").value);
+ formData.append("public",
+ document.getElementById("uploadPublic").value);
+
+ fetchBackend("save_track", "POST", formData,
+ function(aResult, aStatusCode) {
+ if (aStatusCode >= 400) {
+ reportUploadStatus(false, aResult);
+ }
+ else {
+ reportUploadStatus(true);
+ }
+ }
+ );
+}
+
+function reportUploadStatus(aSuccess, aMessage) {
+ document.getElementById("uploadStatusCloseButton").disabled = false;
+ document.getElementById("uploadInProgress").style.display = "none";
+ if (aSuccess) {
+ document.getElementById("uploadSuccess").style.display = "block";
+ }
+ else if (aMessage) {
+ document.getElementById("uploadErrorMsg").textContent = aMessage;
+ document.getElementById("uploadError").style.display = "block";
+ }
+ else {
+ document.getElementById("uploadFailed").style.display = "block";
+ }
+}
+