From 242eed0093c59047033c286d7a14608d0096b125 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Dec 2017 10:04:14 +0100 Subject: comment edit form --- public/assets/js/lib/views/details/editcomment.js | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 public/assets/js/lib/views/details/editcomment.js (limited to 'public/assets/js/lib/views/details/editcomment.js') 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 -- cgit v1.2.3-70-g09d2