Browse Source

deletion feature

master
Fr3deric 7 years ago
parent
commit
df1edc8cab
  1. 16
      journalmarks/journalmarks.py
  2. 28
      journalmarks/templates/overview.html

16
journalmarks/journalmarks.py

@ -161,6 +161,22 @@ def create(): @@ -161,6 +161,22 @@ def create():
return json.dumps(tag)
@journalmarks.route('/delete', methods=['POST'])
@login_required
def delete():
if len(request.json) != 1 or 'tag' not in request.json:
return ('invalid fields', 400, None)
tag = request.json['tag']
try:
j = Journalmark.select().where(
(Journalmark.tag == tag) & (Journalmark.user == flask_g.user)
).get()
j.delete_instance()
except DoesNotExist:
return ('tag not found', 404, None)
return json.dumps('ok')
@journalmarks.route('/update', methods=['POST'])
@login_required
def update():

28
journalmarks/templates/overview.html

@ -23,6 +23,7 @@ function run() { @@ -23,6 +23,7 @@ function run() {
n.getElementsByClassName('tag')[0].innerText = j.tag;
n.getElementsByClassName('tag')[0].href = '/' + j.tag;
n.getElementsByClassName('url')[0].innerText = 'decrypting...';
n.getElementsByClassName('really-delete-yes')[0].dataset.tag = j.tag;
document.getElementById('journalmarks').appendChild(n);
decrs.push(journalmarks_decrypturl(j.content).then(function(url) {
n.getElementsByClassName('url')[0].href = url.url;
@ -37,6 +38,20 @@ function run() { @@ -37,6 +38,20 @@ function run() {
}));
});
return Promise.all(decrs);
}).then(function() {
Array.from(document.getElementsByClassName('delete')).forEach(function(elem) { elem.addEventListener('click', function(e) {
e.target.style.display = 'none';
e.target.parentElement.getElementsByClassName('really-delete')[0].style.display = 'inline';
})});
Array.from(document.getElementsByClassName('really-delete-yes')).forEach(function(elem) { elem.addEventListener('click', function(e) {
post_object('{{ url_for('journalmarks.delete') }}', {tag: e.target.dataset.tag}).then(function() {
window.location.href = '{{ url_for('journalmarks.overview') }}';
});
})});
Array.from(document.getElementsByClassName('really-delete-no')).forEach(function(elem) { elem.addEventListener('click', function(e) {
e.target.parentElement.style.display = 'none';
e.target.parentElement.parentElement.getElementsByClassName('delete')[0].style.display = 'inline';
})});
}).catch(function(error) {
console.log(error);
//deleteKey();
@ -86,6 +101,9 @@ td { @@ -86,6 +101,9 @@ td {
td div {
word-break: break-all;
}
.really-delete {
display: none;
}
</style>
{% endblock %}
@ -104,7 +122,15 @@ td div { @@ -104,7 +122,15 @@ td div {
<tr><td>Created:</td><td><span class="date"></td></tr>
<tr class="comment-row"><td>Comment:</td><td><div><span class="comment"></span></div></td></tr>
</table>
<p class="actionlinks"><a href="">edit comment</a> | <a href="">delete</a></p>
<p class="actionlinks">
<!--<button class="pure-button">edit comment</button>-->
<button class="pure-button delete">Delete</button>
<span class="really-delete">
Really delete?
<button class="pure-button really-delete-yes">Yes!</button>
<button class="pure-button really-delete-no">No!</button>
</span>
</p>
</div>
</div>
{% endblock %}

Loading…
Cancel
Save