diff options
| -rw-r--r-- | bucky/app/bucky.js | 1 | ||||
| -rw-r--r-- | bucky/app/router.js | 38 | ||||
| -rw-r--r-- | public/assets/js/lib/router.js | 30 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/editcomment.js | 42 | ||||
| -rw-r--r-- | views/pages/editcomment.ejs | 21 | ||||
| -rw-r--r-- | views/partials/scripts.ejs | 1 |
6 files changed, 105 insertions, 28 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index ce02b24..2689c4b 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -191,6 +191,7 @@ var bucky = module.exports = { } db.getCommentById(id).then(function(comment){ if (comment) { + comment.set('comment', comment.get('comment').toString()) res.comment = comment next() } diff --git a/bucky/app/router.js b/bucky/app/router.js index e5890ca..2383ab2 100644 --- a/bucky/app/router.js +++ b/bucky/app/router.js @@ -43,6 +43,9 @@ module.exports = function(app){ res.render("pages/post", {title: "Start a new thread" }) } ) + app.get("/comment/:id/edit", middleware.ensureAuthenticated, function(req, res){ + res.render("pages/editcomment", {}) + }) app.get("/api/index", bucky.ensureLastlog, @@ -58,8 +61,7 @@ module.exports = function(app){ hootbox: res.hootbox, lastlog: res.lastlog, }) - } - ) + }) app.get("/api/keyword/:keyword", bucky.ensureLastlog, @@ -76,8 +78,7 @@ module.exports = function(app){ hootbox: res.hootbox, lastlog: res.lastlog, }) - } - ) + }) app.get("/api/thread/:id", middleware.ensureAuthenticated, bucky.ensureThread, @@ -91,8 +92,7 @@ module.exports = function(app){ files: res.files, keyword: res.keyword, }) - } - ) + }) app.post("/api/thread", middleware.ensureAuthenticated, multer.array("files"), @@ -102,7 +102,7 @@ module.exports = function(app){ bucky.createOptionalComment, function(req, res){ res.json(res.thread) - }) + }) app.post("/api/thread/:id/comment", middleware.ensureAuthenticated, bucky.ensureThread, @@ -115,15 +115,13 @@ module.exports = function(app){ res.json({ comment: res.comment }) - }) - app.delete("/api/thread/:id", + }) + app.get("/api/comment/:id", middleware.ensureAuthenticated, - bucky.ensureThread, -// bucky.destroyThread, + bucky.ensureComment, function(req, res){ - // delete a thread - res.send(200) - }) + res.json({ comment: res.comment }) + }) // edit a comment app.put("/api/comment/:id", middleware.ensureAuthenticated, @@ -131,8 +129,8 @@ module.exports = function(app){ bucky.checkCommentPrivacy, bucky.updateComment, function(req, res){ - res.send(200) - }) + res.json({ comment: res.comment }) + }) // delete a comment app.delete("/api/comment/:id", middleware.ensureAuthenticated, @@ -142,6 +140,14 @@ module.exports = function(app){ function(req, res){ console.log("BUAHLAHA") res.send(200) + }) + app.delete("/api/thread/:id", + middleware.ensureAuthenticated, + bucky.ensureThread, +// bucky.destroyThread, + function(req, res){ + // delete a thread + res.send(200) }) app.get("/search/", diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js index 6802a86..27c8617 100644 --- a/public/assets/js/lib/router.js +++ b/public/assets/js/lib/router.js @@ -3,18 +3,19 @@ var SiteRouter = Router.extend({ el: "body", routes: { - "/": 'login', - "/index/:keyword": 'index', - "/index": 'index', - "/login": 'login', - "/details/:id": 'details', - "/post": 'post', - "/post/:keyword": 'post', - "/search": 'search', - "/mail": 'mailbox', - "/mail/:mailbox": 'mailbox', - "/mail/compose": 'compose', - "/message/:id": 'message', + "/": 'login', + "/index/:keyword": 'index', + "/index": 'index', + "/login": 'login', + "/details/:id": 'details', + "/post": 'post', + "/post/:keyword": 'post', + "/search": 'search', + "/mail": 'mailbox', + "/mail/:mailbox": 'mailbox', + "/mail/compose": 'compose', + "/message/:id": 'message', + "/comment/:id/edit": 'editComment', }, initialize: function(){ @@ -34,6 +35,11 @@ var SiteRouter = Router.extend({ app.view.load(id) }, + editComment: function(id){ + app.view = new EditCommentForm () + app.view.load(id) + }, + mailbox: function(box){ app.view = new MailboxView () app.view.load(box) diff --git a/public/assets/js/lib/views/details/editcomment.js b/public/assets/js/lib/views/details/editcomment.js new file mode 100644 index 0000000..1e1474f --- /dev/null +++ b/public/assets/js/lib/views/details/editcomment.js @@ -0,0 +1,42 @@ +var EditCommentForm = FormView.extend({ + + el: "#comment_form", + + events: { + "focus textarea": 'focus', + }, + + action: "", + + initialize: function(){ + this.__super__.initialize.call(this) + this.template = this.$(".template").html() + this.$comment = this.$("[name=comment]") + }, + + load: function(id){ + this.action = "/api/comment/" + id + $.get(this.action, function(data){ + console.log(data) + this.$comment.val(data.comment.comment).focus() + $("body").removeClass("loading") + }.bind(this)) + }, + + focus: function(){ + this.$el.addClass('focused') + }, + + validate: function(){ + var errors = [] + var comment = $("[name=comment]").val() + if (! comment || ! comment.length) { + errors.push("Please enter a comment.") + } + return errors.length ? errors : null + }, + + success: function(data){ + window.location.href = "/details/" + data.comment.id + } +})
\ No newline at end of file diff --git a/views/pages/editcomment.ejs b/views/pages/editcomment.ejs new file mode 100644 index 0000000..97a8402 --- /dev/null +++ b/views/pages/editcomment.ejs @@ -0,0 +1,21 @@ +<% include ../partials/header %> + +<div id="content"> + +<table id="comment_form"> + <tr> + <td> + <form> + <textarea name="comment" placeholder="Enter your comment"></textarea><br> + <div class="inputs"> + <input type="submit" value="POST" /> + </div> + <div class="errors"></div> + </form> + </td> + </tr> +</table> + +</div> + +<% include ../partials/footer %> diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs index 79ef89e..7fda30e 100644 --- a/views/partials/scripts.ejs +++ b/views/partials/scripts.ejs @@ -31,6 +31,7 @@ <script src="/assets/js/lib/views/details/files.js"></script> <script src="/assets/js/lib/views/details/gallery.js"></script> <script src="/assets/js/lib/views/details/commentform.js"></script> +<script src="/assets/js/lib/views/details/editcomment.js"></script> <script src="/assets/js/lib/views/mail/mailbox.js"></script> <script src="/assets/js/lib/views/mail/message.js"></script> |
