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/details/commentform.js33
-rw-r--r--public/assets/js/lib/views/details/index.js5
-rw-r--r--public/assets/js/lib/views/index/hootbox.js21
-rw-r--r--public/assets/js/vendor/view/formview.js7
4 files changed, 50 insertions, 16 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("")
diff --git a/public/assets/js/vendor/view/formview.js b/public/assets/js/vendor/view/formview.js
index 384e470..2c54d3e 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,
@@ -122,7 +122,8 @@ var FormView = View.extend({
if (this.useMinotaur) {
Minotaur.show()
}
-
+
+ this.beforeSend && this.beforeSend()
},
})
@@ -138,4 +139,4 @@ var ModalFormView = ModalView.extend(FormView.prototype).extend({
})
-*/ \ No newline at end of file
+*/