From ed083ad3191a5d7d61abb21fa7dafec5121ecaab Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 25 Sep 2015 18:05:37 -0400 Subject: post comment --- public/assets/js/lib/views/index/hootbox.js | 23 +++++++++++++-- public/assets/js/vendor/view/formview.js | 44 ++++++++++++++--------------- 2 files changed, 42 insertions(+), 25 deletions(-) (limited to 'public/assets/js') diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index 9d1cc3d..4a23d32 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -5,10 +5,13 @@ var HootBox = FormView.extend({ events: { }, + action: "/api/thread/1/comment", + initialize: function(){ this.__super__.initialize.call(this) this.template = this.$(".template").html() this.$hoots = this.$("#hoots") + this.$comment = this.$("[name=comment]") }, load: function(comments){ @@ -31,7 +34,23 @@ var HootBox = FormView.extend({ this.$hoots.append($el) }, - success: function(){ - this.prependComment(comment) + validate: function(){ + var errors = [] + if (! this.$comment.val()) { + errors.push("no comment") + return errors + } + return null + }, + + beforeSend: function(){ + this.$comment.val("") + }, + + showErrors: function(){ + }, + + success: function(data){ + this.prependComment(data.comment) } }) \ No newline at end of file diff --git a/public/assets/js/vendor/view/formview.js b/public/assets/js/vendor/view/formview.js index 05b1ecb..7e77500 100644 --- a/public/assets/js/vendor/view/formview.js +++ b/public/assets/js/vendor/view/formview.js @@ -80,7 +80,7 @@ var FormView = View.extend({ var action = typeof this.action == "function" ? this.action() : this.action if (! action) return - + var request = $.ajax({ url: action, type: this.method, @@ -90,30 +90,27 @@ var FormView = View.extend({ processData: false, contentType: false, success: function(response){ - - if (response.error) { - var errors = [] - for (var key in response.error.errors) { - errors.push(response.error.errors[key].message); - } - if (errorCallback) { - errorCallback(errors) - } - else { - this.showErrors(errors) - } - return + if (response.error) { + var errors = [] + for (var key in response.error.errors) { + errors.push(response.error.errors[key].message); + } + if (errorCallback) { + errorCallback(errors) } else { - if (successCallback) { - successCallback(response) - } - if (this.success) { - this.success(response) - } + this.showErrors(errors) } - - + return + } + else { + if (successCallback) { + successCallback(response) + } + if (this.success) { + this.success(response) + } + } }.bind(this), error: function(response){ }.bind(this), @@ -127,7 +124,8 @@ var FormView = View.extend({ if (this.useMinotaur) { Minotaur.show() } - + + this.beforeSend && this.beforeSend() }, }) -- cgit v1.2.3-70-g09d2