This repository has been archived on 2025-02-20. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cavecomm/templates/templateIncludes/freelancerSubmissionUpload.js.html
2023-08-07 19:34:09 +02:00

75 lines
2.5 KiB
HTML

<script type="text/javascript">
var ajaxG;
function _(el) {
return document.getElementById(el);
}
function upload() {
var file = _("FILE_SUBMISSION").files[0];
const fileSize = file.size / 1024 / 1024;
const maxSize = {{MAXIMUM_STORAGE_IN_MB}} - {{USED_STORAGE_IN_MB}};
const maxFileNameLength = {{MAXIMUM_FILE_NAME_SIZE}};
console.log(maxSize);
console.log(maxFileNameLength);
if (fileSize > maxSize) {
alert('File size exceeds availible space by: ' + (Math.trunc((fileSize - maxSize) * 100) / 100) + ' MB');
unHide();
} else if(file.name.length > maxFileNameLength) {
alert('File name exceeds allowed length by ' + (file.name.length - maxFileNameLength) + ' characters');
unHide();
}
else {
var formdata = new FormData();
formdata.append("FILE_SUBMISSION", file);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler, false);
ajaxG = ajax;
ajax.open("POST", "/freelancer/submissionManagement/add/fulfillment");
ajax.send(formdata);
}
}
function progressHandler(event) {
_("loadedtotal").innerHTML = "Uploaded " + event.loaded + " bytes of " + event.total;
var percent = (event.loaded / event.total) * 100;
_("progressBar").value = Math.round(percent);
_("status").innerHTML = Math.round(percent) + "% uploaded... please wait";
}
function completeHandler(event) {
unHide();
_("status").innerHTML = event.target.responseText;
_("progressBar").value = 0;
}
function errorHandler(event) {
unHide();
_("status").innerHTML = "Upload Failed";
}
function abortHandler(event) {
unHide();
_("status").innerHTML = "Upload Aborted";
}
function hide() {
_("FILE_UPLOAD_BUTTON").style.display = 'none';
_("ABORT_FILE_UPLOAD_BUTTON").style.display = '';
}
function unHide() {
_("FILE_UPLOAD_BUTTON").style.display = '';
_("ABORT_FILE_UPLOAD_BUTTON").style.display = 'none';
}
function abort() {
ajaxG.abort();
ajaxG = null;
}
</script>