diff options
Diffstat (limited to 'public/assets/js/lib/views/index/threadbox.js')
| -rw-r--r-- | public/assets/js/lib/views/index/threadbox.js | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js index 8d8cb02..6efce22 100644 --- a/public/assets/js/lib/views/index/threadbox.js +++ b/public/assets/js/lib/views/index/threadbox.js @@ -8,28 +8,34 @@ var ThreadBox = View.extend({ this.__super__.initialize.call(this) this.template = this.$(".template").html() this.keywordTemplate = this.$(".keywordTemplate").html() + this.welcomeTemplate = this.$(".welcomeTemplate").html() }, load: function(data){ + if (this.options.welcome) { + this.appendWelcome() + } if (data.keyword) { 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)) + this.appendThreads(data.threads) } else { + if (this.options.latest) { + var latest = data.threads.sort( (a,b) => { + return b.lastmodified - a.lastmodified + }).slice(0, 15) + this.appendThreads(latest) + data.threads = data.threads.filter((thread) => thread && !! thread.keyword) + } var keywords = {} data.threads.forEach((thread) => { - var keyword = thread.keyword || '__unsorted' + 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)) + this.appendThreads(keywords[keyword]) }) } }, @@ -62,7 +68,7 @@ var ThreadBox = View.extend({ .replace(/{{files_class}}/g, files[0]) .replace(/{{show_files}}/g, thread.file_count == 0 ? "hidden" : "") .replace(/{{size_class}}/g, size[0] ) - .replace(/{{color}}/g, thread.color || "ivory" ) + .replace(/{{color}}/g, thread.color || "blue" ) return t }, @@ -76,9 +82,18 @@ var ThreadBox = View.extend({ var $row = $( this.parse(thread) ) this.$el.prepend($row) }, + + appendThreads: function(threads){ + threads[0].first = true + threads[threads.length-1].last = true + threads.forEach(this.appendThread.bind(this)) + }, appendThread: function(thread){ + thread.appended = true var $row = $( this.parse(thread) ) + if (thread.first) $row.addClass('first') + if (thread.last) $row.addClass('last') this.$el.append($row) }, @@ -86,4 +101,9 @@ var ThreadBox = View.extend({ var $row = $( this.parseKeyword(keyword) ) this.$el.append($row) }, + + appendWelcome: function(){ + this.$el.append(this.welcomeTemplate) + }, + }) |
