this.operations = null;
this.packages = null;
this.scan_timestamp = 0;
+ this.numpad_buffer = [];
window.pickwidget = this;
start: function(){
var self = this;
instance.webclient.set_content_full_screen(true);
- this.connect_barcode_scanner();
+ this.connect_barcode_scanner_and_numpad();
this.$('.js_pick_quit').click(function(){ self.quit(); });
this.$('.js_pick_pack').click(function(){ self.pack(); });
return current_package;
},
- connect_barcode_scanner: function(){
+ set_operation_quantity: function(quantity){
+ if(quantity === '++'){
+ console.log('Increase quantity!');
+ }else if(quantity === '--'){
+ console.log('Decrease quantity :(');
+ }else if(typeof quantity === 'number'){
+ console.log('Set quantity: ',quantity);
+ }
+ },
+ connect_barcode_scanner_and_numpad: function(){
var self =this;
var numbers = [];
var timestamp = 0;
- var nocode_timeout_id = 0;
- var nocode_delay = 50;
- function nocode(){
- //console.log('NoCode:',numbers);
- numbers = [];
- }
+ var numpad = [];
+ var numpad_timestamp;
// it is important to catch the keypress event and not keyup/keydown as keypress normalizes the input codes :)
- $('body').delegate('','keypress',function(e){
- //console.log('Key:',e);
+ $('body').delegate('','keyup',function(e){
+ //console.log('Key:',e.keyCode);
if (e.keyCode >= 48 && e.keyCode < 58){
- clearTimeout(nocode_timeout_id);
- nocode_timeout_id = setTimeout(nocode,nocode_delay);
if(timestamp + 30 < new Date().getTime()){
- clearTimeout(nocode_timeout_id);
- nocode();
+ numbers = [];
}
numbers.push(e.keyCode - 48);
timestamp = new Date().getTime();
if(numbers.length === 13){
self.scan(numbers.join(''));
numbers = [];
- clearTimeout(nocode_timeout_id);
}
}else{
- nocode();
+ numbers = [];
+ if(numpad_timestamp + 1500 < new Date().getTime()){
+ numpad = [];
+ }
+ if(e.keyCode === 27 || e.keyCode === 8){ // ESC or BACKSPACE
+ numpad = [];
+ }else if(e.keyCode >= 96 && e.keyCode <= 105){ // NUMPAD NUMBERS
+ numpad.push(e.keyCode - 96);
+ }else if(e.keyCode === 13){ // ENTER
+ if(numpad.length > 0){
+ self.set_operation_quantity(parseInt(numpad.join('')));
+ }
+ numpad = [];
+ }else if(e.keyCode === 107){ // NUMPAD +
+ self.set_operation_quantity('++');
+ numpad = [];
+ }else if(e.keyCode === 109){ // NUMPAD -
+ self.set_operation_quantity('--');
+ numpad = [];
+ }else{
+ numpad = [];
+ }
+ numpad_timestamp = new Date().getTime();
}
});
},
- disconnect_barcode_scanner: function(){
+ disconnect_barcode_scanner_and_numpad: function(){
$('body').undelegate('', 'keyup')
},
quit: function(){
console.log('Quit');
- disconnect_barcode_scanner();
+ this.disconnect_barcode_scanner_and_numpad();
instance.webclient.set_content_full_screen(false);
window.location = '/'; // FIXME THIS IS SHIT NIV WILL KILL YOU (BY MULTIPLE FACE-STABBING) IF YOU MERGE THIS IN TRUNK
},