1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-30 19:32:21 +00:00
nk20/templates/note/transactiontemplate_list.html

79 lines
2.7 KiB
HTML
Raw Normal View History

2019-08-11 17:55:04 +00:00
{% extends "base.html" %}
2020-02-03 14:20:37 +00:00
{% load pretty_money %}
2020-03-23 19:21:25 +00:00
{% load i18n %}
{% load render_table from django_tables2 %}
2019-08-11 17:55:04 +00:00
{% block content %}
2020-03-23 19:21:25 +00:00
<div class="row justify-content-center mb-4">
<div class="col-md-10 text-center">
<h4>
{% trans "search button" %}
</h4>
2020-03-23 23:07:25 +00:00
<input class="form-control mx-auto w-25" type="text" onkeyup="search_field_moved();return(false);" id="search_field"/>
2020-03-23 19:21:25 +00:00
<hr>
2020-03-26 16:41:11 +00:00
<a class="btn btn-primary text-center my-1" href="{% url 'note:template_create' %}">{% trans "New button" %}</a>
2020-03-23 19:21:25 +00:00
</div>
</div>
<div class="row justify-content-center">
2020-03-24 23:03:48 +00:00
<div class="col-md-10">
<div class="card card-border shadow">
<div class="card-header text-center">
<h5> {% trans "buttons listing "%}</h5>
</div>
<div class="card-body px-0 py-0" id="buttons_table">
{% render_table table %}
</div>
2020-03-24 21:12:44 +00:00
</div>
</div>
2020-03-23 19:21:25 +00:00
</div>
2019-08-11 17:55:04 +00:00
{% endblock %}
2020-03-23 23:07:25 +00:00
{% block extrajavascript %}
<script>
/* fonction appelée à la fin du timer */
function getInfo() {
var asked = $("#search_field").val();
/* on ne fait la requête que si on a au moins un caractère pour chercher */
var sel = $(".table-row");
if (asked.length >= 1) {
$.getJSON("/api/note/transaction/template/?format=json&search="+asked, function(buttons){
let selected_id = buttons.results.map((a => "#row-"+a.id));
$(".table-row,"+selected_id.join()).show();
$(".table-row").not(selected_id.join()).hide();
});
}else{
// show everything
$('table tr').show();
}
}
var timer;
var timer_on;
/* Fontion appelée quand le texte change (délenche le timer) */
function search_field_moved(secondfield) {
if (timer_on) { // Si le timer a déjà été lancé, on réinitialise le compteur.
clearTimeout(timer);
timer = setTimeout("getInfo(" + secondfield + ")", 300);
}
else { // Sinon, on le lance et on enregistre le fait qu'il tourne.
timer = setTimeout("getInfo(" + secondfield + ")", 300);
timer_on = true;
}
}
2020-03-24 21:12:44 +00:00
// on click of button "delete" , call the API
function delete_button(button_id){
$.ajax({
2020-03-24 22:27:08 +00:00
url:"/api/note/transaction/template/"+button_id+"/",
2020-03-24 21:12:44 +00:00
method:"DELETE",
2020-03-24 22:02:12 +00:00
headers: {"X-CSRFTOKEN": CSRF_TOKEN}
})
.done(function(){
addMsg('{% trans "button successfully deleted "%}','success');
$("#buttons_table").load("{% url 'note:template_list' %} #buttons_table");
})
2020-03-24 22:27:08 +00:00
.fail(function(){
addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' )
});
2020-03-24 22:02:12 +00:00
}
2020-03-23 23:07:25 +00:00
</script>
{% endblock %}