Skip to content

Commit

Permalink
meme form update
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenweaver committed Nov 27, 2024
1 parent 967b22b commit 9637a1d
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions public/assets/js/meme/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
$(function () {
$("form").submit(function (e) {
e.preventDefault();

$("#file-progress").removeClass("hidden");

var formData = new FormData();
var file = document.getElementById("seq-file").files[0];
var filename = document.getElementById("seq-file").files[0].name;

formData.append("files", file);
formData.append("datatype", $("select[name='datatype']").val());
formData.append("gencodeid", $("select[name='gencodeid']").val());
formData.append("mail", $("input[name='mail']").val());

var action_url = $("#msa-form").attr("action");

var xhr = new XMLHttpRequest();

xhr.open("post", action_url, true);

xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
var percentage = (e.loaded / e.total) * 100;

$("#seq-file").css("display", "none");
$(".progress .progress-bar").css("width", percentage + "%");
}
};

xhr.onerror = function (e) {
$("#file-progress").html(e);
};

xhr.onload = function (res) {
// Replace field with green text, name of file
var result = JSON.parse(this.responseText);

if (_.has(result, "error")) {
$("#modal-error-msg").text(result.error);
$("#errorModal").modal();
$("#file-progress").css("display", "none");
$("#seq-file").css("display", "block");
$(".progress .progress-bar").css("width", "0%");
} else if ("error" in result.analysis) {
$("#modal-error-msg").text(result.analysis.error);
$("#errorModal").modal();
$("#file-progress").css("display", "none");
$("#seq-file").css("display", "block");
$(".progress .progress-bar").css("width", "0%");
} else if ("upload_redirect_path" in result) {
window.location.href = result.upload_redirect_path;
} else {
$("#modal-error-msg").text(
"We received data in an unexpected format from the server."
);
$("#errorModal").modal();
$("#file-progress").css("display", "none");
$("#seq-file").css("display", "block");
$(".progress .progress-bar").css("width", "0%");
}
};

xhr.send(formData);
});

$(".mail-group").change(datamonkey.helpers.validate_email);
});

0 comments on commit 9637a1d

Please sign in to comment.