summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details/commentform.js
blob: 30671f23c9003ffc71c2914e6e4dce61576845a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var CommentForm = FormView.extend({
  
  el: "#comment_form",
  
  events: {
  },
  
  action: "/api/thread/1/comment",
  
  initialize: function(){
    this.__super__.initialize.call(this)
    this.template = this.$(".template").html()
    this.$comment = this.$("[name=comment]")
  },
  
  load: function(thread){
    this.action = "/api/thread/" + thread.id + "/comment"
  },
  
  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(comment){
    this.prependComment(comment)
    this.$("[name=comment]").val("")
  }
})