diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js
index d3a18471..096a5e79 100644
--- a/Web/static/js/al_wall.js
+++ b/Web/static/js/al_wall.js
@@ -22,7 +22,7 @@ function trim(string) {
return newStr;
}
-function handleVideoTAreaUpdate(event, id) {
+/*function handleVideoTAreaUpdate(event, id) {
console.log(event, id);
let indicator = u("#post-buttons" + id + " .post-upload");
let file = event.target.files[0];
@@ -34,7 +34,7 @@ function handleVideoTAreaUpdate(event, id) {
}
document.querySelector("#post-buttons" + id + " #wallAttachmentMenu").classList.add("hidden");
-}
+}*/
function initGraffiti(id) {
let canvas = null;
@@ -43,16 +43,7 @@ function initGraffiti(id) {
let fName = "Graffiti-" + Math.ceil(performance.now()).toString() + ".jpeg";
let image = new File([blob], fName, {type: "image/jpeg", lastModified: new Date().getTime()});
- let formdata = new FormData()
- formdata.append("hash", u("meta[name=csrf]").attr("value"))
- formdata.append("count", 1)
-
- //ky.post("/photos/upload", {body:})
- let fileSelect = document.querySelector("#post-buttons" + id + " input[name='_pic_attachment']");
- fileSelect.files = trans.files;
-
- u(fileSelect).trigger("change");
- u("#post-buttons" + id + " #write textarea").trigger("focusin");
+ fastUploadImage(id, image)
}, "image/jpeg", 0.92);
canvas.teardown();
@@ -75,6 +66,61 @@ function initGraffiti(id) {
});
}
+function fastUploadImage(textareaId, file) {
+ // uploading images
+
+ let xhr = new XMLHttpRequest
+ let data = new FormData
+
+ data.append("photo_0", file)
+ data.append("count", 1)
+ data.append("hash", u("meta[name=csrf]").attr("value"))
+
+ xhr.open("POST", "/photos/upload")
+
+ xhr.onloadstart = () => {
+ document.querySelector("#post-buttons"+textareaId+" .upload").insertAdjacentHTML("beforeend", ``)
+ }
+
+ xhr.onload = () => {
+ let response = JSON.parse(xhr.responseText)
+
+ appendImage(response, textareaId)
+ }
+
+ xhr.send(data)
+}
+
+// append image after uploading via /photos/upload
+function appendImage(response, textareaId) {
+ if(!response.success) {
+ MessageBox(tr("error"), (tr("error_uploading_photo") + response.flash.message), [tr("ok")], [() => {Function.noop}])
+ } else {
+ let form = document.querySelector("#post-buttons"+textareaId)
+ let photosInput = form.querySelector("input[name='photos']")
+ let photosIndicator = form.querySelector(".upload")
+
+ for(const phot of response.photos) {
+ let id = phot.owner + "_" + phot.vid
+
+ photosInput.value += (id + ",")
+
+ u(photosIndicator).append(u(`
+