diff options
Diffstat (limited to 'public/assets/js/lib/views/details')
| -rw-r--r-- | public/assets/js/lib/views/details/comments.js | 39 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/files.js | 59 | ||||
| -rw-r--r-- | public/assets/js/lib/views/details/index.js | 28 |
3 files changed, 126 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/details/comments.js b/public/assets/js/lib/views/details/comments.js new file mode 100644 index 0000000..164a3b1 --- /dev/null +++ b/public/assets/js/lib/views/details/comments.js @@ -0,0 +1,39 @@ +var CommentsView = FormView.extend({ + + el: "#comments", + + events: { + }, + + initialize: function(){ + this.__super__.initialize.call(this) + this.template = this.$(".template").html() + }, + + load: function(comments){ + comments.forEach(this.appendComment.bind(this)) + }, + + parse: function(comment){ + var datetime = verbose_date(comment.date) + var t = this.template.replace(/{{username}}/g, comment.username) + .replace(/{{comment}}/g, comment.comment) + .replace(/{{date}}/g, datetime[0]) + .replace(/{{time}}/g, datetime[1]) + return t + }, + + prependComment: function(comment){ + var $el = $( this.parse(comment) ) + this.$el.prepend($el) + }, + + appendComment: function(comment){ + var $el = $( this.parse(comment) ) + this.$el.append($el) + }, + + success: function(){ + this.prependComment(comment) + } +})
\ No newline at end of file diff --git a/public/assets/js/lib/views/details/files.js b/public/assets/js/lib/views/details/files.js new file mode 100644 index 0000000..5a19519 --- /dev/null +++ b/public/assets/js/lib/views/details/files.js @@ -0,0 +1,59 @@ +var FilesView = FormView.extend({ + + el: "#files", + + events: { + }, + + initialize: function(){ + this.__super__.initialize.call(this) + this.template = this.$(".template").html() + this.templateTotal = this.$(".templateTotal").html() + }, + + load: function(files){ + if (! files.length) { + this.$el.hide() + } + var total = 0 + files.forEach(function(file){ + this.appendFile(file) + total += file.size + }.bind(this)) + + var size = hush_size(total) + var t = this.templateTotal.replace(/{{size_class}}/g, size[0]) + .replace(/{{size}}/g, size[1]) + this.$el.append(t) + }, + + parse: function(file){ + var size = hush_size(file.size) + var datetime = verbose_date(file.date) + var date_class = carbon_date(file.date) + + var t = this.template.replace(/{{username}}/g, file.username) + .replace(/{{link}}/g, file.filename) + .replace(/{{filename}}/g, file.filename) + .replace(/{{date_class}}/g, date_class) + .replace(/{{date}}/g, datetime[0]) + .replace(/{{time}}/g, datetime[1]) + .replace(/{{size_class}}/g, size[0]) + .replace(/{{size}}/g, size[1]) + return t + }, + + prependFile: function(file){ + var $el = $( this.parse(file) ) + this.$el.prepend($el) + }, + + appendFile: function(file){ + var $el = $( this.parse(file) ) + this.$el.append($el) + }, + + success: function(){ + this.prependFile(file) + } +})
\ 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 new file mode 100644 index 0000000..e2adb55 --- /dev/null +++ b/public/assets/js/lib/views/details/index.js @@ -0,0 +1,28 @@ +var DetailsView = View.extend({ + + events: { + }, + + action: "/api/thread/", + + initialize: function(opt){ + this.comments = new CommentsView ({ parent: this }) + this.files = new FilesView ({ parent: this }) + }, + + load: function(id){ + id = id.replace(/\D/g, "") + $.get(this.action + id, this.populate.bind(this)) + }, + + populate: function(data){ + $("h1").html(data.thread.title) + this.comments.load(data.comments) + this.files.load(data.files) + }, + + success: function(){ + window.location.href = "/index" + }, + +}) |
