diff options
Diffstat (limited to 'public')
| -rw-r--r-- | public/js/panel.js | 74 | ||||
| -rw-r--r-- | public/js/upload.js | 36 |
2 files changed, 97 insertions, 13 deletions
diff --git a/public/js/panel.js b/public/js/panel.js index e69de29..bc10b0b 100644 --- a/public/js/panel.js +++ b/public/js/panel.js @@ -0,0 +1,74 @@ +window.onload = function () { + + if(!localStorage.token) + return; + + var page = document.getElementById('page'); + + prepareMenu(); + + function prepareMenu(){ + document.getElementById('itemUploads').addEventListener('click', function(){ + getUploads(); + }); + + document.getElementById('itemManageGallery').addEventListener('click', function(){ + getGalleries(); + }); + } + + function getUploads(){ + page.innerHTML = ''; + var xhr = new XMLHttpRequest(); + + xhr.onreadystatechange = function() { + if(xhr.readyState == XMLHttpRequest.DONE){ + if(xhr.responseText !== 'not-authorized'){ + var json = JSON.parse(xhr.responseText); + + var container = document.createElement('div'); + container.innerHTML = ` + <table class="table"> + <thead> + <tr> + <th>File</th> + <th>Gallery</th> + <th>Date</th> + </tr> + </thead> + <tbody id="table"> + </tbody> + </table>`; + page.appendChild(container); + + var table = document.getElementById('table'); + + for(var item of json){ + + var tr = document.createElement('tr'); + tr.innerHTML = ` + <tr> + <th><a href="${item.file}" target="_blank">${item.file}</a></th> + <th>${item.gallery}</th> + <td>${item.date}</td> + </tr> + `; + + table.appendChild(tr); + } + } + } + } + xhr.open('GET', '/api/uploads', true); + xhr.setRequestHeader('auth', localStorage.token); + xhr.send(null); + } + + function getContent(item, value){ + let endpoint; + if(item === 'uploads') endpoint = '/api/uploads' + if(item === 'galleries') endpoint = '/api/uploads' + + } + +} diff --git a/public/js/upload.js b/public/js/upload.js index be15ace..699506c 100644 --- a/public/js/upload.js +++ b/public/js/upload.js @@ -21,8 +21,8 @@ window.onload = function () { if(!localStorage.token){ document.getElementById('tokenContainer').style.display = 'flex' - document.getElementById("tokenSubmit").addEventListener("click", function(){ - getInfo(document.getElementById("token").value) + document.getElementById('tokenSubmit').addEventListener('click', function(){ + getInfo(document.getElementById('token').value) }); }else{ getInfo(localStorage.token); @@ -32,8 +32,8 @@ window.onload = function () { function prepareDropzone(){ - var previewNode = document.querySelector("#template"); - previewNode.id = ""; + var previewNode = document.querySelector('#template'); + previewNode.id = ''; var previewTemplate = previewNode.parentNode.innerHTML; previewNode.parentNode.removeChild(previewNode); @@ -52,26 +52,36 @@ window.onload = function () { 'auth': localStorage.token }, init: function() { - this.on("addedfile", function(file) { + this.on('addedfile', function(file) { document.getElementById('uploads').style.display = 'block'; }); } }); // Update the total progress bar - dropzone.on("uploadprogress", function(file, progress) { - file.previewElement.querySelector(".progress").style.width = progress + "%"; + dropzone.on('uploadprogress', function(file, progress) { + file.previewElement.querySelector('.progress').style.width = progress + '%'; }); - dropzone.on("success", function(file, response) { + dropzone.on('success', function(file, response) { + // Handle the responseText here. For example, add the text to the preview element: + + if(response.success === false){ + var span = document.createElement('span'); + span.innerHTML = response.description; + file.previewTemplate.querySelector('.link').appendChild(span); + return; + } + a = document.createElement('a'); - a.href = response.url; + a.href = response.files[0].url; a.target = '_blank'; - a.innerHTML = response.url; - - file.previewTemplate.querySelector(".progress").style.display = 'none'; - file.previewTemplate.querySelector(".link").appendChild(a); + a.innerHTML = response.files[0].url; + file.previewTemplate.querySelector('.link').appendChild(a); + + file.previewTemplate.querySelector('.progress').style.display = 'none'; + }); } |