summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details/settings.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-12 03:31:07 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-12 03:31:07 +0100
commit942a72123ecf7ed91cf3cba1124adc11a3615208 (patch)
tree42fa36700fd80c4903acb0ecb2b1e0bbdc8da2d6 /public/assets/js/lib/views/details/settings.js
parent41d0bd185c19c8a51ed9b85700f52181b6cc5012 (diff)
404 page and maybe deleting threads
Diffstat (limited to 'public/assets/js/lib/views/details/settings.js')
-rw-r--r--public/assets/js/lib/views/details/settings.js43
1 files changed, 37 insertions, 6 deletions
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