From 5b6ad90559499d722c6a1e78e4382189828f1aa9 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Tue, 6 Feb 2018 20:55:55 +0100 Subject: [PATCH] Auto set the focus to ICS id and serial number Allow to use a scanner configured as keyboard to register items via the web UI. 1. The attributes should be selected manually 2. Focus set manually on ICS id 3. Scan an ICS id -> prefix removed and focus set to serial number 4. Scan serial number 5. Click on submit 6. Focus set automatically on ICS id 7. Repeat from 3 --- app/static/js/create_item.js | 22 ++++++++++++++++++++++ app/static/js/items.js | 14 -------------- app/templates/inventory/create_item.html | 4 ++++ 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 app/static/js/create_item.js diff --git a/app/static/js/create_item.js b/app/static/js/create_item.js new file mode 100644 index 0000000..bd7f848 --- /dev/null +++ b/app/static/js/create_item.js @@ -0,0 +1,22 @@ +$(document).ready(function() { + + // 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(); + } + }); + + $("#clear").click(function() { + // clear all select fields + $("select").val(''); + }); + +}); diff --git a/app/static/js/items.js b/app/static/js/items.js index 017947a..0574112 100644 --- a/app/static/js/items.js +++ b/app/static/js/items.js @@ -32,20 +32,6 @@ $(document).ready(function() { $(this).html(converter.makeHtml(raw)); }); - // 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:', '')); - } - }); - - $("#clear").click(function() { - // clear all select fields - $("select").val(''); - }); - var items_table = $("#items_table").DataTable({ "ajax": { "url": $SCRIPT_ROOT + "/inventory/_retrieve_items" diff --git a/app/templates/inventory/create_item.html b/app/templates/inventory/create_item.html index 5cc2e4e..a42ae78 100644 --- a/app/templates/inventory/create_item.html +++ b/app/templates/inventory/create_item.html @@ -23,3 +23,7 @@ </div> </form> {%- endblock %} + +{% block csentry_scripts %} + <script src="{{ url_for('static', filename='js/create_item.js') }}"></script> +{% endblock %} -- GitLab