summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/stream/hootform.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/stream/hootform.js')
-rw-r--r--public/assets/js/lib/views/stream/hootform.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/stream/hootform.js b/public/assets/js/lib/views/stream/hootform.js
new file mode 100644
index 0000000..368e616
--- /dev/null
+++ b/public/assets/js/lib/views/stream/hootform.js
@@ -0,0 +1,42 @@
+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();
+ },
+
+ 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("");
+ },
+});