panel.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. window.onload = function () {
  2. if(!localStorage.token)
  3. return;
  4. var page = document.getElementById('page');
  5. prepareMenu();
  6. function prepareMenu(){
  7. document.getElementById('itemUploads').addEventListener('click', function(){
  8. getUploads();
  9. });
  10. document.getElementById('itemManageGallery').addEventListener('click', function(){
  11. getGalleries();
  12. });
  13. }
  14. function getUploads(){
  15. page.innerHTML = '';
  16. var xhr = new XMLHttpRequest();
  17. xhr.onreadystatechange = function() {
  18. if(xhr.readyState == XMLHttpRequest.DONE){
  19. if(xhr.responseText !== 'not-authorized'){
  20. var json = JSON.parse(xhr.responseText);
  21. var container = document.createElement('div');
  22. container.innerHTML = `
  23. <table class="table">
  24. <thead>
  25. <tr>
  26. <th>File</th>
  27. <th>Gallery</th>
  28. <th>Date</th>
  29. </tr>
  30. </thead>
  31. <tbody id="table">
  32. </tbody>
  33. </table>`;
  34. page.appendChild(container);
  35. var table = document.getElementById('table');
  36. for(var item of json){
  37. var tr = document.createElement('tr');
  38. tr.innerHTML = `
  39. <tr>
  40. <th><a href="${item.file}" target="_blank">${item.file}</a></th>
  41. <th>${item.gallery}</th>
  42. <td>${item.date}</td>
  43. </tr>
  44. `;
  45. table.appendChild(tr);
  46. }
  47. }
  48. }
  49. }
  50. xhr.open('GET', '/api/uploads', true);
  51. xhr.setRequestHeader('auth', localStorage.token);
  52. xhr.send(null);
  53. }
  54. function getContent(item, value){
  55. let endpoint;
  56. if(item === 'uploads') endpoint = '/api/uploads'
  57. if(item === 'galleries') endpoint = '/api/uploads'
  58. }
  59. }