file.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {% extends "layout.html" %}
  2. {% block title %}{% if file.name.len() > 0 %}{{file.name}}{%else%}Add File{% endif %}{% endblock %}
  3. {% block description %}{{file.description}}{% endblock %}
  4. {% block content %}
  5. <div class="container">
  6. <div class="row justified">
  7. <div class="backed col-sm-12 col-md-12 col-lg-12">
  8. <h1>{{file.name}}</h1>
  9. <a href="/files/{{file.format}}/{{file.organization_key}}/{{file.association_type.to_string()}}/{{file.association_key}}/{{file.name}}">
  10. <img height="128" width="128" alt="📄 View Document" src="/files/{{file.format}}/{{file.organization_key}}/{{file.association_type.to_string()}}/{{file.association_key}}/{{file.name}}"/>
  11. </a>
  12. {% if file.key.to_string() != "00000000-0000-0000-0000-000000000000" %}
  13. <button id="delete" class="delete_button center">🗑️ Delete</button>
  14. {% endif %}
  15. <div class="row justified">
  16. <div class="content">
  17. <form id="add_file_form" action="/file" method="post" enctype="multipart/form-data">
  18. {% if file.key.to_string() == "00000000-0000-0000-0000-000000000000" %}\
  19. <p>
  20. <label>Add file: </label><br />
  21. <input id="file_uploader" type="file" name="file" />
  22. </p>
  23. {% endif %}
  24. <div class="col-sm-12 col-md-12 col-lg-12">
  25. <label for="name">Name</label>
  26. <input type="text" name="name" id="name" placeholder="File Name" value="{{file.name}}" />
  27. </div>
  28. <div class="col-sm-12 col-md-12 col-lg-12">
  29. <label for="tags">Tags</label>
  30. <input type="text" name="tags" id="tags" placeholder="Tags" value="{{file.tags}}" />
  31. </div>
  32. <input type="text" style="display:none" name="key" id="key" value="{{file.key}}" />
  33. <input type="text" style="display:none" name="organization_key" id="organization_key" value="{{file.organization_key}}" />
  34. <input type="text" style="display:none" name="association_type" id="association_type"
  35. value="{{file.association_type.to_string()}}" />
  36. <input type="text" style="display:none" name="association_key" id="association_key"
  37. value="{{file.association_key}}" />
  38. <input type="text" style="display:none" name="url" id="url" value="{{file.url}}" />
  39. <input type="text" style="display:none" name="format" id="format" value="{{file.format}}" />
  40. <input type="text" style="display:none" name="hash" id="hash" value="{{file.hash}}" />
  41. <input type="text" style="display:none" name="size" id="size" value="{{file.size}}" />
  42. <div>
  43. <label for="description">Description</label>
  44. <textarea name="description" id="description" placeholder="Description"
  45. value="{{file.description}}">{{file.description}}</textarea>
  46. </div>
  47. <div>
  48. <input type="submit" class="add_button"
  49. value="{% if file.key.is_nil() %}Create file!{%else%}Update file{% endif %}" />
  50. </div>
  51. </form>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. <script>
  58. window.addEventListener('load', function () {
  59. document.getElementById("file_uploader").onchange = function(e) {
  60. const files = event.target.files
  61. if (files && files.length > 0) {
  62. const filename = files[0].name
  63. const extension = files[0].type
  64. const splits = extension.split("/");
  65. const name_input = document.getElementById("name")
  66. name_input.value = filename
  67. if (splits && splits.length > 0) {
  68. const format_input = document.getElementById("format")
  69. format_input.value = splits[1]
  70. }
  71. }
  72. };
  73. {% if file.key.to_string() != "00000000-0000-0000-0000-000000000000" %}
  74. send_delete("delete", "/file/{{file.key}}", (deleted, res) => {
  75. if (deleted) {
  76. window.location.href = `/{{file.association_type.to_string().to_lowercase()}}/{{file.association_key}}`
  77. }
  78. })
  79. {% endif %}
  80. })
  81. </script>
  82. {% endblock %}