1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-27 18:02:23 +00:00

Consumptions with item selected before

This commit is contained in:
Yohann D'ANELLO 2020-03-13 01:34:20 +01:00
parent e81450e092
commit bb0fc8c2cc
3 changed files with 39 additions and 6 deletions

View File

@ -134,9 +134,12 @@ function removeNote(d, note_prefix="note", notes_display, note_list_id, user_not
* consumptions, put null if not used)
* @param profile_pic_field The identifier of the field that display the profile picture of the hovered note
* (useful in consumptions, put null if not used)
* @param alias_click Function that is called when an alias is clicked. If this method exists and doesn't return true,
* the associated note is not displayed.
* Useful for a consumption if the item is selected before.
*/
function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes_display, alias_prefix="alias",
note_prefix="note", user_note_field=null, profile_pic_field=null) {
note_prefix="note", user_note_field=null, profile_pic_field=null, alias_click=null) {
let field = $("#" + field_id);
// When the user clicks on the search field, it is immediately cleared
field.click(function() {
@ -192,6 +195,12 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
// In the other case, we add a new emitter
if (disp == null)
notes_display.push([alias.name, note.id, note, 1]);
// If the function alias_click exists, it is called. If it doesn't return true, then the notes are
// note displayed. Useful for a consumption when a button is already clicked
if (alias_click && !alias_click())
return;
let note_list = $("#" + note_list_id);
let html = "";
notes_display.forEach(function(disp) {

View File

@ -29,7 +29,13 @@ let buttons = [];
// When the user searches an alias, we update the auto-completion
autoCompleteNote("note", "alias_matched", "note_list", notes, notes_display,
"alias", "note", "user_note", "profile_pic");
"alias", "note", "user_note", "profile_pic", function() {
if (buttons.length > 0) {
consumeAll();
return false;
}
return true;
});
/**
* Add a transaction from a button.
@ -44,7 +50,7 @@ autoCompleteNote("note", "alias_matched", "note_list", notes, notes_display,
function addConso(dest, amount, type, category_id, category_name, template_id, template_name) {
var button = null;
buttons.forEach(function(b) {
if (b[5] === template_id) {
if (b[6] === template_id) {
b[1] += 1;
button = b;
}
@ -52,9 +58,24 @@ function addConso(dest, amount, type, category_id, category_name, template_id, t
if (button == null)
buttons.push([dest, 1, amount, type, category_id, category_name, template_id, template_name]);
// TODO Only in simple consumption mode
if (notes.length > 0)
if ($("#double_conso:checked").length > 0) {
let html = "";
buttons.forEach(function(button) {
html += li("conso_button_" + button[6], button[7]
+ "<span class=\"badge badge-dark badge-pill\">" + button[1] + "</span>");
});
$("#consos_list").html(html);
}
else if (notes_display.length > 0)
consumeAll();
else {
let html = "";
buttons.forEach(function(button) {
html += li("conso_button_" + button[6], button[7]
+ "<span class=\"badge badge-dark badge-pill\">" + button[1] + "</span>");
});
$("#note_list").html(html);
}
}
/**
@ -100,6 +121,7 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
buttons.length = 0;
$("#note_list").html("");
$("#alias_matched").html("");
$("#consos_list").html("");
displayNote(null, "");
refreshHistory();
refreshBalance();

View File

@ -47,7 +47,7 @@
</div>
<ul class="list-group list-group-flush" id="consos_list">
</ul>
<button id="consume" class="form-control btn btn-primary">Consommer !</button>
<button id="consume_all" class="form-control btn btn-primary">Consommer !</button>
</div>
</div>
</div>
@ -163,6 +163,8 @@
$("#consos_list_div").hide();
$("#consume_all").click(consumeAll);
{% for button in transaction_templates %}
{% if button.display %}
$("#button{{ button.id }}").click(function() {