move common script to alias.js

This commit is contained in:
Pierre-antoine Comby 2020-03-26 23:05:08 +01:00
parent 49dd88dbb7
commit f7a66920e0
3 changed files with 42 additions and 31 deletions

37
static/js/alias.js Normal file
View File

@ -0,0 +1,37 @@
$("#alias_input").on('keypress',function(e) {
if(e.which == 13) {
$("#alias_submit").click();
}
});
function create_alias(note_id){
$.post("/api/note/alias/",
{
"csrfmiddlewaretoken": CSRF_TOKEN,
"name": $("#alias_input").val(),
"note": note_id
}
).done(function(){
$("#alias_table").load(location.href+ " #alias_table");
addMsg("Alias ajouté","success");
})
.fail(function(xhr, textStatus, error){
errMsg(xhr.responseJSON);
});
}
// 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('Alias supprimé','success');
$("#alias_table").load(location.href + " #alias_table");
})
.fail(function(xhr,textStatus, error){
errMsg(xhr.responseJSON);
});
}

View File

@ -4,3 +4,7 @@
{% block profile_content %} {% block profile_content %}
{% include "member/alias_update.html" %} {% include "member/alias_update.html" %}
{% endblock %} {% endblock %}
{% block extrajavascript %}
<script src="/static/js/alias.js"></script>
{% endblock%}

View File

@ -6,35 +6,5 @@
{% endblock %} {% endblock %}
{% block extrajavascript %} {% block extrajavascript %}
<script> <script src="/static/js/alias.js"></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%} {% endblock%}