diff --git a/journalmarks/journalmarks.py b/journalmarks/journalmarks.py index 1515fb8..70d033c 100644 --- a/journalmarks/journalmarks.py +++ b/journalmarks/journalmarks.py @@ -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(): diff --git a/journalmarks/templates/overview.html b/journalmarks/templates/overview.html index 0acddef..73f5c17 100644 --- a/journalmarks/templates/overview.html +++ b/journalmarks/templates/overview.html @@ -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() { })); }); 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 { td div { word-break: break-all; } +.really-delete { + display: none; +} {% endblock %} @@ -104,7 +122,15 @@ td div { Created: Comment:
- + {% endblock %}