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 %}
|
2020-03-09 19:59:04 +00:00
|
|
|
{% 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">
|
2020-08-18 12:27:04 +00:00
|
|
|
{# Search field , see js #}
|
2020-08-15 17:47:29 +00:00
|
|
|
<input class="form-control mx-auto w-25" type="text" id="search_field" placeholder="{% trans "Name of the button..." %}" value="{{ request.GET.search }}">
|
2020-03-23 19:21:25 +00:00
|
|
|
<hr>
|
2020-08-09 13:31:38 +00:00
|
|
|
<a class="btn btn-primary text-center my-1" href="{% url 'note:template_create' %}" data-turbolinks="false">{% trans "New button" %}</a>
|
2020-03-23 19:21:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row justify-content-center">
|
2020-08-15 18:04:19 +00:00
|
|
|
<div class="col-md-12">
|
2020-03-24 23:03:48 +00:00
|
|
|
<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 %}
|
2020-07-30 13:49:59 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
|
|
|
let searchbar_obj = $("#search_field");
|
2020-08-15 17:47:29 +00:00
|
|
|
let timer_on = false;
|
|
|
|
let timer;
|
|
|
|
|
|
|
|
function refreshMatchedWords() {
|
|
|
|
$("tr").each(function() {
|
|
|
|
let pattern = searchbar_obj.val();
|
|
|
|
if (pattern) {
|
|
|
|
$(this).find("td:eq(0), td:eq(1), td:eq(3), td:eq(6)").each(function () {
|
|
|
|
$(this).html($(this).text().replace(new RegExp(pattern, 'i'), "<mark>$&</mark>"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshMatchedWords();
|
2020-04-27 01:56:22 +00:00
|
|
|
|
2020-07-30 13:49:59 +00:00
|
|
|
function reloadTable() {
|
|
|
|
let pattern = searchbar_obj.val();
|
2020-08-15 17:47:29 +00:00
|
|
|
$("#buttons_table").load(location.pathname + "?search=" + pattern.replace(" ", "%20") + " #buttons_table", refreshMatchedWords);
|
2020-04-27 01:56:22 +00:00
|
|
|
}
|
2020-07-30 13:49:59 +00:00
|
|
|
|
|
|
|
searchbar_obj.keyup(function() {
|
|
|
|
if (timer_on)
|
|
|
|
clearTimeout(timer);
|
2020-04-27 01:56:22 +00:00
|
|
|
timer_on = true;
|
2020-07-30 13:49:59 +00:00
|
|
|
setTimeout(reloadTable, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-27 01:56:22 +00:00
|
|
|
// on click of button "delete" , call the API
|
|
|
|
function delete_button(button_id) {
|
|
|
|
$.ajax({
|
2020-07-30 13:49:59 +00:00
|
|
|
url:"/api/note/transaction/template/" + button_id + "/",
|
2020-04-27 01:56:22 +00:00
|
|
|
method:"DELETE",
|
|
|
|
headers: {"X-CSRFTOKEN": CSRF_TOKEN}
|
|
|
|
})
|
2020-07-30 13:49:59 +00:00
|
|
|
.done(function() {
|
2020-04-27 01:56:22 +00:00
|
|
|
addMsg('{% trans "button successfully deleted "%}','success');
|
2020-07-30 13:49:59 +00:00
|
|
|
$("#buttons_table").load(location.pathname + "?search=" + $("#search_field").val().replace(" ", "%20") + " #buttons_table");
|
2020-04-27 01:56:22 +00:00
|
|
|
})
|
2020-07-30 13:49:59 +00:00
|
|
|
.fail(function() {
|
|
|
|
addMsg('{% trans "Unable to delete button "%} #' + button_id, 'danger')
|
2020-04-27 01:56:22 +00:00
|
|
|
});
|
|
|
|
}
|
2020-03-23 23:07:25 +00:00
|
|
|
</script>
|
|
|
|
{% endblock %}
|