diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-08 01:35:26 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-08 01:35:26 +0100 |
| commit | e4e0cf21a31b74d5ee1e6d45b343ea60ed44f372 (patch) | |
| tree | d6e3d14c4b5ddfed5d8bd036a5eba29af505553b /public/assets/js | |
| parent | 3a4f027ec05aa5fdf4098ceb0dab09f69c5e0b8b (diff) | |
hootbox stuff
Diffstat (limited to 'public/assets/js')
| -rw-r--r-- | public/assets/js/lib/views/details/index.js | 2 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/hootbox.js | 14 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/threadbox.js | 1 | ||||
| -rw-r--r-- | public/assets/js/vendor/view/formview.js | 47 |
4 files changed, 36 insertions, 28 deletions
diff --git a/public/assets/js/lib/views/details/index.js b/public/assets/js/lib/views/details/index.js index 6290738..7757bae 100644 --- a/public/assets/js/lib/views/details/index.js +++ b/public/assets/js/lib/views/details/index.js @@ -30,7 +30,7 @@ var DetailsView = View.extend({ .replace(/{{ date }}/g, datetime[0]) .replace(/{{ time }}/g, datetime[1]) .replace(/{{ active }}/g, age + " ago") - .replace(/{{ views }}/g, thread.viewed + " " + courtesy_s(thread.viewed, "view")) + .replace(/{{ views }}/g, thread.viewed + " view" + courtesy_s(thread.viewed)) console.log(t) console.log(data.thread) // name date time active views diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index 9d1cc3d..f93a689 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -5,6 +5,17 @@ var HootBox = FormView.extend({ events: { }, + validate: function(){ + var errors = [] + var comment = $("[name=comment]").val() + if (! comment || ! comment.length) { + errors.push("Please enter a comment.") + } + return errors.length ? errors : null + }, + + action: "/api/thread/1/comment", + initialize: function(){ this.__super__.initialize.call(this) this.template = this.$(".template").html() @@ -31,7 +42,8 @@ var HootBox = FormView.extend({ this.$hoots.append($el) }, - success: function(){ + success: function(comment){ this.prependComment(comment) + this.$("[name=comment]").val("") } })
\ No newline at end of file diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js index 0c6a4be..8d8cb02 100644 --- a/public/assets/js/lib/views/index/threadbox.js +++ b/public/assets/js/lib/views/index/threadbox.js @@ -35,6 +35,7 @@ var ThreadBox = View.extend({ }, parse: function(thread){ + if (thread.comment_count === undefined) return "" var views = hush_views(thread.viewed) var size = hush_size(thread.size) var comments = hush_null(thread.comment_count, "c") diff --git a/public/assets/js/vendor/view/formview.js b/public/assets/js/vendor/view/formview.js index 05b1ecb..384e470 100644 --- a/public/assets/js/vendor/view/formview.js +++ b/public/assets/js/vendor/view/formview.js @@ -53,10 +53,10 @@ var FormView = View.extend({ } }); -// if (! hasCSRF) { -// fd.append("_csrf", $("[name=_csrf]").attr("value")) -// } -// + if (! hasCSRF) { + fd.append("_csrf", $("[name=_csrf]").attr("value")) + } + return fd }, @@ -64,7 +64,7 @@ var FormView = View.extend({ e && e.preventDefault() this.$errors.hide().css("opacity", 0.0); - + if (this.validate) { var errors = this.validate() if (errors && errors.length) { @@ -90,30 +90,25 @@ 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 + } + if (successCallback) { + successCallback(response) + } + if (this.success) { + this.success(response) + } }.bind(this), error: function(response){ }.bind(this), |
