diff options
Diffstat (limited to 'public/assets/js/lib/views/index')
| -rw-r--r-- | public/assets/js/lib/views/index/hootbox.js | 24 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/index.js | 2 | ||||
| -rw-r--r-- | public/assets/js/lib/views/index/threadbox.js | 27 |
3 files changed, 34 insertions, 19 deletions
diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index 4a23d32..cdd3eb0 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -33,24 +33,18 @@ var HootBox = FormView.extend({ var $el = $( this.parse(comment) ) this.$hoots.append($el) }, - + validate: function(){ var errors = [] - if (! this.$comment.val()) { - errors.push("no comment") - return errors + var comment = $("[name=comment]").val() + if (! comment || ! comment.length) { + errors.push("Please enter a comment.") } - return null - }, - - beforeSend: function(){ - this.$comment.val("") + return errors.length ? errors : null }, - - showErrors: function(){ - }, - - success: function(data){ - this.prependComment(data.comment) + + 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/index.js b/public/assets/js/lib/views/index/index.js index a1e8af5..d66ea1c 100644 --- a/public/assets/js/lib/views/index/index.js +++ b/public/assets/js/lib/views/index/index.js @@ -8,7 +8,7 @@ var IndexView = View.extend({ initialize: function(opt){ // opt.parent = parent this.hootbox = new HootBox ({ parent: this }) - this.threadbox = new ThreadBox ({ parent: this }) + this.threadbox = new ThreadBox ({ parent: this, latest: true }) this.lastlog = new LastLog ({ parent: this }) this.load() }, diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js index 0475382..8d8cb02 100644 --- a/public/assets/js/lib/views/index/threadbox.js +++ b/public/assets/js/lib/views/index/threadbox.js @@ -12,13 +12,30 @@ var ThreadBox = View.extend({ load: function(data){ if (data.keyword) { - var $row = this.parseKeyword(data.keyword) - this.$el.append($row) + this.appendKeyword(data.keyword) + data.threads.forEach(this.appendThread.bind(this)) + } + else if (this.options.latest) { + data.threads.sort( (a,b) => { + return b.lastmodified - a.lastmodified + }).slice(0, 50).forEach(this.appendThread.bind(this)) + } + else { + var keywords = {} + data.threads.forEach((thread) => { + var keyword = thread.keyword || '__unsorted' + keywords[keyword] = keywords[keyword] || [] + keywords[keyword].push(thread) + }) + Object.keys(keywords).sort().forEach((keyword) => { + this.appendKeyword({ keyword }) + keywords[keyword].forEach(this.appendThread.bind(this)) + }) } - data.threads.forEach(this.appendThread.bind(this)) }, 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") @@ -65,4 +82,8 @@ var ThreadBox = View.extend({ this.$el.append($row) }, + appendKeyword: function(keyword){ + var $row = $( this.parseKeyword(keyword) ) + this.$el.append($row) + }, }) |
