A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

149 linhas
5.1 KiB

  1. {{define "articles"}}
  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 .Suspended}}
  8. {{template "user-suspended"}}
  9. {{end}}
  10. <h2 id="posts-header">drafts</h2>
  11. {{ if .AnonymousPosts }}<div class="atoms posts">
  12. {{ range $el := .AnonymousPosts }}<div id="post-{{.ID}}" class="post">
  13. <h3><a href="/{{if $.SingleUser}}d/{{end}}{{.ID}}" itemprop="url">{{.DisplayTitle}}</a></h3>
  14. <h4>
  15. <date datetime="{{.Created}}" pubdate itemprop="datePublished" content="{{.Created}}">{{.DisplayDate}}</date>
  16. <a class="action" href="/{{if $.SingleUser}}d/{{end}}{{.ID}}/edit">edit</a>
  17. <a class="delete action" href="/{{.ID}}" onclick="delPost(event, '{{.ID}}', true)">delete</a>
  18. {{ if $.Collections }}
  19. {{if gt (len $.Collections) 1}}<div class="action flat-select">
  20. <select id="move-{{.ID}}" onchange="postActions.multiMove(this, '{{.ID}}', {{if $.SingleUser}}true{{else}}false{{end}})" title="Move this post to one of your blogs">
  21. <option style="display:none"></option>
  22. {{range $.Collections}}<option value="{{.Alias}}">{{.DisplayTitle}}</option>{{end}}
  23. </select>
  24. <label for="move-{{.ID}}">move to...</label>
  25. <img class="ic-18dp" src="/img/ic_down_arrow_dark@2x.png" />
  26. </div>{{else}}
  27. {{range $.Collections}}
  28. <a class="action" href="/{{$el.ID}}" title="Publish this post to your blog '{{.DisplayTitle}}'" onclick="postActions.move(this, '{{$el.ID}}', '{{.Alias}}', {{if $.SingleUser}}true{{else}}false{{end}});return false">move to {{.DisplayTitle}}</a>
  29. {{end}}
  30. {{end}}
  31. {{ end }}
  32. </h4>
  33. {{if .Summary}}<p>{{.Summary}}</p>{{end}}
  34. </div>{{end}}
  35. </div>{{ else }}<div id="no-posts-published"><p>You haven't saved any drafts yet.</p>
  36. <p>They'll show up here once you do. {{if not .SingleUser}}Find your blog posts from the <a href="/me/c/">Blogs</a> page.{{end}}</p>
  37. <p class="text-cta"><a href="{{if .SingleUser}}/me/new{{else}}/{{end}}">Start writing</a></p></div>{{ end }}
  38. <div id="moving"></div>
  39. <h2 id="unsynced-posts-header" style="display: none">unsynced posts</h2>
  40. <div id="unsynced-posts-info" style="margin-top: 1em"></div>
  41. <div id="unsynced-posts" class="atoms"></div>
  42. </div>
  43. <script src="/js/h.js"></script>
  44. <script src="/js/postactions.js"></script>
  45. <script>
  46. var auth = true;
  47. function postsLoaded(n) {
  48. if (n == 0) {
  49. return;
  50. }
  51. document.getElementById('unsynced-posts-header').style.display = 'block';
  52. var syncing = false;
  53. var $pInfo = document.getElementById('unsynced-posts-info');
  54. $pInfo.className = 'alert info';
  55. var plural = n != 1;
  56. $pInfo.innerHTML = '<p>You have <strong>'+n+'</strong> post'+(plural?'s that aren\'t':' that isn\'t')+' synced to your account yet. <a href="#" id="btn-sync">Sync '+(plural?'them':'it')+' now</a>.</p>';
  57. var $noPosts = document.getElementById('no-posts-published');
  58. if ($noPosts != null) {
  59. $noPosts.style.display = 'none';
  60. document.getElementById('posts-header').style.display = 'none';
  61. }
  62. H.getEl('btn-sync').on('click', function(e) {
  63. e.preventDefault();
  64. if (syncing) {
  65. return;
  66. }
  67. var http = new XMLHttpRequest();
  68. var params = [];
  69. var posts = JSON.parse(H.get('posts', '[]'));
  70. if (posts.length > 0) {
  71. for (var i=0; i<posts.length; i++) {
  72. params.push({id: posts[i].id, token: posts[i].token});
  73. }
  74. }
  75. this.style.fontWeight = 'bold';
  76. this.innerText = 'Syncing '+(plural?'them':'it')+' now...';
  77. http.open("POST", "/api/posts/claim", true);
  78. // Send the proper header information along with the request
  79. http.setRequestHeader("Content-type", "application/json");
  80. http.onreadystatechange = function() {
  81. if (http.readyState == 4) {
  82. syncing = false;
  83. this.innerText = 'Importing '+(plural?'them':'it')+' now...';
  84. if (http.status == 200) {
  85. var res = JSON.parse(http.responseText);
  86. if (res.data.length > 0) {
  87. if (res.data.length != posts.length) {
  88. // TODO: handle something that royally fucked up
  89. console.error("Request and result array length didn't match!");
  90. return;
  91. }
  92. for (var i=0; i<res.data.length; i++) {
  93. if (res.data[i].code == 200) {
  94. // Post successfully claimed.
  95. for (var j=0; j<posts.length; j++) {
  96. // Find post in local store
  97. if (posts[j].id == res.data[i].post.id) {
  98. // Remove this post
  99. posts.splice(j, 1);
  100. break;
  101. }
  102. }
  103. } else {
  104. for (var j=0; j<posts.length; j++) {
  105. // Find post in local store
  106. if (posts[j].id == res.data[i].id) {
  107. // Note the error in the local post
  108. posts[j].error = res.data[i].error_msg;
  109. break;
  110. }
  111. }
  112. }
  113. }
  114. H.set('posts', JSON.stringify(posts));
  115. location.reload();
  116. }
  117. } else {
  118. // TODO: handle error visually (option to retry)
  119. console.error("Didn't work at all, man.");
  120. this.style.fontWeight = 'normal';
  121. this.innerText = 'Sync '+(plural?'them':'it')+' now';
  122. }
  123. }
  124. }
  125. http.send(JSON.stringify(params));
  126. syncing = true;
  127. });
  128. }
  129. </script>
  130. <script src="/js/posts.js"></script>
  131. {{template "footer" .}}
  132. {{end}}