From 7c1ebfb5b081273354e8d6aa45e7a3a4a2b1e770 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Tue, 20 Feb 2018 13:37:51 +0100 Subject: [PATCH] Add Submit action QRCode to create an item The QRCode content doesn't matter. It's only there to trigger a CR to submit the form. Scanning a serial number will focus on the submit button so that scanning the QRCode doesn't enter text in any form input field. --- app/static/img/actions/submit.png | Bin 0 -> 338 bytes app/static/js/create_item.js | 34 +++++++++--------- app/templates/_helpers.html | 7 ++++ app/templates/inventory/create_item.html | 43 +++++++++++++---------- 4 files changed, 50 insertions(+), 34 deletions(-) create mode 100644 app/static/img/actions/submit.png diff --git a/app/static/img/actions/submit.png b/app/static/img/actions/submit.png new file mode 100644 index 0000000000000000000000000000000000000000..408ac099dd508f202436c1ba4e1332e3a6655ed3 GIT binary patch literal 338 zcmV-Y0j>UtP)<h;3K|Lk000e1NJLTq005By005Bz00000>!W9m0003QNkl<Zc%1E) zF>1p=5Jmr&1gmZxa)8xE68TyI3)!H1MM};QSas>5?PRd{DV!=+sR=1O&B80@4Li$c zDg3Tec7uRB`!kkEX6S%{WNGAWr5=Z|q@*qSt+9nAQd0qmm6Zbkd=WP7x61Np>c}+% zOEtqQS~*VSK3!0Xq=lmZya1#Qg0`7?g(X(x?tpWKrLu59nt-{U0M~m(Nk<Du9yRC^ zX6hI$92wx7`rPcgv3#PUMV1sm(t!7`#~Ad`R2$5ETe{YiN7ti`&gQPJxeJ{4Sn3V> zt+H0?0l3~5qm^S}3B1(vGY-MRQT&|V4R}lLBN#f;1?04=KWD?-?Sgv^N0WVAvjm*l k=z1?%yj|Y^aQ}*Z1I2!PJAb0P7ytkO07*qoM6N<$f_&APJOBUy literal 0 HcmV?d00001 diff --git a/app/static/js/create_item.js b/app/static/js/create_item.js index 64f2bad..76e3ded 100644 --- a/app/static/js/create_item.js +++ b/app/static/js/create_item.js @@ -1,27 +1,29 @@ $(document).ready(function() { - // Prevent enter key to submit the form - // When scanning a code bar, the scanner usually - // send a CR as last character. We don't want that - // to submit the form. - $(window).keydown(function(event) { + // Focus to ICS id when loading the page + $("#ics_id").focus(); + + // Prevent enter key to submit the form when scanning a label + // and remove the ICS:ics_id: prefix + $("#ics_id").keydown(function(event) { if(event.keyCode == 13) { event.preventDefault(); + var value = $(this).val(); + $(this).val(value.replace('CSE:ics_id:', '')); + $("#serial_number").focus(); return false; } }); - // Focus to ICS id when loading the page - $("#ics_id").focus(); - - // remove 'CSE:ics_id:' prefix from ICS id - // allow to scan a label - $("#ics_id").keyup(function(event) { - var value = $(this).val(); - if( value.length == 17 ) { - $(this).val(value.replace('CSE:ics_id:', '')); - // Change the focus to the serial number - $("#serial_number").focus(); + // Prevent enter key to submit the form when scanning serial number + // Focus on the submit button so that scanning the Submit action + // will submit the form (due to the CR sent by the scanner) + $("#serial_number").keydown(function(event) { + console.log(event.keyCode); + if(event.keyCode == 13) { + event.preventDefault(); + $("#submit").focus(); + return false; } }); diff --git a/app/templates/_helpers.html b/app/templates/_helpers.html index 7ad28ca..7e78556 100644 --- a/app/templates/_helpers.html +++ b/app/templates/_helpers.html @@ -79,3 +79,10 @@ </div> </div> {%- endmacro %} + +{% macro figure(filename, description) -%} + <figure class="figure"> + <img src="{{ url_for('static', filename='img/' + filename) }}" class="img-fluid mx-auto d-block" alt="{{ description }}"> + <figcaption class="figure-caption text-center">{{ description }}</figcaption> + </figure> +{%- endmacro %} diff --git a/app/templates/inventory/create_item.html b/app/templates/inventory/create_item.html index a42ae78..19e3f94 100644 --- a/app/templates/inventory/create_item.html +++ b/app/templates/inventory/create_item.html @@ -1,27 +1,34 @@ {% extends "inventory/items.html" %} -{% from "_helpers.html" import render_field %} +{% from "_helpers.html" import render_field, figure %} {% block title %}Register Item - CSEntry{% endblock %} {% block items_main %} - <form id="itemForm" method="POST"> - {{ form.hidden_tag() }} - {{ render_field(form.ics_id) }} - {{ render_field(form.serial_number) }} - {{ render_field(form.quantity) }} - {{ render_field(form.manufacturer_id) }} - {{ render_field(form.model_id) }} - {{ render_field(form.location_id) }} - {{ render_field(form.status_id) }} - {{ render_field(form.parent_id) }} - {{ render_field(form.mac_addresses) }} - <div class="form-group row"> - <div class="col-sm-10"> - <button type="submit" class="btn btn-primary">Submit</button> - <button type="button" class="btn btn-primary" id="clear">Clear</button> - </div> + <div class="row"> + <div class="col-sm-11"> + <form id="itemForm" method="POST"> + {{ form.hidden_tag() }} + {{ render_field(form.ics_id) }} + {{ render_field(form.serial_number) }} + {{ render_field(form.quantity) }} + {{ render_field(form.manufacturer_id) }} + {{ render_field(form.model_id) }} + {{ render_field(form.location_id) }} + {{ render_field(form.status_id) }} + {{ render_field(form.parent_id) }} + {{ render_field(form.mac_addresses) }} + <div class="form-group row"> + <div class="col-sm-10"> + <button type="submit" class="btn btn-primary" id="submit">Submit</button> + <button type="button" class="btn btn-primary" id="clear">Clear</button> + </div> + </div> + </form> </div> - </form> + <div class="col-sm-1"> + {{ figure("actions/submit.png", "Submit") }} + </div> + </div> {%- endblock %} {% block csentry_scripts %} -- GitLab