Commit a0eb23a1 authored by berumuron's avatar berumuron
Browse files

imp: Improve delete button

parent c7b5ef3b
......@@ -44,7 +44,7 @@ def create():
return render_template("events/create.html", today_date=today_date)
@bp.route("/delete/<event_id>", methods=["GET"])
@bp.route("/delete/<event_id>", methods=["DELETE"])
@login_required
def delete(event_id):
event = Event.find_by_id(event_id)
......
......@@ -361,6 +361,22 @@ button.button-ghost {
content: "🔒";
}
.events .event .event-delete {
position: absolute;
right: 0;
opacity: 0;
visibility: hidden;
transition: opacity .2s ease-out;
}
.events .event:hover .event-delete {
opacity: 1;
visibility: visible;
}
.events .event .event-delete::before {
content: "🗑";
}
/* Folder system */
.folder.folder-folded .folder-container {
display: none;
......
......@@ -17,4 +17,36 @@
}
});
});
var buttonsToConfirm = document.querySelectorAll('button[data-confirm]');
buttonsToConfirm.forEach(function (button) {
button.addEventListener('click', function (e) {
var message = e.target.getAttribute('data-confirm');
if (!window.confirm(message)) {
e.preventDefault();
}
});
});
var buttonsToAction = document.querySelectorAll('button[data-action]');
buttonsToAction.forEach(function (button) {
button.addEventListener('click', function (e) {
if (e.defaultPrevented) {
return false;
}
var action = e.target.getAttribute('data-action');
var method = e.target.getAttribute('data-method') || 'get';
window.fetch(action, { method: method.toUpperCase() })
.then(function (response) {
if (response.redirected) {
window.location = response.url;
}
})
.catch(function (error) {
console.error(error, error.stack);
window.alert('Une erreur sauvage est apparue ! (et on sait pas encore bien la gérer) Si tu sais faire, peux-tu ouvrir la console de ton navigateur et envoyer aux développeur·euses ce qui apparaît dedans ?');
});
});
});
}());
......@@ -53,9 +53,14 @@
{% endif %}
{% if g.current_user %}
<button onclick="confirmDelete('{{ url_for('events.delete', event_id=event.id ) }}')">
🗑
</button>
<button
class="button-ghost event-delete"
data-confirm="Êtes-vous certain·e de vouloir supprimer cet évènement ?"
data-action="{{ url_for('events.delete', event_id=event.id ) }}"
data-method="delete"
>
Supprimer
</button>
{% endif %}
</li>
{% endfor %}
......@@ -66,12 +71,4 @@
</div>
{% endfor %}
</div>
<script>
function confirmDelete(deleteUrl) {
if (window.confirm("Êtes-vous sûr.e de vouloir supprimer cet évènement ?")) {
window.location = deleteUrl;
}
}
</script>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment