From cf67e17e85dc565429df3151d7b5dbc1b7125315 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 10 Apr 2020 19:50:42 +0200 Subject: [PATCH 01/19] Do not use JavaScript to hide double conso after loading --- static/js/consos.js | 6 ++---- templates/note/conso_form.html | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/static/js/consos.js b/static/js/consos.js index 9450febc..943dbca3 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -26,7 +26,7 @@ $(document).ready(function() { // Switching in double consumptions mode should update the layout let double_conso_obj = $("#double_conso"); double_conso_obj.click(function() { - $("#consos_list_div").show(); + $("#consos_list_div").attr('class', 'col-xl-5'); $("#infos_div").attr('class', 'col-sm-5 col-xl-6'); $("#note_infos_div").attr('class', 'col-xl-3'); $("#user_select_div").attr('class', 'col-xl-4'); @@ -46,7 +46,7 @@ $(document).ready(function() { let single_conso_obj = $("#single_conso"); single_conso_obj.click(function() { - $("#consos_list_div").hide(); + $("#consos_list_div").attr('class', 'col-xl-5 d-none'); $("#infos_div").attr('class', 'col-sm-5 col-md-4'); $("#note_infos_div").attr('class', 'col-xl-5'); $("#user_select_div").attr('class', 'col-xl-7'); @@ -74,8 +74,6 @@ $(document).ready(function() { double_conso_obj.removeAttr('checked'); $("label[for='double_conso']").attr('class', 'btn btn-sm btn-outline-primary'); - $("#consos_list_div").hide(); - $("#consume_all").click(consumeAll); }); diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 36659849..fd0923f2 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -42,7 +42,7 @@ -
+

@@ -150,7 +150,7 @@ {% endblock %} {% block extrajavascript %} - + From b90ff59d989f360e47924d5af9a79d27b84bda1f Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 10 Apr 2020 22:46:57 +0200 Subject: [PATCH 12/19] Update tooltip position after new emitter --- static/js/base.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/static/js/base.js b/static/js/base.js index 02746302..af8eb8bf 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -317,6 +317,9 @@ function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_pr // Emitters are displayed note_list.html(html); + // Update tooltip position + field.tooltip('update'); + notes_display.forEach(function (disp) { let line_obj = $("#" + note_prefix + "_" + disp.id); // Hover an emitter display also the profile picture From 45c8fdf1c14a0b6a7e00644503d2851aed361914 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 10 Apr 2020 22:47:59 +0200 Subject: [PATCH 13/19] Revert margin for search field --- templates/note/conso_form.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 35eff32c..d55da8b7 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -34,7 +34,7 @@

{# User search with autocompletion #} -
+ From 5c1e3dd0ca58742c549f38008f70d326253d5eb4 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 10 Apr 2020 22:51:26 +0200 Subject: [PATCH 14/19] Make tooltips opaque again --- templates/base.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/base.html b/templates/base.html index 44bc8c82..7cfc474b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -59,6 +59,9 @@ SPDX-License-Identifier: GPL-3.0-or-later cursor: pointer; text-decoration: underline; } + .tooltip.show { + opacity: 1; /* opaque tooltip */ + } .tooltip-inner { background-color: #fff; box-shadow: 0 .5rem 1rem rgba(0,0,0,.15); From 46b5f537bc7504cc2f2e42163a3df64da2a730a2 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 10 Apr 2020 23:04:25 +0200 Subject: [PATCH 15/19] Fix tooltip inner selecter --- static/js/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/base.js b/static/js/base.js index af8eb8bf..bad8ad97 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -223,7 +223,7 @@ function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_pr // When the user type "Enter", the first alias is clicked field.keypress(function (event) { if (event.originalEvent.charCode === 13 && notes.length > 0) { - let li_obj = $(".tooltip-inner ul li").first(); + let li_obj = field.parent().find("ul li").first(); displayNote(notes[0], li_obj.text(), user_note_field, profile_pic_field); li_obj.trigger("click"); } From 700ad7c9f706e00b49e034788b993157808e808c Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 10 Apr 2020 23:15:25 +0200 Subject: [PATCH 16/19] Make consume section more bootstrap --- templates/note/conso_form.html | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index d55da8b7..89a92790 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -28,7 +28,7 @@ {% trans "Consum" %}

-
+
@@ -48,11 +48,15 @@ {% trans "Select consumptions" %}

-
    -
- +
+
    +
+
+
From 7af76899e3591c03ccbf6fc4c33153f2ac5b1647 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 10 Apr 2020 23:40:19 +0200 Subject: [PATCH 17/19] Simplify grids --- static/js/consos.js | 8 ++------ templates/note/conso_form.html | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/static/js/consos.js b/static/js/consos.js index 11ad7302..2fa77249 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -26,10 +26,8 @@ $(document).ready(function() { // Switching in double consumptions mode should update the layout $("#double_conso").click(function() { $("#consos_list_div").removeClass('d-none'); - $("#infos_div").attr('class', 'col-sm-5 col-xl-6'); - $("#note_infos_div").attr('class', 'col-xl-3'); $("#user_select_div").attr('class', 'col-xl-4'); - $("#buttons_div").attr('class', 'col-sm-7 col-xl-6'); + $("#infos_div").attr('class', 'col-sm-5 col-xl-6'); let note_list_obj = $("#note_list"); if (buttons.length > 0 && note_list_obj.text().length > 0) { @@ -45,10 +43,8 @@ $(document).ready(function() { $("#single_conso").click(function() { $("#consos_list_div").addClass('d-none'); - $("#infos_div").attr('class', 'col-sm-5 col-md-4'); - $("#note_infos_div").attr('class', 'col-xl-5'); $("#user_select_div").attr('class', 'col-xl-7'); - $("#buttons_div").attr('class', 'col-sm-7 col-md-8'); + $("#infos_div").attr('class', 'col-sm-5 col-md-4'); let consos_list_obj = $("#consos_list"); if (buttons.length > 0) { diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index 89a92790..451d8a27 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -10,7 +10,7 @@
{# User details column #} -
+
@@ -63,7 +63,7 @@
{# Buttons column #} -
+
{# Show last used buttons #}
From a609d7c9956790eda1e1d9b30ce096336c875950 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 10 Apr 2020 23:41:13 +0200 Subject: [PATCH 18/19] Fix credit/debit tabs --- apps/treasury/signals.py | 4 +- static/js/transfer.js | 65 ++++++++++++++++++++++++++++ templates/note/transaction_form.html | 52 +--------------------- 3 files changed, 69 insertions(+), 52 deletions(-) diff --git a/apps/treasury/signals.py b/apps/treasury/signals.py index 54c19c09..188be1a7 100644 --- a/apps/treasury/signals.py +++ b/apps/treasury/signals.py @@ -1,6 +1,7 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later +from note.models import NoteSpecial from treasury.models import SpecialTransactionProxy, RemittanceType @@ -8,5 +9,6 @@ def save_special_transaction(instance, created, **kwargs): """ When a special transaction is created, we create its linked proxy """ - if created and RemittanceType.objects.filter(note=instance.source).exists(): + if created and isinstance(instance.source, NoteSpecial) \ + and RemittanceType.objects.filter(note=instance.source).exists(): SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save() diff --git a/static/js/transfer.js b/static/js/transfer.js index 69fafac5..78a8ca08 100644 --- a/static/js/transfer.js +++ b/static/js/transfer.js @@ -34,6 +34,9 @@ $(document).ready(function() { if ($("#type_credit").is(":checked") || $("#type_debit").is(":checked")) { let arr = $("#type_credit").is(":checked") ? dests_notes_display : sources_notes_display; + if (arr.length === 0) + return; + let last = arr[arr.length - 1]; arr.length = 0; arr.push(last); @@ -65,6 +68,68 @@ $(document).ready(function() { autoCompleteNote("dest_note", "dest_note_list", dests, dests_notes_display, "dest_alias", "dest_note", "user_note", "profile_pic", checkUniqueNote); + let source = $("#source_note"); + let dest = $("#dest_note"); + + $("#type_gift").click(function() { + $("#special_transaction_div").addClass('d-none'); + source.attr('disabled', true); + source.val(username); + source.tooltip('hide'); + $("#source_note_list").addClass('d-none'); + dest.attr('disabled', false); + $("#dest_note_list").removeClass('d-none'); + }); + + $("#type_transfer").click(function() { + $("#special_transaction_div").addClass('d-none'); + source.attr('disabled', false); + $("#source_note_list").removeClass('d-none'); + dest.attr('disabled', false); + $("#dest_note_list").removeClass('d-none'); + }); + + $("#type_credit").click(function() { + $("#special_transaction_div").removeClass('d-none'); + $("#source_note_list").addClass('d-none'); + $("#dest_note_list").removeClass('d-none'); + source.attr('disabled', true); + source.val($("#credit_type option:selected").text()); + source.tooltip('hide'); + dest.attr('disabled', false); + dest.val(''); + dest.tooltip('hide'); + + if (dests_notes_display.length > 1) { + $("#dest_note_list").html(''); + dests_notes_display.length = 0; + } + }); + + $("#type_debit").click(function() { + $("#special_transaction_div").removeClass('d-none'); + $("#source_note_list").removeClass('d-none'); + $("#dest_note_list").addClass('d-none'); + source.attr('disabled', false); + source.val(''); + source.tooltip('hide'); + dest.attr('disabled', true); + dest.val($("#credit_type option:selected").text()); + dest.tooltip('hide'); + + if (sources_notes_display.length > 1) { + $("#source_note_list").html(''); + sources_notes_display.length = 0; + } + }); + + $("#credit_type").change(function() { + let type = $("#credit_type option:selected").text(); + if ($("#type_credit").is(":checked")) + source.val(type); + else + dest.val(type); + }); // Ensure we begin in gift mode. Removing these lines may cause problems when reloading. let type_gift = $("#type_gift"); // Default mode diff --git a/templates/note/transaction_form.html b/templates/note/transaction_form.html index d1cafa1f..c252f636 100644 --- a/templates/note/transaction_form.html +++ b/templates/note/transaction_form.html @@ -160,57 +160,7 @@ SPDX-License-Identifier: GPL-2.0-or-later TRANSFER_POLYMORPHIC_CTYPE = {{ polymorphic_ctype }}; SPECIAL_TRANSFER_POLYMORPHIC_CTYPE = {{ special_polymorphic_ctype }}; user_id = {{ user.note.pk }}; - - source = $("#source_note"); - dest = $("#dest_note"); - - $("#type_gift").click(function() { - $("#special_transaction_div").addClass('d-none'); - source.attr('disabled', true); - source.val("{{ user.username }}"); - source.tooltip('hide'); - $("#source_note_list").addClass('d-none'); - dest.attr('disabled', false); - $("#dest_note_list").removeClass('d-none'); - }); - - $("#type_transfer").click(function() { - $("#special_transaction_div").addClass('d-none'); - source.attr('disabled', false); - $("#source_note_list").removeClass('d-none'); - dest.attr('disabled', false); - $("#dest_note_list").removeClass('d-none'); - }); - - $("#type_credit").click(function() { - $("#special_transaction_div").removeClass('d-none'); - $("#source_note_list").addClass('d-none'); - $("#dest_note_list").removeClass('d-none'); - source.attr('disabled', true); - source.val($("#credit_type option:selected").text()); - source.tooltip('hide'); - dest.attr('disabled', false); - dest.val(''); - }); - - $("#type_debit").click(function() { - $("#special_transaction_div").removeClass('d-none'); - $("#source_note_list").removeClass('d-none'); - $("#dest_note_list").addClass('d-none'); - source.attr('disabled', false); - source.val(''); - dest.attr('disabled', true); - dest.val($("#credit_type option:selected").text()); - dest.tooltip('hide'); - }); - - $("#credit_type").change(function() { - let type = $("#credit_type option:selected").text(); - if ($("#type_credit").is(":checked")) - source.val(type); - else - dest.val(type); - }); + username = "{{ user.username }}"; {% endblock %} From d96c40a00f57823e310e2d1723cee794ce2e75aa Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 10 Apr 2020 23:46:16 +0200 Subject: [PATCH 19/19] Style was removed when a note was removed --- static/js/base.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static/js/base.js b/static/js/base.js index bad8ad97..db12dae9 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -162,7 +162,8 @@ function removeNote(d, note_prefix = "note", notes_display, note_list_id, user_n disp.quantity -= disp.id === d.id ? 1 : 0; new_notes_display.push(disp); html += li(note_prefix + "_" + disp.id, disp.name - + "" + disp.quantity + ""); + + "" + disp.quantity + "", + displayStyle(disp.note)); } });