blob: f13cc55d3d2edf96489fdb95d63665685b22e2b5 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
var HootForm = FormView.extend({
el: "#hootform",
events: {},
action: "/api/thread/1/comment",
initialize: function (opt) {
this.__super__.initialize.call(this);
this.$comment = this.$("[name=comment]");
},
show: function () {
this.$el.show();
},
hide: function () {
this.$el.hide();
},
toggle: function (state) {
if (state) {
this.show();
} else {
this.hide();
}
},
load: function (comments) {
if (!comments || (!comments.length && !this.options.required)) {
this.$el.hide();
return;
}
comments.forEach(this.appendComment.bind(this));
},
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) {
this.parent.onComment(data.comment);
this.$("[name=comment]").val("");
},
});
|