summaryrefslogtreecommitdiff
path: root/app/media/static/image-preview.js
diff options
context:
space:
mode:
authorlxf <sng@luxagraf.net>2022-05-14 16:38:07 -0400
committerlxf <sng@luxagraf.net>2022-05-14 16:38:07 -0400
commitbb3973ffb714c932e9ec6dd6a751228dc71fe1d3 (patch)
tree6fa32f9392ad2ec32271349b86a4c1388fd6ba95 /app/media/static/image-preview.js
initial commit
Diffstat (limited to 'app/media/static/image-preview.js')
-rw-r--r--app/media/static/image-preview.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/media/static/image-preview.js b/app/media/static/image-preview.js
new file mode 100644
index 0000000..b8fead5
--- /dev/null
+++ b/app/media/static/image-preview.js
@@ -0,0 +1,42 @@
+function build_image_preview () {
+ var url = window.location.href
+ var cur = url.split('/')[6];
+ if (cur) {
+ var container = document.createElement("div");
+ container.className = "form-row field-image";
+ var wrapper = document.createElement("div");
+ var label = document.createElement("label");
+ label.textContent = "Image:";
+ var pwrap = document.createElement("p");
+ var img = document.createElement("img");
+
+ var request = new XMLHttpRequest();
+ request.open('GET', '/photos/luximage/data/admin/preview/'+cur+'/', true);
+ request.onload = function() {
+ if (request.status >= 200 && request.status < 400) {
+ var data = JSON.parse(request.responseText);
+ //console.log(data);
+ img.src = data['url'];
+ } else {
+ console.log("server error");
+ }
+ };
+ request.onerror = function() {
+ console.log("error on request");
+ };
+ request.send();
+ pwrap.appendChild(img);
+ wrapper.appendChild(label);
+ wrapper.appendChild(pwrap);
+ container.appendChild(wrapper);
+ parent = document.getElementById("luximage_form");
+ node = parent.children[1].children[0];
+ node.parentNode.insertBefore(container, node.previousSibling);
+ } else {
+ return;
+ }
+}
+
+document.addEventListener("DOMContentLoaded", function(event) {
+ build_image_preview();
+});