summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/keywords
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/keywords')
-rw-r--r--public/assets/js/lib/views/keywords/keywords.js25
-rw-r--r--public/assets/js/lib/views/keywords/newkeyword.js34
2 files changed, 49 insertions, 10 deletions
diff --git a/public/assets/js/lib/views/keywords/keywords.js b/public/assets/js/lib/views/keywords/keywords.js
index 37fab16..9b2eadc 100644
--- a/public/assets/js/lib/views/keywords/keywords.js
+++ b/public/assets/js/lib/views/keywords/keywords.js
@@ -1,22 +1,23 @@
var KeywordsView = View.extend({
-
+
el: "#keyword_list",
-
+
events: {
},
-
+
action: "/api/keywords/statistics",
-
+
initialize: function(opt){
this.template = this.$(".template").html()
+ this.form = new NewKeywordForm ({ parent: this })
},
-
+
load: function(){
$.get(this.action, this.populate.bind(this))
},
-
+
populate: function(data){
- console.log(data)
+ // console.log(data)
var keywordThreads = {}
data.threadGroups.forEach(kw => {
keywordThreads[kw.keyword] = kw
@@ -29,16 +30,18 @@ var KeywordsView = View.extend({
var thread = keywordThreads[keyword.keyword.toLowerCase()] || {
title: '',
}
- // {
+ // {
// keyword: "warez",
// sum(`viewed`): "498",
// id: 701,
// title: "EMS SYNTHI PLUG FOR MAC",
// lastmodified: 1192401724
// },
- console.log(keyword, thread)
+ // console.log(keyword, thread)
var viewed = thread['sum(`viewed`)']
var views = viewed ? hush_views(viewed) : ['','']
+ var threadCountNum = thread['count(*)']
+ var threadCount = threadCountNum ? hush_threads(threadCountNum) : ['','']
var dot = privacy_dot(thread.privacy)
var datetime = verbose_date(keyword.createdate)
var age = get_age(thread.lastmodified)
@@ -53,6 +56,8 @@ var KeywordsView = View.extend({
.replace(/{{time}}/g, datetime[1])
.replace(/{{date_class}}/g, carbon_date(thread.lastmodified) )
.replace(/{{views}}/g, views[1])
+ .replace(/{{threadcount}}/, threadCount[1])
+ .replace(/{{threadcount_class}}/, threadCount[0])
// .replace(/{{comments}}/g, comments[1])
// .replace(/{{files}}/g, files[1])
// .replace(/{{size}}/g, size[1] )
@@ -68,4 +73,4 @@ var KeywordsView = View.extend({
$("body").removeClass('loading')
},
-}) \ No newline at end of file
+})
diff --git a/public/assets/js/lib/views/keywords/newkeyword.js b/public/assets/js/lib/views/keywords/newkeyword.js
new file mode 100644
index 0000000..9db528a
--- /dev/null
+++ b/public/assets/js/lib/views/keywords/newkeyword.js
@@ -0,0 +1,34 @@
+var NewKeywordForm = FormView.extend({
+
+ el: "#new_keyword",
+
+ action: "/api/keyword/new",
+
+ initialize: function(){
+ this.__super__.initialize.call(this)
+ var $color = this.$('[name=color]')
+ Object.keys(COLORS).forEach((color) => {
+ var option = document.createElement('option')
+ option.value = color
+ option.innerHTML = color
+ $color.append(option)
+ })
+ $color.val(choice(Object.keys(COLORS)))
+ },
+
+ validate: function(){
+ var errors = []
+ var keyword = $("[name=keyword]").val().trim()
+ if (! keyword || ! keyword.length) {
+ errors.push("Please enter a keyword.")
+ }
+ if (keyword === "new") {
+ errors.push("Keyword cannot be called 'new'.")
+ }
+ return errors.length ? errors : null
+ },
+
+ success: function(data){
+ window.location.href = "/post/" + data.keyword.keyword
+ }
+})