summaryrefslogtreecommitdiff
path: root/public/assets/js/lib
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-10 07:02:47 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-10 07:02:47 +0100
commit9e6b80c0321ba1fbe1c824083acbeeac7b7b94d4 (patch)
tree67cd6d247cd1bc15c43ebad10e2f02249217e8ca /public/assets/js/lib
parenta932b664db987f2cf9ceefe9bb56e43793470d5e (diff)
post form and other stuff
Diffstat (limited to 'public/assets/js/lib')
-rw-r--r--public/assets/js/lib/router.js7
-rw-r--r--public/assets/js/lib/views/details/commentform.js7
-rw-r--r--public/assets/js/lib/views/details/index.js2
-rw-r--r--public/assets/js/lib/views/index/lastlog.js2
-rw-r--r--public/assets/js/lib/views/index/threadform.js53
5 files changed, 65 insertions, 6 deletions
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js
index 9879c6c..95b0ac6 100644
--- a/public/assets/js/lib/router.js
+++ b/public/assets/js/lib/router.js
@@ -7,6 +7,8 @@ var SiteRouter = Router.extend({
"/index": 'index',
"/login": 'login',
"/details/:id": 'details',
+ "/post": 'post',
+ "/post/:keyword": 'post',
"/search": 'search',
"/mail": 'mailbox',
"/mail/:mailbox": 'mailbox',
@@ -40,6 +42,11 @@ var SiteRouter = Router.extend({
app.view = new MessageView ()
app.view.load(id)
},
+
+ post: function(keyword){
+ app.view = new ThreadForm ()
+ app.view.load(keyword || "")
+ },
compose: function(){
app.view = new ComposeView ()
diff --git a/public/assets/js/lib/views/details/commentform.js b/public/assets/js/lib/views/details/commentform.js
index 30671f2..3b82ac7 100644
--- a/public/assets/js/lib/views/details/commentform.js
+++ b/public/assets/js/lib/views/details/commentform.js
@@ -5,7 +5,7 @@ var CommentForm = FormView.extend({
events: {
},
- action: "/api/thread/1/comment",
+ action: "",
initialize: function(){
this.__super__.initialize.call(this)
@@ -26,8 +26,7 @@ var CommentForm = FormView.extend({
return errors.length ? errors : null
},
- success: function(comment){
- this.prependComment(comment)
- this.$("[name=comment]").val("")
+ success: function(){
+ window.location.reload()
}
}) \ 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
index 0a40dbc..25ae020 100644
--- a/public/assets/js/lib/views/details/index.js
+++ b/public/assets/js/lib/views/details/index.js
@@ -23,7 +23,7 @@ var DetailsView = View.extend({
populate: function(data){
var thread = data.thread
$("h1").html(thread.title)
- $(".subtitle").show().html(metadata(thread))
+ $(".subtitle").show().html("<a href='/'>&lt; Home</a> | " + metadata(thread))
this.form.load(data.thread)
this.comments.load(data.comments)
this.files.load(data.files)
diff --git a/public/assets/js/lib/views/index/lastlog.js b/public/assets/js/lib/views/index/lastlog.js
index 0fed101..fe50e0f 100644
--- a/public/assets/js/lib/views/index/lastlog.js
+++ b/public/assets/js/lib/views/index/lastlog.js
@@ -23,7 +23,7 @@ var LastLog = View.extend({
},
parse: function(user){
- if (Date.now()/1000 - user.lastseen > 86400 * 14 *10000) return ''
+ if (Date.now()/1000 - user.lastseen > 86400 * 5 *10) return ''
var t = this.template
.replace(/{{username}}/g, user.username)
.replace(/{{age}}/g, get_age(user.lastseen) )
diff --git a/public/assets/js/lib/views/index/threadform.js b/public/assets/js/lib/views/index/threadform.js
new file mode 100644
index 0000000..2ea6988
--- /dev/null
+++ b/public/assets/js/lib/views/index/threadform.js
@@ -0,0 +1,53 @@
+var ThreadForm = FormView.extend({
+
+ el: "#thread_form",
+
+ events: {
+ },
+
+ action: "/api/thread",
+
+ initialize: function(){
+ this.__super__.initialize.call(this)
+ this.template = this.$(".template").html()
+ },
+
+ load: function(selected_keyword){
+ $.get("/api/keywords", function(data){
+ var tags = {}
+ data.keywords.forEach(keyword => {
+ var kw = keyword.keyword
+ var opt = document.createElement('option')
+ opt.value = kw
+ opt.innerHTML = kw
+ if (selected_keyword === kw) {
+ opt.setAttribute("selected", "selected")
+ }
+ tags[kw] = opt
+ })
+ var sorted = Object.keys(tags).sort().map(kw => tags[kw])
+ this.$('[name=keyword]').append(sorted)
+ }.bind(this))
+ },
+
+ validate: function(){
+ var errors = []
+ var title = this.$("[name=title]").val()
+ if (! title || ! title.length) {
+ errors.push("Please title your post.")
+ }
+ var comment = this.$("[name=comment]").val()
+ var files = this.$("[name=files]").val()
+ if ((! comment || ! comment.length) && ! files) {
+ errors.push("Please enter a comment.")
+ }
+ return errors.length ? errors : null
+ },
+
+ success: function(data){
+ if (data.error) {
+ return alert(data.error)
+ }
+ window.location.href = "/details/" + data.id
+ }
+}) \ No newline at end of file