diff --git a/static/js/base.js b/static/js/base.js index f485635bb5393ca5919c9f6abdda94906f12a9a7..cf67759b0132184d5fd849265f8b5dac8b973555 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -217,6 +217,7 @@ function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_pr // Clear search on click field.click(function () { field.tooltip('hide'); + field.removeClass('is-invalid'); field.val(""); }); @@ -233,6 +234,8 @@ function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_pr // When the user type something, the matched aliases are refreshed field.keyup(function (e) { + field.removeClass('is-invalid'); + if (e.originalEvent.charCode === 13) return; diff --git a/static/js/consos.js b/static/js/consos.js index 7a295b789666072a9e57bf69da6087418ba41403..3b6b5bc5b129f6ca3273688480ba602c1ab862ca 100644 --- a/static/js/consos.js +++ b/static/js/consos.js @@ -154,6 +154,22 @@ function reset() { * Apply all transactions: all notes in `notes` buy each item in `buttons` */ function consumeAll() { + let error = false; + + if (notes_display.length === 0) { + $("#note").addClass('is-invalid'); + $("#note_list").html(li("", "<strong>Ajoutez des émetteurs.</strong>", "text-danger")); + error = true; + } + + if (buttons.length === 0) { + $("#consos_list").html(li("", "<strong>Ajoutez des consommations.</strong>", "text-danger")); + error = true; + } + + if (error) + return; + notes_display.forEach(function(note_display) { buttons.forEach(function(button) { consume(note_display.note, note_display.name, button.dest, button.quantity * note_display.quantity, button.amount, diff --git a/static/js/transfer.js b/static/js/transfer.js index 45d5508a5c6beccab97914645dd3f1ab23945ebc..70cf10dc94f3c6456687038273f2e60019fe6bfb 100644 --- a/static/js/transfer.js +++ b/static/js/transfer.js @@ -219,6 +219,16 @@ $("#btn_transfer").click(function() { error = true; } + if (!sources_notes_display.length && !$("#type_credit").is(':checked')) { + $("#source_note").addClass('is-invalid'); + error = true; + } + + if (!dests_notes_display.length && !$("#type_debit").is(':checked')) { + $("#dest_note").addClass('is-invalid'); + error = true; + } + if (error) return; @@ -300,11 +310,6 @@ $("#btn_transfer").click(function() { let given_reason = reason; let source_id, dest_id; if ($("#type_credit").is(':checked')) { - if (!dests_notes_display.length) { - $("#dest_note").addClass('is-invalid'); - return; - } - user_note = dests_notes_display[0].note.id; source_id = special_note; dest_id = user_note; @@ -313,11 +318,6 @@ $("#btn_transfer").click(function() { reason += " (" + given_reason + ")"; } else { - if (!sources_notes_display.length) { - $("#source_note").addClass('is-invalid'); - return; - } - user_note = sources_notes_display[0].note.id; source_id = user_note; dest_id = special_note; diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html index e6335c6e57341f8a854e160f2988a2a1e83e123e..a63f7ffe95293476a660283f8bd5a0e8acf1433a 100644 --- a/templates/note/conso_form.html +++ b/templates/note/conso_form.html @@ -53,9 +53,9 @@ </ul> </div> <div class="card-footer text-center"> - <a id="consume_all" href="#" class="btn btn-primary"> + <span id="consume_all" class="btn btn-primary"> {% trans "Consume!" %} - </a> + </span> </div> </div> </div>