diff options
Diffstat (limited to 'public/assets/js')
| -rw-r--r-- | public/assets/js/lib/router.js | 30 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/editcomment.js | 42 |
2 files changed, 60 insertions, 12 deletions
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 |
