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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
var EditCommentForm = FormView.extend({
el: "#comment_form",
events: {
"focus textarea": 'focus',
"keydown textarea": 'keydown',
},
action: "",
method: 'put',
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){
this.$comment.val(data.comment.comment).focus()
console.log(this.$comment)
setCaretToPos(this.$comment.get(0), 0, 0)
$("body").removeClass("loading")
}.bind(this))
},
focus: function(){
this.$el.addClass('focused')
},
keydown: function(e){
if (((e.ctrlKey || e.metaKey || e.altKey) && e.keyCode == 83) || (e.ctrlKey && e.keyCode == 13)) { // "s" key or "ctrl + enter"
e.preventDefault()
e.stopPropagation()
this.save()
}
},
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.thread
}
})
|