From 48f5da4511a7f96408806664dafc7ceb0c1bd3d4 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 11 Jul 2017 13:05:35 -0500 Subject: [PATCH] Add global key handler for mobile receiving, for scanner wedge input this way we don't have to focus the UPC search box, since that seems to always popup the device keyboard. --- tailbone/static/js/tailbone.mobile.js | 30 ++++++++++++++++++++++----- tailbone/templates/mobile/base.mako | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tailbone/static/js/tailbone.mobile.js b/tailbone/static/js/tailbone.mobile.js index d603643f..4bcb54db 100644 --- a/tailbone/static/js/tailbone.mobile.js +++ b/tailbone/static/js/tailbone.mobile.js @@ -102,11 +102,31 @@ $(document).on('click', '#datasync-restart', function() { }); - -// handle Enter press for receiving UPC lookup -$(document).on('keydown', '.receiving-upc-search', function(event) { - if (event.which == 13) { - $.mobile.navigate($(this).data('url') + '?upc=' + $(this).val()); +// handle global keypress on receiving "row" page, for sake of scanner wedge +$(document).on('keypress', function(event) { + if ($('.ui-page-active [role="main"]').data('route') == 'mobile.receiving.view') { + var upc = $('#upc-search'); + if (upc.length) { + if (upc.is(':focus')) { + if (event.which == 13) { + if (upc.val()) { + $.mobile.navigate(upc.data('url') + '?upc=' + upc.val()); + } + } + } else { + if (event.which >= 48 && event.which <= 57) { // numeric (qwerty) + upc.val(upc.val() + event.key); + // TODO: these codes are correct for 'keydown' but apparently not 'keypress' ? + // } else if (event.which >= 96 && event.which <= 105) { // numeric (10-key) + // upc.val(upc.val() + event.key); + } else if (event.which == 13) { + if (upc.val()) { + $.mobile.navigate(upc.data('url') + '?upc=' + upc.val()); + } + } + return false; + } + } } }); diff --git a/tailbone/templates/mobile/base.mako b/tailbone/templates/mobile/base.mako index 9fb83942..dd5cfa11 100644 --- a/tailbone/templates/mobile/base.mako +++ b/tailbone/templates/mobile/base.mako @@ -94,7 +94,7 @@ <%def name="mobile_page_body()"> -
+
% if request.session.peek_flash('error'): % for error in request.session.pop_flash('error'):