Remove console log and keep the classic upload viewable
This commit is contained in:
parent
952f2ec584
commit
da657fcf60
2 changed files with 41 additions and 22 deletions
|
|
@ -42,17 +42,24 @@ document.getElementById('upload_form').addEventListener('submit', (e) => {
|
||||||
document.getElementById('submit-id-submit').value = "Please be patient";
|
document.getElementById('submit-id-submit').value = "Please be patient";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
submitbtn = document.getElementById('submit-id-submit');
|
submitbtn = document.getElementById('submit-id-submit');
|
||||||
submitbtn.type = "button";
|
//submitbtn.type = "button";
|
||||||
|
|
||||||
|
//submitbtn.addEventListener("click", uplaodfnc);
|
||||||
|
|
||||||
|
var ctnbtn = document.createElement("input");
|
||||||
|
ctnbtn.classList = submitbtn.classList;
|
||||||
|
ctnbtn.value="Continious Upload";
|
||||||
|
ctnbtn.type = "button";
|
||||||
|
|
||||||
async function uplaodfnc() {
|
async function uplaodfnc() {
|
||||||
|
|
||||||
console.log(uploadInput.files);
|
console.log(uploadInput.files);
|
||||||
files = uploadInput.files;
|
files = uploadInput.files;
|
||||||
submitbtn.disabled = true;
|
submitbtn.disabled = true;
|
||||||
|
ctnbtn.disabled = true;
|
||||||
actual = 0;
|
actual = 0;
|
||||||
submitbtn.value = "Please be patient 0% (" + actual + "/" + files.length + ")";
|
ctnbtn.value = "Please be patient 0% (" + actual + "/" + files.length + ")";
|
||||||
|
|
||||||
csrfvalue = document.getElementsByName("csrfmiddlewaretoken")[0].value;
|
csrfvalue = document.getElementsByName("csrfmiddlewaretoken")[0].value;
|
||||||
|
|
||||||
|
|
@ -66,17 +73,18 @@ async function uplaodfnc() {
|
||||||
|
|
||||||
fdata = new FormData(uploadInput.form);
|
fdata = new FormData(uploadInput.form);
|
||||||
fdata.delete("file_field");
|
fdata.delete("file_field");
|
||||||
fdata.append("reptype", "json");
|
//fdata.append("reptype", "json");
|
||||||
console.log(fdata);
|
|
||||||
|
|
||||||
response = await fetch("/upload/", {
|
response = await fetch("/upload/", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: fdata,
|
body: fdata,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
returned = await response.json();
|
returned = await response.json();
|
||||||
|
|
||||||
console.log(returned);
|
|
||||||
console.log(returned.code);
|
|
||||||
if (returned.code != 200) {
|
if (returned.code != 200) {
|
||||||
window.alert("There is an error in the form" + returned.error);
|
window.alert("There is an error in the form" + returned.error);
|
||||||
}
|
}
|
||||||
|
|
@ -87,20 +95,22 @@ async function uplaodfnc() {
|
||||||
sendform = new FormData();
|
sendform = new FormData();
|
||||||
sendform.append("csrfmiddlewaretoken", csrfvalue);
|
sendform.append("csrfmiddlewaretoken", csrfvalue);
|
||||||
sendform.append("file_field", file);
|
sendform.append("file_field", file);
|
||||||
sendform.append("reptype", "json");
|
//sendform.append("reptype", "json");
|
||||||
sendform.append("gallery", returned.galleryID);
|
sendform.append("gallery", returned.galleryID);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/upload/", {
|
const response = await fetch("/upload/", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: sendform,
|
body: sendform,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
okpass = await response.ok;
|
okpass = await response.ok;
|
||||||
console.log(file.name, okpass);
|
if (!okpass) {
|
||||||
if ( !okpass) {
|
|
||||||
window.alert("Error with " + file.name + "code" + await response.code);
|
window.alert("Error with " + file.name + "code" + await response.code);
|
||||||
}
|
}
|
||||||
submitbtn.value = "Please be patient " + Math.round(100 * actual / total) + "% (" + actual + "/" + files.length + ")";
|
ctnbtn.value = "Please be patient " + Math.round(100 * actual / total) + "% (" + actual + "/" + files.length + ")";
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
@ -110,22 +120,30 @@ async function uplaodfnc() {
|
||||||
|
|
||||||
fdata = new FormData(uploadInput.form);
|
fdata = new FormData(uploadInput.form);
|
||||||
fdata.delete("file_field");
|
fdata.delete("file_field");
|
||||||
fdata.append("reptype", "json");
|
fdata.delete("new_gallery_title");
|
||||||
fdata.append("end","end")
|
fdata.delete("new_galleru_date_start");
|
||||||
console.log(fdata);
|
fdata.delete("new_galleru_date_end");
|
||||||
|
//fdata.append("reptype", "json");
|
||||||
|
fdata.append("gallery", returned.galleryID);
|
||||||
|
fdata.append("end", "end")
|
||||||
|
|
||||||
response = await fetch("/upload/", {
|
response = await fetch("/upload/", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: fdata,
|
body: fdata,
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
returned = await response.json();
|
returned = await response.json();
|
||||||
|
|
||||||
submitbtn.value = "Upload Complete Please reload the page";
|
ctnbtn.value = "Upload Complete Please reload the page";
|
||||||
}
|
}
|
||||||
|
|
||||||
submitbtn.addEventListener("click", uplaodfnc);
|
|
||||||
|
|
||||||
console.log("New Upload File");
|
ctnbtn.addEventListener("click", uplaodfnc);
|
||||||
|
|
||||||
|
form.appendChild(ctnbtn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,11 +191,12 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
# Get or create gallery
|
# Get or create gallery
|
||||||
|
|
||||||
if form.data.get("reptype","")=="json":
|
if self.request.accepts('text/html') or not self.request.accepts('application/json'):
|
||||||
response_json = True
|
|
||||||
finish_json = form.data.get("end","")=="end"
|
|
||||||
else :
|
|
||||||
response_json = False
|
response_json = False
|
||||||
|
finish_json = False
|
||||||
|
else :
|
||||||
|
response_json = True
|
||||||
|
finish_json = form.data.get("end","") == "end"
|
||||||
|
|
||||||
gallery = form.get_or_create_gallery()
|
gallery = form.get_or_create_gallery()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue