add: edit author/email/website/message
This commit is contained in:
parent
e3fddf4ae8
commit
2adb779fef
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
</script>
|
||||
<div class="wrapper">
|
||||
<div class="header">
|
||||
@ -130,18 +190,22 @@ function delete_com(com_id, hash) {
|
||||
<div class='text-wrapper'>
|
||||
<div class='isso-comment-header' role='meta'>
|
||||
{% if order_by != "tid" %}
|
||||
Thread: {{comment.title}}<br />
|
||||
<div>Thread: {{comment.title}}</div><br />
|
||||
{% endif %}
|
||||
{% if comment.author %}
|
||||
<span class='author'>{{comment.author}}</span>
|
||||
<span class='author' id="isso-author-{{comment.id}}">{{comment.author}}</span>
|
||||
{% else %}
|
||||
<span class='author'>Anonymous</span>
|
||||
<span class='author' id="isso-author-{{comment.id}}">Anonymous</span>
|
||||
{% endif %}
|
||||
{% if comment.email %}
|
||||
<a href="mailto:{{comment.email}}" rel='nofollow' class='email'>({{comment.email}})</a>
|
||||
(<span id="isso-email-{{comment.id}}">{{comment.email}}</span> <a href="mailto:{{comment.email}}" rel='nofollow' class='email'>mailto</a>)
|
||||
{% else %}
|
||||
<span id="isso-email-{{comment.id}}"></span>
|
||||
{% endif %}
|
||||
{% if comment.website %}
|
||||
<a href="{{comment.website}}" rel='nofollow' class='website'>({{comment.website}})</a>
|
||||
(<span id="isso-website-{{comment.id}}">{{comment.website}}</span> <a href="{{comment.website}}" rel='nofollow' class='website'>open</a>)
|
||||
{% else %}
|
||||
<span id="isso-website-{{comment.id}}"></span>
|
||||
{% endif %}
|
||||
<span class="spacer"> •</span>
|
||||
<time>{{comment.created | datetimeformat}}</time>
|
||||
@ -159,13 +223,16 @@ function delete_com(com_id, hash) {
|
||||
{% if comment.mode == 4 %}
|
||||
<strong>HIDDEN</strong>. Original text: <br />
|
||||
{% endif %}
|
||||
{{comment.text}}
|
||||
<div id="isso-text-{{comment.id}}">{{comment.text}}</div>
|
||||
</div>
|
||||
<div class='isso-comment-footer'>
|
||||
{% if conf.votes and comment.likes - comment.dislikes != 0 %}
|
||||
<span class='votes'>{{comment.likes - comment.dislikes}}</span>
|
||||
{% endif %}
|
||||
<span class='spacer'></span>
|
||||
<a id="edit-btn-{{comment.id}}" class="edit" onClick="javascript:start_edit({{comment.id}})">Edit</a>
|
||||
<a id="stop-edit-btn-{{comment.id}}" class="hidden edit" onClick="javascript:stop_edit({{comment.id}})">Cancel</a>
|
||||
<a id="send-edit-btn-{{comment.id}}" class="hidden edit" onClick="javascript:send_edit({{comment.id}}, '{{comment.hash}}')">Send</a>
|
||||
{% if comment.mode != 4 %}
|
||||
<a class="delete"
|
||||
onClick="javascript:delete_com({{comment.id}}, '{{comment.hash}}')">
|
||||
|
@ -88,8 +88,8 @@ class API(object):
|
||||
('view', ('GET', '/id/<int:id>')),
|
||||
('edit', ('PUT', '/id/<int:id>')),
|
||||
('delete', ('DELETE', '/id/<int:id>')),
|
||||
('moderate',('GET', '/id/<int:id>/<any(activate,delete):action>/<string:key>')),
|
||||
('moderate',('POST', '/id/<int:id>/<any(activate,delete):action>/<string:key>')),
|
||||
('moderate',('GET', '/id/<int:id>/<any(edit,activate,delete):action>/<string:key>')),
|
||||
('moderate',('POST', '/id/<int:id>/<any(edit,activate,delete):action>/<string:key>')),
|
||||
('like', ('POST', '/id/<int:id>/like')),
|
||||
('dislike', ('POST', '/id/<int:id>/dislike')),
|
||||
('demo', ('GET', '/demo')),
|
||||
@ -318,7 +318,6 @@ class API(object):
|
||||
return resp
|
||||
|
||||
def moderate(self, environ, request, id, action, key):
|
||||
|
||||
try:
|
||||
id = self.isso.unsign(key, max_age=2**32)
|
||||
except (BadSignature, SignatureExpired):
|
||||
@ -348,12 +347,20 @@ class API(object):
|
||||
with self.isso.lock:
|
||||
self.comments.activate(id)
|
||||
self.signal("comments.activate", id)
|
||||
return Response("Yo", 200)
|
||||
elif action == "edit":
|
||||
data = request.get_json()
|
||||
with self.isso.lock:
|
||||
rv = self.comments.update(id, data)
|
||||
for key in set(rv.keys()) - API.FIELDS:
|
||||
rv.pop(key)
|
||||
self.signal("comments.edit", rv)
|
||||
return JSON(rv, 200)
|
||||
else:
|
||||
with self.isso.lock:
|
||||
self.comments.delete(id)
|
||||
self.cache.delete('hash', (item['email'] or item['remote_addr']).encode('utf-8'))
|
||||
self.signal("comments.delete", id)
|
||||
|
||||
return Response("Yo", 200)
|
||||
|
||||
@requires(str, 'uri')
|
||||
|
Loading…
Reference in New Issue
Block a user