2015-07-18 23:00:54 +00:00
|
|
|
var barcodeBuf = ""
|
|
|
|
var barcodeShown = false
|
|
|
|
|
|
|
|
function showBarcode(text) {
|
|
|
|
if (!barcodeShown) {
|
|
|
|
document.getElementById('barcode').classList.add('shown')
|
2015-07-21 17:18:00 +00:00
|
|
|
barcodeShown = true
|
2015-07-18 23:00:54 +00:00
|
|
|
}
|
|
|
|
document.getElementById('barcodeContent').textContent = text
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:14:47 +00:00
|
|
|
function hideBarcode() {
|
|
|
|
if (barcodeShown) {
|
|
|
|
document.getElementById('barcode').classList.remove('shown')
|
2015-07-21 17:18:00 +00:00
|
|
|
barcodeShown = false
|
2015-07-21 12:14:47 +00:00
|
|
|
}
|
2015-07-21 17:18:00 +00:00
|
|
|
return ""
|
2015-07-21 12:14:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 22:57:50 +00:00
|
|
|
function barcodeKeyPress( event ) { // takes input from either keyboard or barcode scanner
|
|
|
|
var key = String.fromCharCode( event.charCode )
|
|
|
|
var input = document.getElementById( 'crement' )
|
|
|
|
var inputcount = document.querySelectorAll( '[type="text"]' ).length + document.querySelectorAll( '[type="number"]' ).length
|
|
|
|
if ( input && inputcount == 1 ) { // focus in 'crement' when no other input fields only
|
2015-07-21 12:33:37 +00:00
|
|
|
input.focus()
|
|
|
|
}
|
2015-07-21 07:14:38 +00:00
|
|
|
var focused = document.activeElement
|
2015-07-21 19:22:06 +00:00
|
|
|
if ( !focused || focused == document.body ) {
|
2015-07-21 07:14:38 +00:00
|
|
|
focused = null
|
2015-07-21 19:22:06 +00:00
|
|
|
} else if ( document.querySelector ) {
|
2015-07-21 22:57:50 +00:00
|
|
|
focused = document.querySelector( ":focus" )
|
2015-07-21 07:14:38 +00:00
|
|
|
}
|
2015-07-21 22:57:50 +00:00
|
|
|
if (
|
|
|
|
!event.ctrlKey && !event.altKey // no hotkeys used
|
|
|
|
&& ( focused == null || focused.tagName != "INPUT" ) // focus not in input fielf for manual input
|
|
|
|
) {
|
|
|
|
if ( event.keyCode === 13 ) { // carriage return
|
|
|
|
var input = document.getElementById( 'barcodeInput' )
|
|
|
|
if ( input && barcodeBuf.length > 0 ) {
|
|
|
|
input.setAttribute( 'value', barcodeBuf )
|
2015-07-21 07:14:38 +00:00
|
|
|
input.parentNode.submit()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
barcodeBuf = ""
|
|
|
|
event.preventDefault()
|
2015-07-21 22:57:50 +00:00
|
|
|
} else if ( event.keyCode === 27 ) { // escape
|
|
|
|
console.log( "escape" )
|
2015-07-21 12:14:47 +00:00
|
|
|
barcodeBuf=hideBarcode()
|
|
|
|
event.preventDefault()
|
2015-07-21 22:57:50 +00:00
|
|
|
} else if ( event.keyCode === 8 ) { // backspace
|
|
|
|
console.log( "backspace" )
|
2015-07-21 12:14:47 +00:00
|
|
|
barcodeBuf = barcodeBuf.substring( 0, barcodeBuf.length - 1 )
|
2015-07-21 22:57:50 +00:00
|
|
|
showBarcode( barcodeBuf )
|
2015-07-21 12:14:47 +00:00
|
|
|
if ( barcodeBuf.length <= 0 ) {
|
2015-07-21 22:57:50 +00:00
|
|
|
barcodeBuf = hideBarcode()
|
2015-07-21 12:14:47 +00:00
|
|
|
}
|
|
|
|
event.preventDefault()
|
2017-11-07 19:53:10 +00:00
|
|
|
} else if ( key && key != " " ) {
|
2015-07-21 22:57:50 +00:00
|
|
|
console.log( "some input: " + barcodeBuf + "[" + key + "] <= {" + event.keyCode + "}" )
|
2015-07-21 07:14:38 +00:00
|
|
|
barcodeBuf += key
|
2015-07-21 22:57:50 +00:00
|
|
|
showBarcode( barcodeBuf )
|
2015-07-21 07:14:38 +00:00
|
|
|
event.preventDefault()
|
2015-07-20 23:14:21 +00:00
|
|
|
}
|
2015-07-18 23:00:54 +00:00
|
|
|
}
|
|
|
|
}
|