[IMP] point_of_sale : add keyboard events on pos product selection interface

Keyboard Shortcuts: Numbers on the keypads (0 to 9), Backspace and Delete

related to task: #33518

closes odoo/odoo#17162
This commit is contained in:
Deep Patel
2019-01-11 08:54:26 +00:00
parent a00e6f3dd1
commit 4704128dc4
2 changed files with 53 additions and 1 deletions
+23 -1
View File
@@ -2717,6 +2717,22 @@ exports.NumpadState = Backbone.Model.extend({
});
this.trigger('set_value',this.get('buffer'));
},
positiveSign: function() {
var oldBuffer;
oldBuffer = this.get('buffer');
if (oldBuffer[0] === '-'){
this.set({buffer: oldBuffer.substr(1)});
this.trigger('set_value',this.get('buffer'));
}
},
negativeSign: function() {
var oldBuffer;
oldBuffer = this.get('buffer');
if (oldBuffer[0] !== '-'){
this.set({buffer: "-" + oldBuffer});
this.trigger('set_value',this.get('buffer'));
}
},
changeMode: function(newMode) {
this.set({
buffer: "0",
@@ -2730,7 +2746,13 @@ exports.NumpadState = Backbone.Model.extend({
});
},
resetValue: function(){
this.set({buffer:'0'});
if(this.get('buffer') === "") {
this.trigger('set_value','remove');
}
else {
this.set({ buffer: "" });
this.trigger('set_value',this.get('buffer'));
}
},
});
@@ -1016,6 +1016,7 @@ var ProductScreenWidget = ScreenWidget.extend({
if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) {
this.chrome.widget.keyboard.connect($(this.el.querySelector('.searchbox input')));
}
$(document).on('keydown.productscreen',this._onKeypadKeyDown.bind(this));
},
close: function(){
@@ -1023,6 +1024,35 @@ var ProductScreenWidget = ScreenWidget.extend({
if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){
this.chrome.widget.keyboard.hide();
}
$(document).off('keydown.productscreen',this._onKeypadKeyDown.bind(this));
},
_onKeypadKeyDown: function (ev) {
//prevent input and textarea keydown event
if(!_.contains(["INPUT", "TEXTAREA"], $(ev.target).prop('tagName'))) {
if ((ev.key >= "0" && ev.key <= "9") || ev.key === "."){
this.numpad.state.appendNewChar(ev.key)
}
else {
switch (ev.key){
case "Backspace":
this.numpad.state.deleteLastChar();
break;
case "Delete":
this.numpad.state.resetValue();
break;
case ",":
this.numpad.state.appendNewChar(".");
break;
case "+":
this.numpad.state.positiveSign();
break;
case "-":
this.numpad.state.negativeSign();
break;
}
}
}
},
});
gui.define_screen({name:'products', widget: ProductScreenWidget});