Allow users to discard their own topics

This commit is contained in:
rubenwardy
2018-12-25 17:51:29 +00:00
parent c726f56b3e
commit 09150a4dbb
6 changed files with 63 additions and 36 deletions

View File

@@ -59,7 +59,7 @@ Topics to be Added
</form>
{% from "macros/topics.html" import render_topics_table %}
{{ render_topics_table(topics, show_discard=True) }}
{{ render_topics_table(topics, show_discard=True, current_user=current_user) }}
<ul class="pagination mt-4">
<li class="page-item {% if not prev_url %}disabled{% endif %}">
@@ -83,35 +83,5 @@ Topics to be Added
<script>
var csrf_token = "{{ csrf_token() }}";
</script>
<script>
$(".topic-discard").click(function() {
var ele = $(this);
var tid = ele.attr("data-tid");
var discard = !ele.parent().parent().hasClass("discardtopic");
fetch(new Request("{{ url_for('topic_set_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)
});
</script>
<script src="/static/topic_discard.js"></script>
{% endblock %}