summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-22 07:11:26 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-22 07:11:26 +0100
commitfa4ed0f3b1ce5decfc6ee59d38e63e78a7793de4 (patch)
tree74658c754cbdff432aa8dc8b4f3521c993993c45 /public/assets/js/lib/views
parent1a67f6f262364ee4fed0c1538ef2f41d772bf1b1 (diff)
new keyword form
Diffstat (limited to 'public/assets/js/lib/views')
-rw-r--r--public/assets/js/lib/views/details/settings.js38
-rw-r--r--public/assets/js/lib/views/index/index.js14
-rw-r--r--public/assets/js/lib/views/keywords/keywords.js25
-rw-r--r--public/assets/js/lib/views/keywords/newkeyword.js34
4 files changed, 75 insertions, 36 deletions
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js
index 1d048ab..c8e53db 100644
--- a/public/assets/js/lib/views/details/settings.js
+++ b/public/assets/js/lib/views/details/settings.js
@@ -1,7 +1,7 @@
var ThreadSettingsForm = FormView.extend({
-
+
el: "#thread_settings",
-
+
events: {
"click": "hide",
"click .inner": "stopPropagation",
@@ -14,17 +14,17 @@ var ThreadSettingsForm = FormView.extend({
"keydown [name=allowed_field]": "keydownAllowed",
"blur [name=allowed_field]": "updateAllowed",
},
-
+
action: "",
method: 'put',
-
+
initialize: function(){
this.__super__.initialize.call(this)
this.template = this.$(".template").html()
this.allowedTemplate = this.$(".allowedTemplate").html()
this.filesTemplate = this.$(".settingsFilesTemplate").html()
},
-
+
populate: function(){
var data = this.options.parent.data
var keywords = data.keywords
@@ -34,7 +34,7 @@ var ThreadSettingsForm = FormView.extend({
var files = data.files
var settings = thread.settings
var display = thread.display
-
+
this.thread = thread
this.files = data.files
this.action = "/api/thread/" + thread.id
@@ -48,7 +48,7 @@ var ThreadSettingsForm = FormView.extend({
this.$("[name=shorturls]").prop("checked", !!thread.settings.shorturls)
this.$("[name=noupload]").prop("checked", !!thread.settings.noupload)
this.$("[name=privacy]").prop("checked", !!thread.privacy)
-
+
var $color = this.$('[name=color]')
Object.keys(COLORS).forEach((color) => {
var option = document.createElement('option')
@@ -57,10 +57,10 @@ var ThreadSettingsForm = FormView.extend({
$color.append(option)
})
$color.val(thread && thread.color? thread.color: keyword? keyword.color: "")
-
+
this.toggleAllowed()
this.fetchKeywords()
-
+
var $files = this.$(".files")
$files.empty()
files.sort((a,b) => cmp(a.filename, b.filename))
@@ -84,7 +84,7 @@ var ThreadSettingsForm = FormView.extend({
$("body").removeClass("loading")
},
-
+
fetchKeywords: function(thread){
$.get('/api/keywords', function(data){
var $keyword = this.$('[name=keyword]')
@@ -100,7 +100,7 @@ var ThreadSettingsForm = FormView.extend({
$keyword.val(this.thread.keyword)
}.bind(this))
},
-
+
toggleAllowed: function(e){
var checked = this.$('[name=privacy]').prop('checked')
this.$(".allowed_field_container").toggle(checked)
@@ -109,7 +109,7 @@ var ThreadSettingsForm = FormView.extend({
this.$("[name=allowed_field]").focus()
this.displayAllowed()
},
-
+
displayAllowed: function(e){
var $allowedNames = this.$(".allowed_names").empty()
this.allowed.forEach(username => {
@@ -117,7 +117,7 @@ var ThreadSettingsForm = FormView.extend({
$allowedNames.append(t)
})
},
-
+
keydownAllowed: function(e){
if (e.keyCode === 13) { // enter
e.preventDefault()
@@ -125,7 +125,7 @@ var ThreadSettingsForm = FormView.extend({
this.updateAllowed()
}
},
-
+
updateAllowed: function(){
var usernames = this.$('[name=allowed_field]').val().replace(/,/g, ' ').split(' ').map(s => s.trim()).filter(s => !! s)
this.$('[name=allowed_field]').val('')
@@ -145,14 +145,14 @@ var ThreadSettingsForm = FormView.extend({
}.bind(this),
})
},
-
+
removeAllowed: function(){
this.allowed = this.$("#allowed_names input[type=checkbox]:checked").map(function(){
return $(this).val()
})
this.displayAllowed()
},
-
+
validate: function(){
var errors = []
var title = $("[name=title]").val()
@@ -184,7 +184,7 @@ var ThreadSettingsForm = FormView.extend({
},
visible: false,
-
+
show: function(){
this.visible = true
app.typing = true
@@ -205,7 +205,7 @@ var ThreadSettingsForm = FormView.extend({
if (this.visible) this.hide()
else this.show()
},
-
+
changeColor: function(){
var color_name = this.$("[name=color]").val()
set_background_color(color_name)
@@ -264,4 +264,4 @@ var ThreadSettingsForm = FormView.extend({
}
},
-}) \ 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 94bc57d..3f217fc 100644
--- a/public/assets/js/lib/views/index/index.js
+++ b/public/assets/js/lib/views/index/index.js
@@ -2,18 +2,19 @@ var IndexView = View.extend({
events: {
},
-
+
action: "/api/index",
keywordAction: "/api/keyword/",
-
+
initialize: function(opt){
// opt.parent = parent
this.hootbox = new HootBox ({ parent: this })
this.threadbox = new ThreadBox ({ parent: this })
this.lastlog = new LastLog ({ parent: this })
},
-
+
load: function(keyword){
+ $("body").addClass("index")
if (keyword) {
$(".subtitle").html('<a href="/">&lt; Home</a> &middot; <a href="/keywords">Keywords</a>')
this.threadbox.options.latest = false
@@ -25,10 +26,9 @@ var IndexView = View.extend({
this.threadbox.options.latest = true
this.threadbox.options.welcome = true
$.get(this.action, this.populate.bind(this))
- $("body").addClass("index")
}
},
-
+
populate: function(data){
$("body").removeClass('loading')
this.hootbox.load(data.hootbox)
@@ -36,9 +36,9 @@ var IndexView = View.extend({
this.lastlog.load(data.lastlog)
$(".search_form input").focus()
},
-
+
success: function(){
window.location.href = "/index"
},
-}) \ No newline at end of file
+})
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
+ }
+})