summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-12 04:41:13 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-12 04:41:13 +0100
commit041efed20500c145a639d8303c2a0e770bba4552 (patch)
tree8a8c00ac93589036b1b917a8f3e58e06670e1f33
parentd4ece4ab1f461653c53bb56f23406c553ea78dd3 (diff)
hoot order!
-rw-r--r--bucky/app/bucky.js25
-rw-r--r--bucky/app/router.js29
-rw-r--r--public/assets/css/bucky.css8
-rw-r--r--public/assets/js/lib/views/details/commentform.js3
-rw-r--r--public/assets/js/lib/views/details/comments.js10
-rw-r--r--public/assets/js/lib/views/details/index.js6
-rw-r--r--public/assets/js/lib/views/details/settings.js27
-rw-r--r--public/assets/js/vendor/view/formview.js2
-rw-r--r--views/partials/settings.ejs11
9 files changed, 95 insertions, 26 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 6ec76a0..41c3bff 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -158,7 +158,6 @@ var bucky = module.exports = {
next()
})
},
-
ensureCommentsForThread: function (req, res, next){
db.getCommentsForThread(res.thread.get('id')).then(function(comments){
res.comments = comments || []
@@ -180,6 +179,30 @@ var bucky = module.exports = {
res.thread.set('lastmodified', util.now())
res.thread.save().then( () => next() )
},
+ updateThreadSettings: function (req, res, next){
+ var title = util.sanitize(req.body.title || "")
+ if (! title || ! title.length) {
+ return res.sendStatus(500)
+ }
+ var keyword = util.sanitize(req.body.keyword || "")
+ var settings
+ if (typeof req.body.settings === 'object') {
+ try {
+ settings = JSON.stringify(req.body.settings)
+ } catch(e) {
+ }
+ }
+ if (! settings) {
+ return res.sendStatus(500)
+ }
+ res.thread.set('title', title)
+ res.thread.set('keyword', keyword)
+ res.thread.set('color', util.sanitize(req.body.color || 'blue'))
+ res.thread.set('revision', res.thread.get('revision')+1)
+ res.thread.set('settings', settings)
+ res.thread.save().then( () => next() )
+ },
+
destroyThread: function (req, res, next) {
console.log(">>> destroying thread", res.thread.get('id'))
var commentPromises = res.comments.map((comment) => {
diff --git a/bucky/app/router.js b/bucky/app/router.js
index bac5e42..2e690fb 100644
--- a/bucky/app/router.js
+++ b/bucky/app/router.js
@@ -128,6 +128,25 @@ module.exports = function(app){
function(req, res){
res.json(res.thread)
})
+ app.put("/api/thread/:id",
+ middleware.ensureAuthenticated,
+ bucky.ensureThread,
+ bucky.checkThreadPrivacy,
+ bucky.updateThreadSettings,
+ function(req, res){
+ res.json({ status: 'ok' })
+ })
+ app.delete("/api/thread/:id",
+ middleware.ensureAuthenticated,
+ bucky.ensureThread,
+ bucky.checkThreadPrivacy,
+ bucky.ensureCommentsForThread,
+ bucky.ensureFilesForThread,
+ bucky.destroyThread,
+ function(req, res){
+ res.sendStatus(200)
+ })
+
app.post("/api/thread/:id/comment",
middleware.ensureAuthenticated,
bucky.ensureThread,
@@ -168,16 +187,6 @@ module.exports = function(app){
function(req, res){
res.sendStatus(200)
})
- app.delete("/api/thread/:id",
- middleware.ensureAuthenticated,
- bucky.ensureThread,
- bucky.checkThreadPrivacy,
- bucky.ensureCommentsForThread,
- bucky.ensureFilesForThread,
- bucky.destroyThread,
- function(req, res){
- res.sendStatus(200)
- })
app.get("/search/",
middleware.ensureAuthenticated,
diff --git a/public/assets/css/bucky.css b/public/assets/css/bucky.css
index 5d4a1a6..1ba5010 100644
--- a/public/assets/css/bucky.css
+++ b/public/assets/css/bucky.css
@@ -484,7 +484,7 @@ pre br {
width: 100%;
font-family: 'Trebuchet MS', sans-serif;
padding: 5px;
- font-size: 15px;
+ font-size: 13px;
background: white;
border-color: #ddd;
height: 240px;
@@ -498,6 +498,11 @@ pre br {
height: 30px;
opacity: 0.4;
}
+.black #comment_form textarea:invalid::placeholder {
+ color: #fff;
+ padding-bottom: 4px;
+ border-bottom: 1px solid #fff;
+}
#comment_form.focused textarea {
background: white;
height: 240px;
@@ -597,6 +602,7 @@ pre br {
left: 50%;
transform: translate3d(-50%,-20%,0);
background: white;
+ color: #333;
border: 1px solid #ddd;
box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
diff --git a/public/assets/js/lib/views/details/commentform.js b/public/assets/js/lib/views/details/commentform.js
index e082248..b3f37bc 100644
--- a/public/assets/js/lib/views/details/commentform.js
+++ b/public/assets/js/lib/views/details/commentform.js
@@ -16,6 +16,9 @@ var CommentForm = FormView.extend({
load: function(thread){
this.action = "/api/thread/" + thread.id + "/comment"
+ if (thread.settings.noupload) {
+ this.$("[type=file]").hide()
+ }
},
focus: function(){
diff --git a/public/assets/js/lib/views/details/comments.js b/public/assets/js/lib/views/details/comments.js
index 473fb22..4c217a4 100644
--- a/public/assets/js/lib/views/details/comments.js
+++ b/public/assets/js/lib/views/details/comments.js
@@ -14,8 +14,14 @@ var CommentsView = FormView.extend({
this.$formRow = this.$("#comment_form")
},
- load: function(comments){
- comments.forEach(this.appendComment.bind(this))
+ load: function(comments, thread){
+ if (thread.settings.hootbox) {
+ comments.forEach(this.prependComment.bind(this))
+ this.$el.prepend(this.$formRow)
+ }
+ else {
+ comments.forEach(this.appendComment.bind(this))
+ }
},
parse: function(comment){
diff --git a/public/assets/js/lib/views/details/index.js b/public/assets/js/lib/views/details/index.js
index f8e9d50..871ac62 100644
--- a/public/assets/js/lib/views/details/index.js
+++ b/public/assets/js/lib/views/details/index.js
@@ -37,9 +37,9 @@ var DetailsView = View.extend({
$(".metadata").html(metadata(thread))
$(".settings_link").attr("href", "/details/" + thread.id + "/settings")
this.form.load(data.thread)
- this.comments.load(data.comments)
- this.files.load(data.files)
- this.gallery.load(data.files)
+ this.comments.load(data.comments, data.thread)
+ this.files.load(data.files, data.thread)
+ this.gallery.load(data.files, data.thread)
if (data.thread.keyword) {
$.get(this.keywordAction + data.thread.keyword, this.populateKeyword.bind(this))
}
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js
index eacbec4..777a9ba 100644
--- a/public/assets/js/lib/views/details/settings.js
+++ b/public/assets/js/lib/views/details/settings.js
@@ -19,9 +19,6 @@ var ThreadSettingsForm = FormView.extend({
},
populate: function(){
- // this.action = "/api/thread/" + data.id
- $("body").removeClass("loading")
-
var data = this.options.parent.data
var keywords = data.keywords
var keyword = data.keyword
@@ -31,10 +28,16 @@ var ThreadSettingsForm = FormView.extend({
var settings = thread.settings
var display = thread.display
+ this.action = "/api/thread/" + thread.id
+
this.$(".close_link").attr("href", "/details/" + thread.id)
this.$(".metadata").html(metadata(thread))
this.$("[name=title]").val(sanitize(thread.title))
+ this.$("[name=hootbox]").prop("checked", !!thread.settings.hootbox)
+ this.$("[name=shorturls]").prop("checked", !!thread.settings.shorturls)
+ this.$("[name=noupload]").prop("checked", !!thread.settings.noupload)
+
var $color = this.$('[name=color]')
Object.keys(COLORS).forEach((color) => {
var option = document.createElement('option')
@@ -57,6 +60,8 @@ var ThreadSettingsForm = FormView.extend({
})
$keyword.val(thread.keyword)
}.bind(this))
+
+ $("body").removeClass("loading")
},
validate: function(){
@@ -67,12 +72,24 @@ var ThreadSettingsForm = FormView.extend({
}
return errors.length ? errors : null
},
-
+
serialize: function(){
+ var data = {
+ title: $("[name=title]").val(),
+ keyword: $("[name=keyword]").val(),
+ color: $("[name=color]").val(),
+ settings: {
+ hootbox: $("[name=hootbox]:checked").val() ? true : false,
+ shorturls: $("[name=shorturls]:checked").val() ? true : false,
+ noupload: $("[name=noupload]:checked").val() ? true : false,
+ }
+ }
+ return JSON.stringify(data)
},
success: function(data){
- window.location.href = "/details/" + data.comment.thread
+ console.log(data)
+ window.location.href = "/details/" + this.options.parent.data.thread.id
},
visible: false,
diff --git a/public/assets/js/vendor/view/formview.js b/public/assets/js/vendor/view/formview.js
index 6da7db6..1f681cb 100644
--- a/public/assets/js/vendor/view/formview.js
+++ b/public/assets/js/vendor/view/formview.js
@@ -100,7 +100,7 @@ var FormView = View.extend({
dataType: "json",
processData: false,
success: function(response){
- // console.log(response)
+ console.log(response)
if (response.error) {
var errors = []
for (var key in response.error.errors) {
diff --git a/views/partials/settings.ejs b/views/partials/settings.ejs
index adf184e..d36cf6c 100644
--- a/views/partials/settings.ejs
+++ b/views/partials/settings.ejs
@@ -29,9 +29,14 @@
<select id="thread_keyword" name="keyword"></select>
</div>
<div>
- <label for="thread_hoots">hoot style</label>
- <input id="thread_hoots" name="hoots" value="0" type="hidden">
- <input id="thread_hoots" name="hoots" value="1" type="checkbox">
+ <label for="thread_hootbox">hoot style</label>
+ <input id="thread_hootbox" name="hootbox" value="0" type="hidden">
+ <input id="thread_hootbox" name="hootbox" value="1" type="checkbox">
+ </div>
+ <div>
+ <label for="thread_noupload">disable uploads</label>
+ <input id="thread_noupload" name="noupload" value="0" type="hidden">
+ <input id="thread_noupload" name="noupload" value="1" type="checkbox">
</div>
<div>
<label for="thread_shorturls">shorten urls</label>