api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vanilla.html 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <script>
  5. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  6. alert("Your browser is too old to support HTML5 File API");
  7. }
  8. function showImagePreview() {
  9. var demoImage = document.querySelector('img#preview');
  10. var file = document.querySelector('input[type=file]').files[0];
  11. var reader = new FileReader();
  12. reader.onload = function (event) {
  13. console.log(reader.result)
  14. demoImage.src = reader.result;
  15. }
  16. console.log(file)
  17. reader.readAsDataURL(file);
  18. }
  19. function uploadImageFile() {
  20. var demoImage = document.querySelector('img#preview');
  21. var req = new XMLHttpRequest();
  22. req.onreadystatechange = function () {
  23. if (req.readyState==4) {
  24. console.log(req.responseText);
  25. listImageFiles();
  26. }
  27. }
  28. url = '/api.php/records/categories';
  29. req.open("POST", url);
  30. var icon = demoImage.src.split(";")[1].split(",")[1];
  31. req.send(JSON.stringify({"name":"upload","icon":icon}));
  32. }
  33. function listImageFiles() {
  34. var ul = document.querySelector('ul');
  35. var req = new XMLHttpRequest();
  36. req.onreadystatechange = function () {
  37. if (req.readyState==4) {
  38. console.log(req.responseText);
  39. output.innerHTML = "";
  40. var categories = JSON.parse(req.responseText).records;
  41. for (var i=0;i<categories.length;i++) {
  42. var li = document.createElement('li');
  43. var img = document.createElement('img');
  44. var span = document.createElement('span');
  45. img.style = 'height:2em;margin:0 .5em;';
  46. img.src = "data:image/png;base64," + categories[i].icon;
  47. span.innerHTML = categories[i].name;
  48. li.appendChild(img);
  49. li.appendChild(span);
  50. ul.appendChild(li);
  51. }
  52. }
  53. }
  54. url = '/api.php/records/categories';
  55. req.open("GET", url);
  56. req.send();
  57. }
  58. </script>
  59. </head>
  60. <body onload="listImageFiles()">
  61. <ul id="output"></ul>
  62. <hr>
  63. <form onsubmit="uploadImageFile(); return false;">
  64. <img src="" id="preview" style="height:2em;margin:0 .5em;" alt="PNG preview..."><br><br>
  65. <input type="file" onchange="showImagePreview()" accept="image/png"><br><br>
  66. <input type="submit" value="Upload PNG">
  67. </form>
  68. </body>
  69. </html>