panosteal/server/static/worker.js

94 lines
2.9 KiB
JavaScript
Raw Normal View History

$("#options").hide();
2018-10-19 16:21:59 +00:00
$body = $("body");
function toggleOptions() {
$("#options").toggle();
}
2018-10-19 16:21:59 +00:00
function lockform() {
2018-10-21 09:07:03 +00:00
$("#theform :input").prop("disabled", true);
$body.addClass("loading");
2018-10-19 16:21:59 +00:00
}
function unlockform() {
2018-10-21 09:07:03 +00:00
$("#theform :input").prop("disabled", false);
$body.removeClass("loading");
2018-10-19 16:21:59 +00:00
}
2018-10-21 17:06:14 +00:00
function deletecard(jobid) {
if ( $("#" + jobid).length ) {
$("#" + jobid).remove();
};
}
2018-10-21 17:54:01 +00:00
function addcard(jobid, title) {
var text = '<div class="col-sm-3" id="' + jobid + '"> <div class="card"> <img class="card-img-top img-fluid" src="/spinner.gif" alt="Creating Image"><div style="text-align: center; font-weight: bold;" class="card-block">' + title + '</div> </div> </div>';
2018-10-21 17:06:14 +00:00
$('#cards').append(text);
2018-10-21 17:11:31 +00:00
$('html,body').animate({scrollTop: $('#' + jobid).offset().top});
2018-10-21 17:06:14 +00:00
}
2018-10-21 17:54:01 +00:00
function failcard(jobid, title) {
deletecard(jobid, title);
2018-10-21 17:06:14 +00:00
2018-10-21 17:54:01 +00:00
var text = '<div class="col-sm-3" id="' + jobid + '"> <div class="card"> <div style="text-align: center; color: red; font-weight: bold;" class="card-block">' + title + ': Export failed.</div><div style="text-align: center;" class="card-block"> <a style="color: white;" onclick="deletecard(\'' + jobid + '\');" class="btn btn-danger">Hide</a></div> </div> </div>';
2018-10-21 17:06:14 +00:00
$('#cards').append(text);
}
2018-10-21 17:54:01 +00:00
function finishcard(jobid, title) {
2018-10-21 17:06:14 +00:00
deletecard(jobid);
2018-10-21 17:54:01 +00:00
var text = '<div class="col-sm-3" id="' + jobid + '"> <div class="card"> <img class="card-img-top img-fluid" src="/getjob/' + jobid + '" alt="Final Image"><div style="text-align: center; font-weight: bold;" class="card-block">' + title + '</div> <div style="text-align: center; color: white;" class="card-block"> <a href="/getjob/' + jobid + '" class="btn btn-primary">Download</a> <a onclick="deletecard(\'' + jobid + '\');" class="btn btn-danger">Hide</a></div> </div> </div>';
2018-10-21 17:06:14 +00:00
$('#cards').append(text);
}
2018-10-19 16:21:59 +00:00
$('#theform').submit(function(event){
2018-10-21 09:07:03 +00:00
event.preventDefault();
if(this.checkValidity()) {
$.ajax({
type: "POST",
url: "/addjob",
data: $('#theform').serialize(),
success: function(msg){
2018-10-21 17:54:01 +00:00
var title = ($("#title").val() ? $("#title").val() : "No title");
var interval = setInterval(checkServerForFile,3000,msg, title);
2018-10-21 09:07:03 +00:00
window.panaxworking = false;
2018-10-21 17:54:01 +00:00
addcard(msg, title);
function checkServerForFile(jobid, title) {
2018-10-21 17:06:14 +00:00
2018-10-21 09:07:03 +00:00
if (!window.panaxworking) {
window.panaxworking = true;
$.ajax({
type: "GET",
cache: false,
url: "/getjob/" + jobid,
statusCode: {
404: function() {
clearInterval(interval);
2018-10-21 17:54:01 +00:00
failcard(jobid, title);
2018-10-21 17:06:14 +00:00
return;
2018-10-21 09:07:03 +00:00
},
200: function() {
clearInterval(interval);
2018-10-21 17:54:01 +00:00
finishcard(jobid, title);
2018-10-21 17:06:14 +00:00
return;
2018-10-21 09:07:03 +00:00
},
500: function() {
clearInterval(interval);
2018-10-21 17:54:01 +00:00
failcard(jobid, title);
2018-10-21 17:06:14 +00:00
return;
2018-10-21 09:07:03 +00:00
}
}
});
window.panaxworking = false;
};
}
2018-10-19 16:21:59 +00:00
2018-10-21 09:07:03 +00:00
}
});}
2018-10-19 16:21:59 +00:00
});