Browse Source

[fix] scanner bug

pull/155/head
ufaks 9 years ago
committed by Vincent Van Rossem
parent
commit
b550159b3d
  1. 1
      pos_keyboard/__openerp__.py
  2. 39
      pos_keyboard/static/src/js/pos.js

1
pos_keyboard/__openerp__.py

@ -4,6 +4,7 @@
'author': "IT-Projects LLC, Ivan Yelizariev", 'author': "IT-Projects LLC, Ivan Yelizariev",
'license': 'LGPL-3', 'license': 'LGPL-3',
"website" : "https://yelizariev.github.io", "website" : "https://yelizariev.github.io",
'images': ['images/main.png'],
'category' : 'Point Of Sale', 'category' : 'Point Of Sale',
'version': '1.0.0', 'version': '1.0.0',
'depends': ['point_of_sale'], 'depends': ['point_of_sale'],

39
pos_keyboard/static/src/js/pos.js

@ -7,8 +7,8 @@ function pos_keyboard_widgets(instance, module){
res = resSuper.done(function(e){ res = resSuper.done(function(e){
self.pos.keypad.connect(); self.pos.keypad.connect();
self.pos.keypad.set_action_callback(function(data){ self.pos.keypad.set_action_callback(function(data){
self.keypad_action(data, self.pos.keypad.type);
});
self.keypad_action(data, self.pos.keypad.type);
});
}); });
return res; return res;
}, },
@ -117,7 +117,7 @@ function pos_keyboard_widgets(instance, module){
//cancel return to the previous page when press backspace //cancel return to the previous page when press backspace
var rx = /INPUT|SELECT|TEXTAREA/i; var rx = /INPUT|SELECT|TEXTAREA/i;
$(document).bind("keydown keypress", function(e){
$(document).on("keydown keypress", function(e){
if( e.which == 8 ){ // 8 == backspace if( e.which == 8 ){ // 8 == backspace
if(!rx.test(e.target.tagName) || e.target.disabled || e.target.readOnly ){ if(!rx.test(e.target.tagName) || e.target.disabled || e.target.readOnly ){
e.preventDefault(); e.preventDefault();
@ -126,18 +126,21 @@ function pos_keyboard_widgets(instance, module){
}); });
//usb keyboard keyup event //usb keyboard keyup event
$('body').delegate('','keyup', function (e){
var ok = false;
var timeStamp = 0;
$('body').on('keyup', '', function (e){
var statusHandler = !rx.test(e.target.tagName) || var statusHandler = !rx.test(e.target.tagName) ||
e.target.disabled || e.target.readOnly; e.target.disabled || e.target.readOnly;
if (statusHandler){ if (statusHandler){
var ok =false;
var is_number = false;
var type = self.type; var type = self.type;
var buttonMode = self.pos.pos_widget.numpad.modeButton
token = e.keyCode;
var buttonMode = self.pos.pos_widget.numpad.modeButton;
var token = e.keyCode;
if ((token >= 96 && token <= 105 || token == 110) || if ((token >= 96 && token <= 105 || token == 110) ||
(token >= 48 && token <= 57 || token == 190)) { (token >= 48 && token <= 57 || token == 190)) {
self.data.type = type.numchar; self.data.type = type.numchar;
self.data.val = kc_lookup[token]; self.data.val = kc_lookup[token];
is_number = true;
ok = true; ok = true;
} }
else if (token == KC_PLU || token == KC_PLU_1) { else if (token == KC_PLU || token == KC_PLU_1) {
@ -146,7 +149,7 @@ function pos_keyboard_widgets(instance, module){
} }
else if (token == KC_QTY || token == KC_QTY_1) { else if (token == KC_QTY || token == KC_QTY_1) {
self.data.type = type.bmode; self.data.type = type.bmode;
self.data.val = buttonMode.qty
self.data.val = buttonMode.qty;
ok = true; ok = true;
} }
else if (token == KC_AMT || token == KC_AMT_1) { else if (token == KC_AMT || token == KC_AMT_1) {
@ -161,18 +164,28 @@ function pos_keyboard_widgets(instance, module){
} }
else if (token == KC_BACKSPACE) { else if (token == KC_BACKSPACE) {
self.data.type = type.backspace; self.data.type = type.backspace;
self.action_callback(self.data);
ok = true; ok = true;
} }
if (ok) {self.action_callback(self.data);}
if (is_number) {
if (timeStamp + 50 > new Date().getTime()) {
ok = false;
}
}
timeStamp = new Date().getTime();
setTimeout(function(){
if (ok) {self.action_callback(self.data);}
}, 50);
} }
}); });
}, },
// stops catching keyboard events // stops catching keyboard events
disconnect: function(){ disconnect: function(){
$('body').undelegate('', 'keyup')
},
$('body').off('keyup', '')
}
}); });
} }
@ -183,4 +196,4 @@ function pos_keyboard_widgets(instance, module){
var module = instance.point_of_sale; var module = instance.point_of_sale;
pos_keyboard_widgets(instance, module); pos_keyboard_widgets(instance, module);
} }
})()
})();
Loading…
Cancel
Save