diff options
| author | rubenwardy <rw@rubenwardy.com> | 2018-12-25 17:51:29 +0000 |
|---|---|---|
| committer | rubenwardy <rw@rubenwardy.com> | 2018-12-25 17:51:29 +0000 |
| commit | 09150a4dbb74e9fb0d9fe4bdc5ced3ac246cd0e9 (patch) | |
| tree | 6a79e990698c72053a396456f04ed8b7af0d4981 /app/public/static | |
| parent | c726f56b3edbc2b97b82b777bada83a2097acb80 (diff) | |
| download | cheatdb-09150a4dbb74e9fb0d9fe4bdc5ced3ac246cd0e9.tar.xz | |
Allow users to discard their own topics
Diffstat (limited to 'app/public/static')
| -rw-r--r-- | app/public/static/topic_discard.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/public/static/topic_discard.js b/app/public/static/topic_discard.js new file mode 100644 index 0000000..efc4272 --- /dev/null +++ b/app/public/static/topic_discard.js @@ -0,0 +1,29 @@ +$(".topic-discard").click(function() { + var ele = $(this); + var tid = ele.attr("data-tid"); + var discard = !ele.parent().parent().hasClass("discardtopic"); + fetch(new Request("/api/topic_discard/?tid=" + tid + + "&discard=" + (discard ? "true" : "false"), { + method: "post", + credentials: "same-origin", + headers: { + "Accept": "application/json", + "X-CSRFToken": csrf_token, + }, + })).then(function(response) { + response.text().then(function(txt) { + console.log(JSON.parse(txt)); + if (JSON.parse(txt).discarded) { + ele.parent().parent().addClass("discardtopic"); + ele.removeClass("btn-danger"); + ele.addClass("btn-success"); + ele.text("Show"); + } else { + ele.parent().parent().removeClass("discardtopic"); + ele.removeClass("btn-success"); + ele.addClass("btn-danger"); + ele.text("Discard"); + } + }).catch(console.log) + }).catch(console.log) +}); |
