From e125601f52ac43a48a47fc1f4af8868981e6e23b Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby <comby@crans.org> Date: Thu, 26 Mar 2020 17:48:17 +0100 Subject: [PATCH] almost working javascript --- templates/member/profile_alias.html | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/templates/member/profile_alias.html b/templates/member/profile_alias.html index dafc8e5a..9d2c34a3 100644 --- a/templates/member/profile_alias.html +++ b/templates/member/profile_alias.html @@ -4,3 +4,37 @@ {% block profile_content %} {% include "member/alias_update.html"%} {% endblock %} + +{% block extrajavascript %} +<script> + function create_alias(note_id){ + $.post("/api/note/alias/", + { + "csrfmiddlewaretoken": CSRF_TOKEN, + "name": $("#alias_input").val(), + "note": note_id + } + ).done(function(){ + $("#alias_table").load("{% url 'member:user_alias' object.pk %} #alias_table"); + }) + .fail(function(xhr, textStatus, error){ + addMsg(xhr.responseJSON.name[0],'danger'); + }); +} + // on click of button "delete" , call the API + function delete_button(button_id){ + $.ajax({ + url:"/api/note/alias/"+button_id+"/", + method:"DELETE", + headers: {"X-CSRFTOKEN": CSRF_TOKEN} + }) + .done(function(){ + addMsg('{% trans "alias successfully deleted "%}','success'); + $("#alias_table").load("{% url 'member:user_alias' object.pk %} #alias_table"); + }) + .fail(function(){ + addMsg(' {% trans "Unable to delete alias "%} #' + button_id,'danger' ) + }); + } +</script> +{% endblock%} -- GitLab