Rewrite article publication with the REST API

- Add a default App and ApiToken for each user, that is used by the front-end
- Add an API route to update an article (CSRF had to be disabled because of a bug in rocket_csrf)
- Use AJAX to publish and edit articles in the new editor, instead of weird hacks with HTML forms
This commit is contained in:
Ana Gelez
2019-08-03 23:04:25 +02:00
parent 4142e73018
commit cc998e7c61
17 changed files with 372 additions and 162 deletions
+12 -2
View File
@@ -9,9 +9,19 @@
@use routes::posts::NewPostForm;
@use routes::*;
@(ctx: BaseContext, title: String, blog: Blog, editing: bool, form: &NewPostForm, is_draft: bool, article: Option<Post>, errors: ValidationErrors, medias: Vec<Media>, content_len: u64)
@(ctx: BaseContext, title: String, blog: Blog, editing: bool, form: &NewPostForm, is_draft: bool, article: Option<Post>, errors: ValidationErrors, medias: Vec<Media>, content_len: u64, api_token: String)
@:base(ctx, title.clone(), {}, {}, {
<script>
window.blog_id = @blog.id
window.api_token = '@api_token'
@if editing {
window.editing = true
window.post_id = @article.clone().unwrap().id
} else {
window.editing = false
}
</script>
<div id="plume-editor" style="display: none;" dir="auto">
<header>
<a href="#" id="close-editor">@i18n!(ctx.1, "Classic editor (any changes will be lost)")</a>
@@ -34,7 +44,7 @@
<a href="#" id="cancel-publish">@i18n!(ctx.1, "Cancel")</a>
<p>@i18n!(ctx.1, "You are about to publish this article in {}"; &blog.title)</p>
<button id="confirm-publish" class="button">@i18n!(ctx.1, "Confirm publication")</button>
<button id="draft" class="button secondary">@i18n!(ctx.1, "Save as draft")</button>
<button id="save-draft" class="button secondary">@i18n!(ctx.1, "Save as draft")</button>
</div>
</aside>
</div>