summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/stream/hootcomment.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/stream/hootcomment.js')
-rw-r--r--public/assets/js/lib/views/stream/hootcomment.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/stream/hootcomment.js b/public/assets/js/lib/views/stream/hootcomment.js
new file mode 100644
index 0000000..93c57e4
--- /dev/null
+++ b/public/assets/js/lib/views/stream/hootcomment.js
@@ -0,0 +1,60 @@
+var HootCommentForm = FormView.extend({
+ events: {
+ "focus textarea": "focus",
+ "mouseup input[type=file]": "focus",
+ "keydown textarea": "keydown",
+ },
+
+ action: "",
+
+ initialize: function (opt) {
+ this.__super__.initialize.call(this, opt);
+ this.template = this.$(".template").html();
+ this.$comment = this.$("[name=comment]");
+ },
+
+ load: function (thread) {
+ this.action = "/api/thread/" + thread.id + "/comment";
+ this.$comment.addClass("empty");
+ if (thread.settings.noupload) {
+ this.$("[type=file]").hide();
+ }
+ },
+
+ keydown: function (e) {
+ if ((e.ctrlKey || e.metaKey || e.altKey) && e.keyCode == 83) {
+ // "s" key
+ e.preventDefault();
+ e.stopPropagation();
+ this.save();
+ }
+ },
+
+ focus: function () {
+ this.$el.addClass("focused");
+ this.$comment.removeClass("empty");
+ $("[name=comment]").prop("required", false);
+ },
+
+ validate: function () {
+ var errors = [];
+ var comment = $("[name=comment]").val();
+ var files = this.$("[name=files]").val();
+ if ((!comment || !comment.length) && !files) {
+ errors.push("Please enter a comment or add some files.");
+ }
+ return errors.length ? errors : null;
+ },
+
+ success: function (data) {
+ $("[name=comment").val("");
+ $("[name=files").val("");
+ // window.location.reload()
+ console.log(this);
+ console.log(this.parent);
+ console.log(data);
+ data.comment && this.parent.comments.load([data.comment]);
+ data.files && this.parent.files.add(data.files);
+ data.files && this.parent.gallery.add(data.files);
+ },
+});