A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
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.
 
 
 
 
 

117 lines
3.4 KiB

  1. {{define "collections"}}
  2. {{template "header" .}}
  3. <div class="snug content-container">
  4. {{if .Flashes}}<ul class="errors">
  5. {{range .Flashes}}<li class="urgent">{{.}}</li>{{end}}
  6. </ul>{{end}}
  7. {{if .Silenced}}
  8. {{template "user-silenced"}}
  9. {{end}}
  10. <h1>Blogs</h1>
  11. <ul class="atoms collections">
  12. {{range $i, $el := .Collections}}<li class="collection">
  13. <div class="row lineitem">
  14. <div>
  15. <h3>
  16. <a class="title" href="/{{.Alias}}/" >{{if .Title}}{{.Title}}{{else}}{{.Alias}}{{end}}</a>
  17. <span class="electron" {{if .IsPrivate}}style="font-style: italic"{{end}}>{{if .IsPrivate}}private{{else}}{{.DisplayCanonicalURL}}{{end}}</span>
  18. </h3>
  19. {{template "collection-nav" (dict "Alias" .Alias "Path" $.Path "SingleUser" $.SingleUser "CanPost" true )}}
  20. {{if .Description}}<p class="description">{{.Description}}</p>{{end}}
  21. </div>
  22. </div>
  23. </li>{{end}}
  24. <li id="create-collection">
  25. {{if not .NewBlogsDisabled}}
  26. <form method="POST" action="/api/collections" id="new-collection-form" onsubmit="return createCollection()">
  27. <h4>
  28. <input type="text" name="title" placeholder="Blog name" id="blog-name">
  29. <input type="hidden" name="web" value="true" />
  30. <input type="submit" value="Create" id="create-collection-btn">
  31. </h4>
  32. </form>
  33. {{end}}
  34. </li>
  35. </ul>
  36. {{if not .NewBlogsDisabled}}<p style="margin-top:0"><a id="new-collection" href="#new-collection">New blog</a></p>{{end}}
  37. </div>
  38. {{template "foot" .}}
  39. <script src="/js/h.js"></script>
  40. <script>
  41. function createCollection() {
  42. var input = He.get('blog-name');
  43. if (input.value == "") {
  44. return false;
  45. }
  46. var form = He.get('new-collection-form');
  47. var submit = He.get('create-collection-btn');
  48. submit.value = "Creating...";
  49. submit.disabled = "disabled";
  50. He.postJSON("/api/collections", {
  51. title: input.value,
  52. web: true
  53. }, function(code, data) {
  54. if (data.code == 201) {
  55. location.reload();
  56. } else {
  57. var $createColl = document.getElementById('create-collection');
  58. var $submit = $createColl.querySelector('input[type=submit]');
  59. $submit.value = "Create";
  60. $submit.disabled = "";
  61. var $err = $createColl.querySelector('.error');
  62. if (data.code == 409) {
  63. if ($err === null) {
  64. var url = He.create('span');
  65. url.className = "error";
  66. url.innerText = "This name is taken.";
  67. $createColl.appendChild(url);
  68. } else {
  69. $err.innerText = "This name is taken.";
  70. }
  71. } else {
  72. if ($err === null) {
  73. var url = He.create('span');
  74. url.className = "error";
  75. url.innerText = data.error_msg;
  76. $createColl.appendChild(url);
  77. } else {
  78. $err.innerText = "This name is taken.";
  79. }
  80. }
  81. }
  82. });
  83. return false;
  84. };
  85. (function() {
  86. H.getEl('new-collection').on('click', function(e) {
  87. e.preventDefault();
  88. var collForm = He.get('create-collection');
  89. if (collForm.style.display == '' || collForm.style.display == 'none') {
  90. // Show form
  91. this.textContent = "Cancel";
  92. collForm.style.display = 'list-item';
  93. collForm.querySelector('input[type=text]').focus();
  94. return;
  95. }
  96. // Hide form
  97. this.textContent = "New blog";
  98. collForm.style.display = 'none';
  99. });
  100. if (location.hash == '#new-collection' || location.hash == '#new') {
  101. var collForm = He.get('create-collection');
  102. collForm.style.display = 'list-item';
  103. collForm.querySelector('input[type=text]').focus();
  104. He.get('new-collection').textContent = "Cancel";
  105. }
  106. }());
  107. </script>
  108. {{template "body-end" .}}
  109. {{end}}