summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/lib/router.js7
-rw-r--r--public/assets/js/lib/views/details/index.js7
-rw-r--r--public/assets/js/lib/views/details/settings.js43
-rw-r--r--public/assets/js/util/color.js3
4 files changed, 51 insertions, 9 deletions
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js
index f9850e8..a83437a 100644
--- a/public/assets/js/lib/router.js
+++ b/public/assets/js/lib/router.js
@@ -82,4 +82,11 @@ var SiteRouter = Router.extend({
app.view.load()
},
+ error404: function(){
+ $("content").hide()
+ $("#error_404").show()
+ $("h1").html("error: page not found")
+ $("body").removeClass("loading")
+ },
+
}) \ 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 5550173..f8e9d50 100644
--- a/public/assets/js/lib/views/details/index.js
+++ b/public/assets/js/lib/views/details/index.js
@@ -18,7 +18,12 @@ var DetailsView = View.extend({
load: function(id){
id = id.replace(/\D/g, "")
- $.get(this.action + id, this.populate.bind(this))
+ $.ajax({
+ method: "get",
+ url: this.action + id,
+ success: this.populate.bind(this),
+ error: app.router.error404,
+ })
},
populate: function(data){
diff --git a/public/assets/js/lib/views/details/settings.js b/public/assets/js/lib/views/details/settings.js
index 6e6b0b2..eacbec4 100644
--- a/public/assets/js/lib/views/details/settings.js
+++ b/public/assets/js/lib/views/details/settings.js
@@ -5,7 +5,9 @@ var ThreadSettingsForm = FormView.extend({
events: {
"click": "hide",
"click .inner": "stopPropagation",
- "click .close_link": "hide"
+ "click .thread_delete": "deleteThread",
+ "click .close_link": "hide",
+ "change [name=color]": "changeColor",
},
action: "",
@@ -28,7 +30,7 @@ var ThreadSettingsForm = FormView.extend({
var files = data.files
var settings = thread.settings
var display = thread.display
-
+
this.$(".close_link").attr("href", "/details/" + thread.id)
this.$(".metadata").html(metadata(thread))
this.$("[name=title]").val(sanitize(thread.title))
@@ -55,17 +57,19 @@ var ThreadSettingsForm = FormView.extend({
})
$keyword.val(thread.keyword)
}.bind(this))
- console.log(thread)
},
validate: function(){
var errors = []
- var comment = $("[name=comment]").val()
- if (! comment || ! comment.length) {
- errors.push("Please enter a comment.")
+ var title = $("[name=title]").val()
+ if (! title || ! title.length) {
+ errors.push("Please enter a title.")
}
return errors.length ? errors : null
},
+
+ serialize: function(){
+ },
success: function(data){
window.location.href = "/details/" + data.comment.thread
@@ -91,5 +95,32 @@ 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)
+ },
+
+ deleteThread: function(e){
+ var data = this.options.parent.data
+ var id = data.thread.id
+ var comment_count = (data.comments || []).length
+ var file_count = (data.files || []).length
+ var msg = "Are you sure you want to delete this thread?\n\n#" + id + ' "' + sanitize(data.thread.title) + '"'
+ msg += " + " + comment_count + " comment" + courtesy_s(comment_count)
+ if ( file_count) msg += " + " + file_count + " file" + courtesy_s(file_count)
+ var should_remove = confirm(msg)
+ if (should_remove) {
+ $.ajax({
+ method: "DELETE",
+ url: "/api/thread/" + id,
+ headers: { "csrf-token": $("[name=_csrf]").attr("value") },
+ data: { csrf: csrf() },
+ success: function(){
+ window.location.href = "/"
+ },
+ })
+ }
+ },
}) \ No newline at end of file
diff --git a/public/assets/js/util/color.js b/public/assets/js/util/color.js
index bcdfe77..6d33a72 100644
--- a/public/assets/js/util/color.js
+++ b/public/assets/js/util/color.js
@@ -110,12 +110,11 @@ function set_background_color_from_time(){
set_background_color(color_name)
}
function set_background_color(color_name){
- console.log(color_name)
color_name = color_name || "plain"
var color = COLORS[color_name]
.clone()
.mottleRGB(4,4,8)
// .add(nighttime_quotient())
-console.log(color.toString())
document.body.style.backgroundColor = color.toString()
+ $(document.body).toggleClass("black", color_name === "black")
}