Browse Source

basic grabbing of posts for editing

pull/1/head
wes 8 years ago
parent
commit
dcca02c217
  1. 3
      src/posts.py
  2. 30
      src/scripts/editor.tag
  3. 4
      src/website.py

3
src/posts.py

@ -39,3 +39,6 @@ class Posts:
}) })
return jsonify(posts) return jsonify(posts)
def getpost(self, _id):
return jsonify(self.db[_id])

30
src/scripts/editor.tag

@ -2,6 +2,14 @@
<div class="centered container"> <div class="centered container">
<div class="columns"> <div class="columns">
<div class="column col-6"> <div class="column col-6">
<ul>
<li each={this.currentPosts}>
<p>
{title} by {author}, id = {_id}
</p>
<button onclick={loadPost(this._id)}>Load it</button>
</li>
</ul>
<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>
<textarea onfocus={clearplaceholder} <textarea onfocus={clearplaceholder}
@ -42,6 +50,9 @@ this.placeholderText = "Write a post!"
this.placeholder = this.placeholderText; this.placeholder = this.placeholderText;
this.focused = false; this.focused = false;
this.currentPosts = [];
var self = this;
clearplaceholder() { clearplaceholder() {
if (!this.focused) { if (!this.focused) {
this.update({ this.update({
@ -68,8 +79,6 @@ echo(ev) {
}); });
} }
var self = this; /* Why do we need this??????????? */
submit() { submit() {
var post = self.querystring.stringify({ var post = self.querystring.stringify({
"title" : this.refs.title.value, "title" : this.refs.title.value,
@ -97,10 +106,25 @@ submit() {
console.log(post); console.log(post);
} }
loadPost(_id) {
return function() {
axios.get(`/blog/getpost/${_id}`)
.then(function(resp) {
self.refs.textarea.value = resp.data.content;
self.focused = true;
self.update();
self.echo();
})
.catch(function(err) {
console.log(err);
})
};
}
listPosts() { listPosts() {
axios.get("/blog/allposts") axios.get("/blog/allposts")
.then(function(resp) { .then(function(resp) {
console.log(resp); self.update({"currentPosts" : resp.data});
}) })
.catch(function(err) { .catch(function(err) {
console.log(err); console.log(err);

4
src/website.py

@ -97,6 +97,10 @@ def NeverWhere(configfile=None):
def allposts(): def allposts():
return posts.allposts() return posts.allposts()
@app.route("/blog/getpost/<_id>")
def getpost(_id):
return posts.getpost(_id)
# editor routes # editor routes
@app.route("/blog/editor/", methods=("GET", "POST")) @app.route("/blog/editor/", methods=("GET", "POST"))

Loading…
Cancel
Save