panosteal/server/static/worker.js

106 lines
3.8 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);
}
2019-02-18 16:23:47 +00:00
function finishcard(jobid, title, video) {
2018-10-21 17:06:14 +00:00
deletecard(jobid);
2019-02-18 16:23:47 +00:00
if (!video) {
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>';
} else {
var text = '<div class="col-sm-3" id="' + jobid + '"> <div class="card"> <img class="card-img-top img-fluid" id="' + jobid + '-thumb" src="/getjob/' + jobid + '-thumb" alt="Final Video"><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);
2019-02-18 16:23:47 +00:00
var counter = 0;
var interval = setInterval(function() {
var image = document.getElementById(jobid + '-thumb');
image.src = "/getjob/" + jobid + "-thumb?rand=" + Math.random();
if (++counter === 10) {
window.clearInterval(interval);
}
}, 2000);
2018-10-21 17:06:14 +00:00
}
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,
2019-02-18 16:23:47 +00:00
url: "/getjob/" + jobid + "-info",
2018-10-21 09:07:03 +00:00
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
},
2019-02-18 16:23:47 +00:00
200: function(data, tstatus, xhr) {
2018-10-21 09:07:03 +00:00
clearInterval(interval);
2019-02-18 16:23:47 +00:00
finishcard(jobid, title, (xhr.getResponseHeader('content-type') == "image/png") ? false : true);
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
});