summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/lib/views/index/hootbox.js23
-rw-r--r--public/assets/js/vendor/view/formview.js44
2 files changed, 42 insertions, 25 deletions
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()
},
})