From 2adb779fefa8f0aae10abc7e0da9ecb761088eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Latinier?= Date: Tue, 6 Dec 2016 23:03:27 +0100 Subject: [PATCH] add: edit author/email/website/message --- isso/css/admin.css | 9 +++++ isso/templates/admin.html | 79 ++++++++++++++++++++++++++++++++++++--- isso/views/comments.py | 17 ++++++--- 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/isso/css/admin.css b/isso/css/admin.css index 5a434fc..c440528 100644 --- a/isso/css/admin.css +++ b/isso/css/admin.css @@ -123,3 +123,12 @@ a { float: left; margin-left: 2em; } +.editable { + border: 1px solid #aaa; + border-radius: 5px; + margin: 10px; + padding: 5px; +} +.hidden { + display: none; +} diff --git a/isso/templates/admin.html b/isso/templates/admin.html index 376aa59..12ac60c 100644 --- a/isso/templates/admin.html +++ b/isso/templates/admin.html @@ -39,12 +39,72 @@ function moderate(com_id, hash, action) { fade(document.getElementById("isso-" + com_id)); }}); } +function edit(com_id, hash, author, email, website, comment) { + ajax({method: "POST", + url: "/id/" + com_id + "/edit/" + hash, + data: JSON.stringify({text: comment, + author: author, + email: email, + website: website}), + success: function(ret){ + console.log("edit successed: ", ret);// TODO display some pretty stuff & update msg + }, + error: function(ret){ + console.log("Error: ", ret); // TODO flash msg/notif + }}); +} function validate_com(com_id, hash) { moderate(com_id, hash, "validate"); } function delete_com(com_id, hash) { moderate(com_id, hash, "delete"); } +function unset_editable(elt_id) { + var elt = document.getElementById(elt_id); + if (elt) { + elt.contentEditable = false; + elt.classList.remove("editable"); + } +} +function set_editable(elt_id) { + var elt = document.getElementById(elt_id); + if (elt) { + elt.contentEditable = true; + elt.classList.add("editable"); + } +} +function start_edit(com_id) { + var editable_elements = ['isso-author-' + com_id, + 'isso-email-' + com_id, + 'isso-website-' + com_id, + 'isso-text-' + com_id]; + for (var idx=0; idx <= editable_elements.length; idx++) { + set_editable(editable_elements[idx]); + } + document.getElementById('edit-btn-' + com_id).classList.toggle('hidden'); + document.getElementById('stop-edit-btn-' + com_id).classList.toggle('hidden'); + document.getElementById('send-edit-btn-' + com_id).classList.toggle('hidden'); +} +function stop_edit(com_id) { + var editable_elements = ['isso-author-' + com_id, + 'isso-email-' + com_id, + 'isso-website-' + com_id, + 'isso-text-' + com_id]; + for (var idx=0; idx <= editable_elements.length; idx++) { + unset_editable(editable_elements[idx]); + } + document.getElementById('edit-btn-' + com_id).classList.toggle('hidden'); + document.getElementById('stop-edit-btn-' + com_id).classList.toggle('hidden'); + document.getElementById('send-edit-btn-' + com_id).classList.toggle('hidden'); +} +function send_edit(com_id, hash) { + var author = document.getElementById('isso-author-' + com_id).textContent; + var email = document.getElementById('isso-email-' + com_id).textContent; + var website = document.getElementById('isso-website-' + com_id).textContent; + var comment = document.getElementById('isso-text-' + com_id).textContent; + edit(com_id, hash, author, email, website, comment); + stop_edit(com_id); +}
@@ -130,18 +190,22 @@ function delete_com(com_id, hash) {
{% if order_by != "tid" %} - Thread: {{comment.title}}
+
Thread: {{comment.title}}

{% endif %} {% if comment.author %} - {{comment.author}} + {{comment.author}} {% else %} - Anonymous + Anonymous {% endif %} {% if comment.email %} - + ({{comment.email}} ) + {% else %} + {% endif %} {% if comment.website %} - ({{comment.website}}) + ({{comment.website}} open) + {% else %} + {% endif %} @@ -159,13 +223,16 @@ function delete_com(com_id, hash) { {% if comment.mode == 4 %} HIDDEN. Original text:
{% endif %} - {{comment.text}} +
{{comment.text}}