diff options
Diffstat (limited to 'public/assets/js/lib/views')
| -rw-r--r-- | public/assets/js/lib/views/details/commentform.js | 33 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/index.js | 5 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/hootbox.js | 21 |
3 files changed, 46 insertions, 13 deletions
diff --git a/public/assets/js/lib/views/details/commentform.js b/public/assets/js/lib/views/details/commentform.js new file mode 100644 index 0000000..30671f2 --- /dev/null +++ b/public/assets/js/lib/views/details/commentform.js @@ -0,0 +1,33 @@ +var CommentForm = FormView.extend({ + + el: "#comment_form", + + events: { + }, + + action: "/api/thread/1/comment", + + initialize: function(){ + this.__super__.initialize.call(this) + this.template = this.$(".template").html() + this.$comment = this.$("[name=comment]") + }, + + load: function(thread){ + this.action = "/api/thread/" + thread.id + "/comment" + }, + + 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(comment){ + this.prependComment(comment) + this.$("[name=comment]").val("") + } +})
\ No newline at end of file diff --git a/public/assets/js/lib/views/details/index.js b/public/assets/js/lib/views/details/index.js index 7757bae..cd8045a 100644 --- a/public/assets/js/lib/views/details/index.js +++ b/public/assets/js/lib/views/details/index.js @@ -11,6 +11,7 @@ var DetailsView = View.extend({ this.comments = new CommentsView ({ parent: this }) this.files = new FilesView ({ parent: this }) this.gallery = new GalleryView ({ parent: this }) + this.form = new CommentForm ({ parent: this }) this.threadbox = new ThreadBox ({ parent: this }) this.metadataTemplate = $(".metadata_template").html() }, @@ -31,10 +32,8 @@ var DetailsView = View.extend({ .replace(/{{ time }}/g, datetime[1]) .replace(/{{ active }}/g, age + " ago") .replace(/{{ views }}/g, thread.viewed + " view" + courtesy_s(thread.viewed)) -console.log(t) - console.log(data.thread) -// name date time active views $(".metadata").html(t) + this.form.load(data.thread) this.comments.load(data.comments) this.files.load(data.files) this.gallery.load(data.files) diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index f93a689..cdd3eb0 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -5,21 +5,13 @@ 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() this.$hoots = this.$("#hoots") + this.$comment = this.$("[name=comment]") }, load: function(comments){ @@ -41,7 +33,16 @@ var HootBox = FormView.extend({ var $el = $( this.parse(comment) ) this.$hoots.append($el) }, - + + 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(comment){ this.prependComment(comment) this.$("[name=comment]").val("") |
