summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details/editcomment.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/details/editcomment.js')
-rw-r--r--public/assets/js/lib/views/details/editcomment.js42
1 files changed, 42 insertions, 0 deletions
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