diff options
Diffstat (limited to 'public/assets/js/lib/views/details/settings.js')
| -rw-r--r-- | public/assets/js/lib/views/details/settings.js | 43 |
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 |
