note.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. {% extends "layout.html" %}
  2. {% block title %}{% if note.title.len() > 0 %}{{note.title}}{%else%}Create Note{% endif %}{% endblock %}
  3. {% block description %}{{note.content}}{% endblock %}
  4. {% block head %}
  5. <link rel="stylesheet" defer href="https://unpkg.com/easymde/dist/easymde.min.css">
  6. {% endblock %}
  7. pub association_type: AssociationType,
  8. pub association_key: uuid::Uuid,
  9. {% block content %}
  10. <div class="container">
  11. <div class="row justified">
  12. <div class="content">
  13. <div class="backed col-sm-12 col-md-12 col-lg-12">
  14. {% if note.key.to_string() != "00000000-0000-0000-0000-000000000000" %}
  15. <button id="delete" class="delete_button center">🗑️ Delete</button>
  16. {% endif %}
  17. <form id="add_note_form">
  18. <h1 name="title" id="title" contentEditable="true">{% if note.title.len() ==
  19. 0%}Title{%else%}{{note.title}}{% endif %}</h1>
  20. <textarea name="content" id="note_area_md">{{note.content}}</textarea>
  21. <input type="submit" class="add_button"
  22. value="{% if note.title.len() == 0%}Create Note!{%else%}Update Note{% endif %}" />
  23. </form>
  24. </div>
  25. </div>
  26. </div>
  27. <script src="/fs/js/easymde@2.18.0.min.js"></script>
  28. <script>
  29. window.addEventListener('load', function () {
  30. {% if note.key.to_string() != "00000000-0000-0000-0000-000000000000" %}
  31. send_delete("delete", "/note/{{note.key}}", (deleted, res) => {
  32. if (deleted) {
  33. let type = "{{note.association_type.to_string()}}".toLowerCase()
  34. window.location.href = `/${type}/{{note.association_key}}`
  35. }
  36. })
  37. {% endif %}
  38. const easyMDE = new EasyMDE({ element: document.getElementById('note_area_md') });
  39. const title = document.getElementById('title');
  40. post_form("add_note_form", "/note", data => {
  41. const key = "{{note.key}}"
  42. data.key = key == "" ? "00000000-0000-0000-0000-000000000000" : key
  43. data.organization_key = "{{user.organization_key}}"
  44. data.owner_key = "{{user.key}}"
  45. data.association_type = "{{note.association_type.to_string()}}";
  46. data.association_key = "{{note.association_key}}";
  47. data.url = data.url || "";
  48. data.title = title.innerHTML;
  49. data.content = data.content || "";
  50. data.created = data.created || 0;
  51. data.updated = data.updated || 0;
  52. return data;
  53. }, (response_text) => {
  54. const object = JSON.parse(response_text);
  55. window.location.href = `/note/${object.key}`
  56. });
  57. })
  58. </script>
  59. {% endblock %}