Browse Source

1. added support for basic keyboard

2. handling has been omitted in input
pull/155/head
Ilnur Gallyamov 9 years ago
committed by Vincent Van Rossem
parent
commit
b18f45cd3e
  1. 74
      pos_keyboard/static/src/js/pos.js

74
pos_keyboard/static/src/js/pos.js

@ -3,8 +3,8 @@ function pos_keyboard_widgets(instance, module){
module.PosWidget.include({
start: function() {
self = this;
res = this._super();
res.done(function(e){
resSuper = this._super();
res = resSuper.done(function(e){
self.pos.keypad.connect();
self.pos.keypad.set_action_callback(function(data){
self.keypad_action(data, self.pos.keypad.type);
@ -18,15 +18,15 @@ function pos_keyboard_widgets(instance, module){
},
keypad_action: function(data, type){
var numpad = this.pos_widget.numpad;
if (data.type === type.bmode) {
if (data.type === type.numchar){
numpad.state.appendNewChar(data.val);
}
else if (data.type === type.bmode) {
numpad.state.changeMode(data.val);
}
else if (data.type === type.sign){
numpad.clickSwitchSign();
}
else if (data.type === type.numchar){
numpad.state.appendNewChar(data.val);
}
else if (data.type === type.backspace){
numpad.clickDeleteLastChar();
}
@ -94,12 +94,22 @@ function pos_keyboard_widgets(instance, module){
// calling the callback when needed.
connect: function(){
var self = this;
var KC_PLU = 107; // KeyCode: Product Code (Keypad '+')
// --- additional keyboard ---//
var KC_PLU = 107; // KeyCode: + or - (Keypad '+')
var KC_QTY = 111; // KeyCode: Quantity (Keypad '/')
var KC_AMT = 106; // KeyCode: Price (Keypad '*')
var KC_DISC = 109; // KeyCode: Discount Percentage [0..100] (Keypad '-')
// --- basic keyboard --- //
var KC_PLU_1 = 83; // KeyCode: sign + or - (Keypad 's')
var KC_QTY_1 = 81; // KeyCode: Quantity (Keypad 'q')
var KC_AMT_1 = 80; // KeyCode: Price (Keypad 'p')
var KC_DISC_1 = 68; // KeyCode: Discount Percentage [0..100] (Keypad 'd')
var KC_BACKSPACE = 8; // KeyCode: Backspace (Keypad 'backspace')
var kc_lookup = {
48: '0', 49: '1', 50: '2', 51: '3', 52: '4',
53: '5', 54: '6', 55: '7', 56: '8', 57: '9',
80: 'p', 83: 's', 68: 'd', 190: '.', 81: 'q',
96: '0', 97: '1', 98: '2', 99: '3', 100: '4',
101: '5', 102: '6', 103: '7', 104: '8', 105: '9',
106: '*', 107: '+', 109: '-', 110: '.', 111: '/',
@ -117,32 +127,44 @@ function pos_keyboard_widgets(instance, module){
//usb keyboard keyup event
$('body').delegate('','keyup', function (e){
var type = self.type;
var buttonMode = self.pos.pos_widget.numpad.modeButton
token = e.keyCode;
if ((token >= 96 && token <= 111) || token === KC_PLU || token === KC_QTY || token === KC_AMT) {
if (token === KC_PLU) {
var statusHandler = !rx.test(e.target.tagName) ||
e.target.disabled || e.target.readOnly;
if (statusHandler){
var ok =false;
var type = self.type;
var buttonMode = self.pos.pos_widget.numpad.modeButton
token = e.keyCode;
if ((token >= 96 && token <= 105 || token == 110) ||
(token >= 48 && token <= 57 || token == 190)) {
self.data.type = type.numchar;
self.data.val = kc_lookup[token];
ok = true;
}
else if (token == KC_PLU || token == KC_PLU_1) {
self.data.type = type.sign;
} else if (token === KC_QTY) {
ok = true;
}
else if (token == KC_QTY || token == KC_QTY_1) {
self.data.type = type.bmode;
self.data.val = buttonMode.qty
} else if (token === KC_AMT) {
ok = true;
}
else if (token == KC_AMT || token == KC_AMT_1) {
self.data.type = type.bmode;
self.data.val = buttonMode.price;
} else if (token === KC_DISC) {
ok = true;
}
else if (token == KC_DISC || token == KC_DISC_1) {
self.data.type = type.bmode;
self.data.val = buttonMode.disc;
} else {
self.data.type = type.numchar;
self.data.val = kc_lookup[token];
}
self.action_callback(self.data);
} else if (token === KC_BACKSPACE && !rx.test(e.target.tagName)) {
self.data.type = type.backspace;
self.action_callback(self.data);
ok = true;
}
else if (token == KC_BACKSPACE) {
self.data.type = type.backspace;
self.action_callback(self.data);
ok = true;
}
if (ok) {self.action_callback(self.data);}
}
});
},

Loading…
Cancel
Save