summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/details')
-rw-r--r--public/assets/js/lib/views/details/commentform.js33
-rw-r--r--public/assets/js/lib/views/details/index.js16
2 files changed, 48 insertions, 1 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 554c475..cd8045a 100644
--- a/public/assets/js/lib/views/details/index.js
+++ b/public/assets/js/lib/views/details/index.js
@@ -6,11 +6,14 @@ var DetailsView = View.extend({
action: "/api/thread/",
keywordAction: "/api/keyword/",
+
initialize: function(opt){
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()
},
load: function(id){
@@ -19,7 +22,18 @@ var DetailsView = View.extend({
},
populate: function(data){
- $("h1").html(data.thread.title)
+ var thread = data.thread
+ $("h1").html(thread.title)
+ var datetime = verbose_date(thread.createdate, true)
+ var age = get_age(thread.lastmodified, true)
+ var t = this.metadataTemplate
+ .replace(/{{ username }}/g, thread.username)
+ .replace(/{{ date }}/g, datetime[0])
+ .replace(/{{ time }}/g, datetime[1])
+ .replace(/{{ active }}/g, age + " ago")
+ .replace(/{{ views }}/g, thread.viewed + " view" + courtesy_s(thread.viewed))
+ $(".metadata").html(t)
+ this.form.load(data.thread)
this.comments.load(data.comments)
this.files.load(data.files)
this.gallery.load(data.files)