1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Filter buttons list with visible buttons only

This commit is contained in:
Yohann D'ANELLO 2020-04-27 03:56:22 +02:00
parent 2bc2048076
commit 5ea531fe68
6 changed files with 125 additions and 86 deletions

View File

@ -214,8 +214,7 @@ class RecurrentTransaction(Transaction):
template = models.ForeignKey( template = models.ForeignKey(
TransactionTemplate, TransactionTemplate,
null=True, on_delete=models.PROTECT,
on_delete=models.SET_NULL,
) )
category = models.ForeignKey( category = models.ForeignKey(
TemplateCategory, TemplateCategory,

View File

@ -129,13 +129,14 @@ class ButtonTable(tables.Table):
'table table-bordered condensed table-hover' 'table table-bordered condensed table-hover'
} }
row_attrs = { row_attrs = {
'class': lambda record: 'table-row ' + 'table-success' if record.display else 'table-danger', 'class': lambda record: 'table-row ' + ('table-success' if record.display else 'table-danger'),
'id': lambda record: "row-" + str(record.pk), 'id': lambda record: "row-" + str(record.pk),
'data-href': lambda record: record.pk 'data-href': lambda record: record.pk
} }
model = TransactionTemplate model = TransactionTemplate
exclude = ('id',) exclude = ('id',)
order_by = ('type', '-display', 'destination__name', 'name',)
edit = tables.LinkColumn('note:template_update', edit = tables.LinkColumn('note:template_update',
args=[A('pk')], args=[A('pk')],

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-27 03:19+0200\n" "POT-Creation-Date: 2020-04-27 03:55+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -46,7 +46,7 @@ msgstr ""
#: apps/activity/models.py:23 apps/activity/models.py:48 #: apps/activity/models.py:23 apps/activity/models.py:48
#: apps/member/models.py:99 apps/member/models.py:202 #: apps/member/models.py:99 apps/member/models.py:202
#: apps/note/models/notes.py:188 apps/note/models/transactions.py:24 #: apps/note/models/notes.py:188 apps/note/models/transactions.py:24
#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:237 #: apps/note/models/transactions.py:44 apps/note/models/transactions.py:236
#: templates/member/club_info.html:13 templates/member/profile_info.html:14 #: templates/member/club_info.html:13 templates/member/profile_info.html:14
#: templates/registration/future_profile_detail.html:16 #: templates/registration/future_profile_detail.html:16
msgid "name" msgid "name"
@ -238,12 +238,12 @@ msgstr ""
msgid "create" msgid "create"
msgstr "" msgstr ""
#: apps/logs/models.py:61 apps/note/tables.py:144 #: apps/logs/models.py:61 apps/note/tables.py:145
#: templates/activity/activity_detail.html:67 #: templates/activity/activity_detail.html:67
msgid "edit" msgid "edit"
msgstr "" msgstr ""
#: apps/logs/models.py:62 apps/note/tables.py:120 apps/note/tables.py:149 #: apps/logs/models.py:62 apps/note/tables.py:120 apps/note/tables.py:150
msgid "delete" msgid "delete"
msgstr "" msgstr ""
@ -672,33 +672,33 @@ msgstr ""
msgid "Transfer" msgid "Transfer"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:227 #: apps/note/models/transactions.py:226
msgid "Template" msgid "Template"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:242 #: apps/note/models/transactions.py:241
msgid "first_name" msgid "first_name"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:247 #: apps/note/models/transactions.py:246
msgid "bank" msgid "bank"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:253 #: apps/note/models/transactions.py:252
#: templates/activity/activity_entry.html:17 #: templates/activity/activity_entry.html:17
#: templates/note/transaction_form.html:24 #: templates/note/transaction_form.html:24
msgid "Credit" msgid "Credit"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:253 templates/note/transaction_form.html:28 #: apps/note/models/transactions.py:252 templates/note/transaction_form.html:28
msgid "Debit" msgid "Debit"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:269 apps/note/models/transactions.py:274 #: apps/note/models/transactions.py:268 apps/note/models/transactions.py:273
msgid "membership transaction" msgid "membership transaction"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:270 #: apps/note/models/transactions.py:269
msgid "membership transactions" msgid "membership transactions"
msgstr "" msgstr ""
@ -714,11 +714,11 @@ msgstr ""
msgid "No reason specified" msgid "No reason specified"
msgstr "" msgstr ""
#: apps/note/tables.py:122 apps/note/tables.py:151 #: apps/note/tables.py:122 apps/note/tables.py:152
msgid "Delete" msgid "Delete"
msgstr "" msgstr ""
#: apps/note/tables.py:146 templates/member/club_info.html:55 #: apps/note/tables.py:147 templates/member/club_info.html:55
#: templates/note/conso_form.html:128 #: templates/note/conso_form.html:128
msgid "Edit" msgid "Edit"
msgstr "" msgstr ""
@ -819,6 +819,7 @@ msgstr ""
#: templates/activity/activity_invite.html:8 #: templates/activity/activity_invite.html:8
#: templates/django_filters/rest_framework/form.html:5 #: templates/django_filters/rest_framework/form.html:5
#: templates/member/add_members.html:14 templates/member/club_form.html:9 #: templates/member/add_members.html:14 templates/member/club_form.html:9
#: templates/note/transactiontemplate_form.html:15
#: templates/treasury/invoice_form.html:46 #: templates/treasury/invoice_form.html:46
msgid "Submit" msgid "Submit"
msgstr "" msgstr ""
@ -1306,22 +1307,30 @@ msgid "Current price"
msgstr "" msgstr ""
#: templates/note/transactiontemplate_list.html:9 #: templates/note/transactiontemplate_list.html:9
msgid "search button" msgid "Search button"
msgstr "" msgstr ""
#: templates/note/transactiontemplate_list.html:13 #: templates/note/transactiontemplate_list.html:11
msgid "Name of the button..."
msgstr ""
#: templates/note/transactiontemplate_list.html:16
msgid "Display visible buttons only"
msgstr ""
#: templates/note/transactiontemplate_list.html:21
msgid "New button" msgid "New button"
msgstr "" msgstr ""
#: templates/note/transactiontemplate_list.html:20 #: templates/note/transactiontemplate_list.html:28
msgid "buttons listing " msgid "buttons listing "
msgstr "" msgstr ""
#: templates/note/transactiontemplate_list.html:70 #: templates/note/transactiontemplate_list.html:86
msgid "button successfully deleted " msgid "button successfully deleted "
msgstr "" msgstr ""
#: templates/note/transactiontemplate_list.html:74 #: templates/note/transactiontemplate_list.html:90
msgid "Unable to delete button " msgid "Unable to delete button "
msgstr "" msgstr ""

View File

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-27 03:19+0200\n" "POT-Creation-Date: 2020-04-27 03:55+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -42,7 +42,7 @@ msgstr "Vous ne pouvez pas inviter plus de 3 personnes à cette activité."
#: apps/activity/models.py:23 apps/activity/models.py:48 #: apps/activity/models.py:23 apps/activity/models.py:48
#: apps/member/models.py:99 apps/member/models.py:202 #: apps/member/models.py:99 apps/member/models.py:202
#: apps/note/models/notes.py:188 apps/note/models/transactions.py:24 #: apps/note/models/notes.py:188 apps/note/models/transactions.py:24
#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:237 #: apps/note/models/transactions.py:44 apps/note/models/transactions.py:236
#: templates/member/club_info.html:13 templates/member/profile_info.html:14 #: templates/member/club_info.html:13 templates/member/profile_info.html:14
#: templates/registration/future_profile_detail.html:16 #: templates/registration/future_profile_detail.html:16
msgid "name" msgid "name"
@ -234,12 +234,12 @@ msgstr "Nouvelles données"
msgid "create" msgid "create"
msgstr "Créer" msgstr "Créer"
#: apps/logs/models.py:61 apps/note/tables.py:144 #: apps/logs/models.py:61 apps/note/tables.py:145
#: templates/activity/activity_detail.html:67 #: templates/activity/activity_detail.html:67
msgid "edit" msgid "edit"
msgstr "Modifier" msgstr "Modifier"
#: apps/logs/models.py:62 apps/note/tables.py:120 apps/note/tables.py:149 #: apps/logs/models.py:62 apps/note/tables.py:120 apps/note/tables.py:150
msgid "delete" msgid "delete"
msgstr "Supprimer" msgstr "Supprimer"
@ -675,33 +675,33 @@ msgstr "transactions"
msgid "Transfer" msgid "Transfer"
msgstr "Virement" msgstr "Virement"
#: apps/note/models/transactions.py:227 #: apps/note/models/transactions.py:226
msgid "Template" msgid "Template"
msgstr "Bouton" msgstr "Bouton"
#: apps/note/models/transactions.py:242 #: apps/note/models/transactions.py:241
msgid "first_name" msgid "first_name"
msgstr "prénom" msgstr "prénom"
#: apps/note/models/transactions.py:247 #: apps/note/models/transactions.py:246
msgid "bank" msgid "bank"
msgstr "banque" msgstr "banque"
#: apps/note/models/transactions.py:253 #: apps/note/models/transactions.py:252
#: templates/activity/activity_entry.html:17 #: templates/activity/activity_entry.html:17
#: templates/note/transaction_form.html:24 #: templates/note/transaction_form.html:24
msgid "Credit" msgid "Credit"
msgstr "Crédit" msgstr "Crédit"
#: apps/note/models/transactions.py:253 templates/note/transaction_form.html:28 #: apps/note/models/transactions.py:252 templates/note/transaction_form.html:28
msgid "Debit" msgid "Debit"
msgstr "Débit" msgstr "Débit"
#: apps/note/models/transactions.py:269 apps/note/models/transactions.py:274 #: apps/note/models/transactions.py:268 apps/note/models/transactions.py:273
msgid "membership transaction" msgid "membership transaction"
msgstr "Transaction d'adhésion" msgstr "Transaction d'adhésion"
#: apps/note/models/transactions.py:270 #: apps/note/models/transactions.py:269
msgid "membership transactions" msgid "membership transactions"
msgstr "Transactions d'adhésion" msgstr "Transactions d'adhésion"
@ -717,11 +717,11 @@ msgstr "Cliquez pour valider"
msgid "No reason specified" msgid "No reason specified"
msgstr "Pas de motif spécifié" msgstr "Pas de motif spécifié"
#: apps/note/tables.py:122 apps/note/tables.py:151 #: apps/note/tables.py:122 apps/note/tables.py:152
msgid "Delete" msgid "Delete"
msgstr "Supprimer" msgstr "Supprimer"
#: apps/note/tables.py:146 templates/member/club_info.html:55 #: apps/note/tables.py:147 templates/member/club_info.html:55
#: templates/note/conso_form.html:128 #: templates/note/conso_form.html:128
msgid "Edit" msgid "Edit"
msgstr "Éditer" msgstr "Éditer"
@ -824,6 +824,7 @@ msgstr "Trésorerie"
#: templates/activity/activity_invite.html:8 #: templates/activity/activity_invite.html:8
#: templates/django_filters/rest_framework/form.html:5 #: templates/django_filters/rest_framework/form.html:5
#: templates/member/add_members.html:14 templates/member/club_form.html:9 #: templates/member/add_members.html:14 templates/member/club_form.html:9
#: templates/note/transactiontemplate_form.html:15
#: templates/treasury/invoice_form.html:46 #: templates/treasury/invoice_form.html:46
msgid "Submit" msgid "Submit"
msgstr "Envoyer" msgstr "Envoyer"
@ -1317,22 +1318,30 @@ msgid "Current price"
msgstr "Prix actuel" msgstr "Prix actuel"
#: templates/note/transactiontemplate_list.html:9 #: templates/note/transactiontemplate_list.html:9
msgid "search button" msgid "Search button"
msgstr "Chercher un bouton" msgstr "Chercher un bouton"
#: templates/note/transactiontemplate_list.html:13 #: templates/note/transactiontemplate_list.html:11
msgid "Name of the button..."
msgstr "Nom du bouton ..."
#: templates/note/transactiontemplate_list.html:16
msgid "Display visible buttons only"
msgstr "N'afficher que les boutons visibles uniquement"
#: templates/note/transactiontemplate_list.html:21
msgid "New button" msgid "New button"
msgstr "Nouveau bouton" msgstr "Nouveau bouton"
#: templates/note/transactiontemplate_list.html:20 #: templates/note/transactiontemplate_list.html:28
msgid "buttons listing " msgid "buttons listing "
msgstr "Liste des boutons" msgstr "Liste des boutons"
#: templates/note/transactiontemplate_list.html:70 #: templates/note/transactiontemplate_list.html:86
msgid "button successfully deleted " msgid "button successfully deleted "
msgstr "Le bouton a bien été supprimé" msgstr "Le bouton a bien été supprimé"
#: templates/note/transactiontemplate_list.html:74 #: templates/note/transactiontemplate_list.html:90
msgid "Unable to delete button " msgid "Unable to delete button "
msgstr "Impossible de supprimer le bouton " msgstr "Impossible de supprimer le bouton "

View File

@ -12,10 +12,10 @@
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{form|crispy}} {{form|crispy}}
<button class="btn btn-primary" type="submit">Submit</button> <button class="btn btn-primary" type="submit">{% trans "Submit" %}</button>
</form> </form>
{% if price_history %} {% if price_history and price_history.1 %}
<hr> <hr>
<h4>{% trans "Price history" %}</h4> <h4>{% trans "Price history" %}</h4>

View File

@ -6,9 +6,17 @@
<div class="row justify-content-center mb-4"> <div class="row justify-content-center mb-4">
<div class="col-md-10 text-center"> <div class="col-md-10 text-center">
<h4> <h4>
{% trans "search button" %} {% trans "Search button" %}
</h4> </h4>
<input class="form-control mx-auto w-25" type="text" onkeyup="search_field_moved();return(false);" id="search_field"/> <input class="form-control mx-auto w-25" type="text" id="search_field" placeholder="{% trans "Name of the button..." %}">
<div class="form-group">
<div id="div_active_only" class="form-check">
<label for="active_only" class="form-check-label">
<input type="checkbox" name="active_only" class="checkboxinput form-check-input" id="active_only">
{% trans "Display visible buttons only" %}
</label>
</div>
</div>
<hr> <hr>
<a class="btn btn-primary text-center my-1" href="{% url 'note:template_create' %}">{% trans "New button" %}</a> <a class="btn btn-primary text-center my-1" href="{% url 'note:template_create' %}">{% trans "New button" %}</a>
</div> </div>
@ -29,38 +37,46 @@
{% block extrajavascript %} {% block extrajavascript %}
<script> <script>
/* fonction appelée à la fin du timer */ /* fonction appelée à la fin du timer */
function getInfo() { function getInfo() {
var asked = $("#search_field").val(); var asked = $("#search_field").val();
/* on ne fait la requête que si on a au moins un caractère pour chercher */ /* 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) { if (asked.length >= 1) {
$.getJSON("/api/note/transaction/template/?format=json&search="+asked, function(buttons){ $.getJSON("/api/note/transaction/template/?format=json&search=" + asked + ($("#active_only").is(":checked") ? "&display=true" : ""), function(buttons) {
let selected_id = buttons.results.map((a => "#row-"+a.id)); console.log(buttons);
$(".table-row,"+selected_id.join()).show(); let selected_id = buttons.results.map((a => "#row-" + a.id));
$(".table-row").not(selected_id.join()).hide(); console.log(".table-row " + selected_id.join());
$(".table-row " + selected_id.join()).removeClass('d-none');
$(".table-row").not(selected_id.join()).addClass('d-none');
}); });
}else{
// show everything
$('table tr').show();
} }
} else {
var timer; if ($("#active_only").is(":checked")) {
var timer_on; $('.table-success').removeClass('d-none');
/* Fontion appelée quand le texte change (délenche le timer) */ $('.table-danger').addClass('d-none');
function search_field_moved(secondfield) { }
else {
// show everything
$('table tr').removeClass('d-none');
}
}
}
var timer;
var timer_on;
/* Fontion appelée quand le texte change (délenche le timer) */
function search_field_moved() {
if (timer_on) { // Si le timer a déjà été lancé, on réinitialise le compteur. if (timer_on) { // Si le timer a déjà été lancé, on réinitialise le compteur.
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout("getInfo(" + secondfield + ")", 300); timer = setTimeout(getInfo, 300);
} }
else { // Sinon, on le lance et on enregistre le fait qu'il tourne. else { // Sinon, on le lance et on enregistre le fait qu'il tourne.
timer = setTimeout("getInfo(" + secondfield + ")", 300); timer = setTimeout(getInfo, 300);
timer_on = true; timer_on = true;
} }
} }
// on click of button "delete" , call the API // on click of button "delete" , call the API
function delete_button(button_id){ function delete_button(button_id) {
$.ajax({ $.ajax({
url:"/api/note/transaction/template/"+button_id+"/", url:"/api/note/transaction/template/"+button_id+"/",
method:"DELETE", method:"DELETE",
@ -74,5 +90,10 @@ function search_field_moved(secondfield) {
addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' ) addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' )
}); });
} }
$(document).ready(function() {
$("#search_field").keyup(search_field_moved);
$("#active_only").change(search_field_moved);
});
</script> </script>
{% endblock %} {% endblock %}