Browse Source

try to auto-load posts to edit

pull/1/head
wes 8 years ago
parent
commit
a9f5bdd87c
  1. 16
      src/scripts/editor.tag

16
src/scripts/editor.tag

@ -6,11 +6,6 @@
<span> <span>
{this.currentPost().title} by {this.currentPost().author} {this.currentPost().title} by {this.currentPost().author}
</span> </span>
<button
class="btn btn-primary"
onclick={loadPost(this.currentPost()._id)}>
Load it
</button>
</div> </div>
<button <button
class="btn btn-primary" class="btn btn-primary"
@ -78,8 +73,6 @@ this.querystring = querystring;
this.converter = new showdown.Converter(); this.converter = new showdown.Converter();
this.converted = "<h3>Nothing here yet</h3>"; this.converted = "<h3>Nothing here yet</h3>";
this._id = false;
this.placeholderText = "Write a post!" this.placeholderText = "Write a post!"
this.placeholder = this.placeholderText; this.placeholder = this.placeholderText;
this.focused = false; this.focused = false;
@ -100,10 +93,12 @@ currentPost() {
goRight() { goRight() {
self.update({"currentPosts" : Z.goRight(self.currentPosts)}); self.update({"currentPosts" : Z.goRight(self.currentPosts)});
self.one("updated", self.loadPost(this.currentPost()._id));
} }
goLeft() { goLeft() {
self.update({"currentPosts" : Z.goLeft(self.currentPosts)}); self.update({"currentPosts" : Z.goLeft(self.currentPosts)});
self.one("updated", self.loadPost(this.currentPost()._id));
} }
clearplaceholder() { clearplaceholder() {
@ -132,7 +127,6 @@ echo(ev) {
} }
newPost() { newPost() {
this._id = false
this.refs.title.value = ""; this.refs.title.value = "";
this.refs.author.value = ""; this.refs.author.value = "";
this.refs.textarea.value = ""; this.refs.textarea.value = "";
@ -148,8 +142,8 @@ submit() {
"csrf_token" : this.opts.csrf_token "csrf_token" : this.opts.csrf_token
}; };
if (this._id) { if (this.currentPost()._id) {
post["_id"] = this._id; post["_id"] = this.currentPost()._id;
} }
var postQuery = self.querystring.stringify(post); var postQuery = self.querystring.stringify(post);
@ -164,7 +158,6 @@ submit() {
axios.post("/blog/insert/", postQuery, headers) axios.post("/blog/insert/", postQuery, headers)
.then(function(resp) { .then(function(resp) {
/* Refresh the current list of posts */ /* Refresh the current list of posts */
self._id = resp.data[0];
self.listPosts(); self.listPosts();
console.log(Z.toJS(self.currentPosts)); console.log(Z.toJS(self.currentPosts));
}) })
@ -181,7 +174,6 @@ loadPost(_id) {
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.focused = true; self.focused = true;
self.update(); self.update();

Loading…
Cancel
Save