Browse Source

new post feature

pull/1/head
wes 8 years ago
parent
commit
ee252a87e5
  1. 26
      src/scripts/editor.tag

26
src/scripts/editor.tag

@ -14,6 +14,13 @@
</button> </button>
</li> </li>
</ul> </ul>
<button
class="btn btn-primary"
onclick={newPost}
>
New Post
</button>
<span>title</span><input ref="title"> <span>title</span><input ref="title">
<span>author</span><input ref="author"></input> <span>author</span><input ref="author"></input>
<span>Editing post {_id}</span> <span>Editing post {_id}</span>
@ -45,6 +52,8 @@ import 'whatwg-fetch';
import { default as showdown } from 'showdown'; import { default as showdown } from 'showdown';
import { default as R } from 'ramda'; import { default as R } from 'ramda';
import querystring from 'querystring'; import querystring from 'querystring';
import Z from './zipper.js';
this.R = R; this.R = R;
this.querystring = querystring; this.querystring = querystring;
@ -86,6 +95,15 @@ echo(ev) {
}); });
} }
newPost() {
this._id = false
this.refs.title.value = "";
this.refs.author.value = "";
this.refs.textarea.value = "";
this.echo();
this.update();
}
submit() { submit() {
var post = { var post = {
"title" : this.refs.title.value, "title" : this.refs.title.value,
@ -109,26 +127,26 @@ submit() {
axios.post("/blog/insert/", postQuery, headers) axios.post("/blog/insert/", postQuery, headers)
.then(function(resp) { .then(function(resp) {
console.log(resp); /* Refresh the current list of posts */
self._id = resp.data[0];
self.listPosts(); self.listPosts();
}) })
.catch(function(err) { .catch(function(err) {
console.log(err); console.log(err);
}) })
console.log("Submitting the post");
console.log(post);
} }
loadPost(_id) { loadPost(_id) {
return function() { return function() {
axios.get(`/blog/getpost/${_id}`) axios.get(`/blog/getpost/${_id}`)
.then(function(resp) { .then(function(resp) {
self.refs.textarea.value = resp.data.content; self.refs.textarea.value = resp.data.content;
self.refs.title.value = resp.data.title; self.refs.title.value = resp.data.title;
self.refs.author.value = resp.data.author; self.refs.author.value = resp.data.author;
self._id = _id; self._id = _id;
self.focused = true; self.focused = true;
self.update(); self.update();
self.echo(); self.echo();
}) })

Loading…
Cancel
Save