Browse Source

ability to use keyboard for password popup close #411

pull/155/head
KolushovAlexandr 6 years ago
committed by Vincent Van Rossem
parent
commit
6a241b97a8
  1. 2
      pos_keyboard/__manifest__.py
  2. 5
      pos_keyboard/doc/changelog.rst
  3. 92
      pos_keyboard/static/src/js/pos.js

2
pos_keyboard/__manifest__.py

@ -8,7 +8,7 @@
'images': ['images/keyboard.png'], 'images': ['images/keyboard.png'],
'category': 'Point Of Sale', 'category': 'Point Of Sale',
'license': 'LGPL-3', 'license': 'LGPL-3',
'version': '1.0.2',
'version': '10.0.1.0.2',
'depends': ['point_of_sale'], 'depends': ['point_of_sale'],
"price": 15.00, "price": 15.00,
"currency": "EUR", "currency": "EUR",

5
pos_keyboard/doc/changelog.rst

@ -3,6 +3,11 @@
Updates Updates
======= =======
`1.1.0`
-------
**New:** Added popup handling
`1.0.2` `1.0.2`
------- -------

92
pos_keyboard/static/src/js/pos.js

@ -1,55 +1,62 @@
function pos_keyboard_widgets(instance, module){
odoo.define('pos_keyboard.pos', function (require) {
"use strict";
module.PosWidget.include({
var core = require('web.core');
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
var _super_posmodel = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
initialize: function (session, attributes) {
this.keypad = new Keypad({'pos': this});
return _super_posmodel.initialize.call(this, session, attributes);
}
});
screens.NumpadWidget.include({
start: function() { start: function() {
self = this;
resSuper = this._super();
res = resSuper.done(function(e){
self.pos.keypad.connect();
self.pos.keypad.set_action_callback(function(data){
this._super();
var self = this;
this.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;
},
close: function() {
this._super();
this.pos.keypad.disconnect();
}, },
keypad_action: function(data, type){ keypad_action: function(data, type){
var numpad = this.pos_widget.numpad;
if (data.type === type.numchar){ if (data.type === type.numchar){
numpad.state.appendNewChar(data.val);
this.state.appendNewChar(data.val);
} }
else if (data.type === type.bmode) { else if (data.type === type.bmode) {
numpad.state.changeMode(data.val);
this.state.changeMode(data.val);
} }
else if (data.type === type.sign){ else if (data.type === type.sign){
numpad.clickSwitchSign();
this.clickSwitchSign();
} }
else if (data.type === type.backspace){ else if (data.type === type.backspace){
numpad.clickDeleteLastChar();
this.clickDeleteLastChar();
}
} }
},
}); });
var PosModelSuper = module.PosModel;
module.PosModel = module.PosModel.extend({
initialize: function(session, attributes) {
this.keypad = new module.Keypad({'pos': this});
PosModelSuper.prototype.initialize.call(this, session, attributes);
screens.PaymentScreenWidget.include({
show: function(){
this._super();
this.pos.keypad.disconnect();
}, },
hide: function(){
this._super();
this.pos.keypad.connect();
}
}); });
// this module mimics a keypad-only cash register. Use connect() and // this module mimics a keypad-only cash register. Use connect() and
// disconnect() to activate and deactivate it. // disconnect() to activate and deactivate it.
module.Keypad = instance.web.Class.extend({
var Keypad = core.Class.extend({
init: function(attributes){ init: function(attributes){
this.pos = attributes.pos; this.pos = attributes.pos;
this.pos_widget = this.pos.pos_widget;
/*this.pos_widget = this.pos.pos_widget;*/
this.type = { this.type = {
numchar: 'number, dot', numchar: 'number, dot',
bmode: 'qty, disc, price',
bmode: 'quantity, discount, price',
sign: '+, -', sign: '+, -',
backspace: 'backspace' backspace: 'backspace'
}; };
@ -101,20 +108,11 @@ function pos_keyboard_widgets(instance, module){
80: 'p', 83: 's', 68: 'd', 190: '.', 81: 'q', 80: 'p', 83: 's', 68: 'd', 190: '.', 81: 'q',
96: '0', 97: '1', 98: '2', 99: '3', 100: '4', 96: '0', 97: '1', 98: '2', 99: '3', 100: '4',
101: '5', 102: '6', 103: '7', 104: '8', 105: '9', 101: '5', 102: '6', 103: '7', 104: '8', 105: '9',
106: '*', 107: '+', 109: '-', 110: '.', 111: '/',
106: '*', 107: '+', 109: '-', 110: '.', 111: '/'
}; };
//cancel return to the previous page when press backspace
var rx = /INPUT|SELECT|TEXTAREA/i;
$(document).on("keydown keypress", function(e){
if( e.which == 8 ){ // 8 == backspace
if(!rx.test(e.target.tagName) || e.target.disabled || e.target.readOnly ){
e.preventDefault();
}
}
});
//usb keyboard keyup event //usb keyboard keyup event
var rx = /INPUT|SELECT|TEXTAREA/i;
var ok = false; var ok = false;
var timeStamp = 0; var timeStamp = 0;
$('body').on('keyup', '', function (e){ $('body').on('keyup', '', function (e){
@ -159,6 +157,11 @@ function pos_keyboard_widgets(instance, module){
self.data.type = type.backspace; self.data.type = type.backspace;
ok = true; ok = true;
} }
else {
self.data.type = undefined;
self.data.val = undefined;
ok = false;
}
if (is_number) { if (is_number) {
if (timeStamp + 50 > new Date().getTime()) { if (timeStamp + 50 > new Date().getTime()) {
@ -180,13 +183,8 @@ function pos_keyboard_widgets(instance, module){
$('body').off('keyup', ''); $('body').off('keyup', '');
} }
}); });
}
(function(){
var _super = window.openerp.point_of_sale;
window.openerp.point_of_sale = function(instance){
_super(instance);
var module = instance.point_of_sale;
pos_keyboard_widgets(instance, module);
return {
Keypad: Keypad
}; };
})();
});
Loading…
Cancel
Save