2019-08-11 17:55:04 +00:00
|
|
|
{% extends "base.html" %}
|
2020-09-01 08:20:16 +00:00
|
|
|
{% comment %}
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
{% endcomment %}
|
|
|
|
{% load pretty_money i18n %}
|
2020-03-09 19:59:04 +00:00
|
|
|
{% load render_table from django_tables2 %}
|
2020-09-01 08:20:16 +00:00
|
|
|
|
2019-08-11 17:55:04 +00:00
|
|
|
{% block content %}
|
2020-09-01 08:13:05 +00:00
|
|
|
<h1 class="text-white">{{ title }}</h1>
|
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">
|
2021-10-07 20:54:01 +00:00
|
|
|
function refreshMatchedWords() {
|
|
|
|
$("tr").each(function() {
|
|
|
|
let pattern = $('#search_field').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>"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function reloadTable() {
|
|
|
|
let pattern = $('#search_field').val();
|
|
|
|
$("#buttons_table").load(location.pathname + "?search=" + pattern.replace(" ", "%20") + " #buttons_table", refreshMatchedWords);
|
|
|
|
}
|
|
|
|
|
2020-07-30 13:49:59 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
let searchbar_obj = $("#search_field");
|
2020-08-15 17:47:29 +00:00
|
|
|
let timer_on = false;
|
|
|
|
let timer;
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
2021-10-07 20:54:01 +00:00
|
|
|
|
|
|
|
// on click of button "hide/show", call the API
|
|
|
|
function hideshow(id, displayed) {
|
|
|
|
$.ajax({
|
|
|
|
url: '/api/note/transaction/template/' + id + '/',
|
|
|
|
type: 'PATCH',
|
|
|
|
dataType: 'json',
|
|
|
|
headers: {
|
|
|
|
'X-CSRFTOKEN': CSRF_TOKEN
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
display: !displayed
|
|
|
|
},
|
|
|
|
success: function() {
|
|
|
|
if(displayed)
|
2021-10-07 21:06:40 +00:00
|
|
|
addMsg("{% trans "Button hidden"%}", 'success', 1000)
|
|
|
|
else addMsg("{% trans "Button displayed"%}", 'success', 1000)
|
2021-10-07 20:54:01 +00:00
|
|
|
reloadTable()
|
|
|
|
},
|
|
|
|
error: function (err) {
|
2021-10-07 21:06:40 +00:00
|
|
|
addMsg("{% trans "An error occured"%}", 'danger')
|
2021-10-07 20:54:01 +00:00
|
|
|
}})
|
|
|
|
}
|
2020-03-23 23:07:25 +00:00
|
|
|
</script>
|
|
|
|
{% endblock %}
|