Browse Source

💚 pre-commit: auto cleanups

pull/155/head
Ivan Yelizariev 5 years ago
committed by Vincent Van Rossem
parent
commit
f2e287fc0e
  1. 147
      pos_keyboard/static/src/js/pos.js

147
pos_keyboard/static/src/js/pos.js

@ -6,21 +6,23 @@
Copyright 2019 raulovallet <https://github.com/raulovallet> Copyright 2019 raulovallet <https://github.com/raulovallet>
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). */ License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). */
/* eslint-disable complexity */ /* eslint-disable complexity */
odoo.define('pos_keyboard.pos', function (require) {
odoo.define("pos_keyboard.pos", function(require) {
"use strict"; "use strict";
var core = require('web.core');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens');
var PopupWidget = require('point_of_sale.popups');
var core = require("web.core");
var gui = require("point_of_sale.gui");
var models = require("point_of_sale.models");
var screens = require("point_of_sale.screens");
var PopupWidget = require("point_of_sale.popups");
gui.Gui.prototype.popup_classes.filter(function(c){
return c.name === 'password';
})[0].widget.include({
gui.Gui.prototype.popup_classes
.filter(function(c) {
return c.name === "password";
})[0]
.widget.include({
init: function(parent, args) { init: function(parent, args) {
this._super(parent, args); this._super(parent, args);
this.popup_type = 'password';
this.popup_type = "password";
}, },
}); });
@ -30,9 +32,9 @@ odoo.define('pos_keyboard.pos', function (require) {
if (data.type === type.numchar) { if (data.type === type.numchar) {
this.click_keyboard(data.val); this.click_keyboard(data.val);
} else if (data.type === type.backspace) { } else if (data.type === type.backspace) {
this.click_keyboard('BACKSPACE');
this.click_keyboard("BACKSPACE");
} else if (data.type === type.enter) { } else if (data.type === type.enter) {
// some pop-ups might throw an error due to lack of some income data
// Some pop-ups might throw an error due to lack of some income data
try { try {
return this.click_confirm(); return this.click_confirm();
} catch (error) { } catch (error) {
@ -43,28 +45,27 @@ odoo.define('pos_keyboard.pos', function (require) {
} }
}, },
click_keyboard: function(value) { click_keyboard: function(value) {
if (typeof this.inputbuffer === 'undefined') {
if (typeof this.inputbuffer === "undefined") {
return; return;
} }
var newbuf = this.gui.numpad_input(
this.inputbuffer,
value,
{'firstinput': this.firstinput});
var newbuf = this.gui.numpad_input(this.inputbuffer, value, {
firstinput: this.firstinput,
});
this.firstinput = (newbuf.length === 0);
this.firstinput = newbuf.length === 0;
var $value = this.$('.value');
var $value = this.$(".value");
if (newbuf !== this.inputbuffer) { if (newbuf !== this.inputbuffer) {
this.inputbuffer = newbuf; this.inputbuffer = newbuf;
$value.text(this.inputbuffer); $value.text(this.inputbuffer);
} }
if (this.popup_type === 'password' && newbuf) {
$value.text($value.text().replace(/./g, '•'));
if (this.popup_type === "password" && newbuf) {
$value.text($value.text().replace(/./g, "•"));
} }
}, },
show: function(options) { show: function(options) {
this._super(options); this._super(options);
this.$('input,textarea').focus();
this.$("input,textarea").focus();
}, },
}); });
@ -80,7 +81,7 @@ odoo.define('pos_keyboard.pos', function (require) {
} else if (data.type === type.backspace) { } else if (data.type === type.backspace) {
this.clickDeleteLastChar(); this.clickDeleteLastChar();
} }
}
},
}); });
screens.PaymentScreenWidget.include({ screens.PaymentScreenWidget.include({
@ -91,25 +92,25 @@ odoo.define('pos_keyboard.pos', function (require) {
hide: function() { hide: function() {
this._super(); this._super();
this.pos.keypad.connect(); 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.
var Keypad = core.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',
bmode: 'quantity, discount, price',
sign: '+, -',
backspace: 'backspace',
enter: 'enter',
escape: 'escape',
numchar: "number, dot",
bmode: "quantity, discount, price",
sign: "+, -",
backspace: "backspace",
enter: "enter",
escape: "escape",
}; };
this.data = { this.data = {
// type: undefined,
// Type: undefined,
// val: undefined // val: undefined
}; };
delete this.action_callback; delete this.action_callback;
@ -130,12 +131,12 @@ odoo.define('pos_keyboard.pos', function (require) {
this.action_callback = callback; this.action_callback = callback;
}, },
//remove action callback
// Remove action callback
reset_action_callback: function() { reset_action_callback: function() {
delete this.action_callback; delete this.action_callback;
}, },
// starts catching keyboard events and tries to interpret keystrokes,
// Starts catching keyboard events and tries to interpret keystrokes,
// calling the callback when needed. // calling the callback when needed.
connect: function() { connect: function() {
var self = this; var self = this;
@ -168,32 +169,61 @@ odoo.define('pos_keyboard.pos', function (require) {
// KeyCode: Escape (Keypad 'esc') // KeyCode: Escape (Keypad 'esc')
var KC_ESCAPE = 27; var KC_ESCAPE = 27;
var kc_lookup = { 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: '/'
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: "/",
}; };
//usb keyboard keyup event
// Usb keyboard keyup event
var rx = /INPUT|SELECT|TEXTAREA/i; var rx = /INPUT|SELECT|TEXTAREA/i;
var ok = false; var ok = false;
var timeStamp = 0; var timeStamp = 0;
$('body').on('keyup', '', function (e){
var statusHandler = !rx.test(e.target.tagName) ||
e.target.disabled || e.target.readOnly;
$("body").on("keyup", "", function(e) {
var statusHandler =
!rx.test(e.target.tagName) ||
e.target.disabled ||
e.target.readOnly;
if (statusHandler) { if (statusHandler) {
var is_number = false; var is_number = false;
var type = self.type; var type = self.type;
var buttonMode = { var buttonMode = {
qty: 'quantity',
disc: 'discount',
price: 'price'
qty: "quantity",
disc: "discount",
price: "price",
}; };
var token = e.keyCode; var token = e.keyCode;
if (((token >= 96 && token <= 105) || token === 110) ||
((token >= 48 && token <= 57) || token === 190)) {
if (
(token >= 96 && token <= 105) ||
token === 110 ||
(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; is_number = true;
@ -246,18 +276,18 @@ self.action_callback(self.data);
self.active = true; self.active = true;
}, },
// stops catching keyboard events
// Stops catching keyboard events
disconnect: function() { disconnect: function() {
$('body').off('keyup', '');
$("body").off("keyup", "");
this.active = false; this.active = false;
}
},
}); });
var _super_posmodel = models.PosModel.prototype; var _super_posmodel = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({ models.PosModel = models.PosModel.extend({
initialize: function(session, attributes) { initialize: function(session, attributes) {
var self = this; var self = this;
this.keypad = new Keypad({'pos': this});
this.keypad = new Keypad({pos: this});
_super_posmodel.initialize.call(this, session, attributes); _super_posmodel.initialize.call(this, session, attributes);
this.ready.then(function() { this.ready.then(function() {
self.keypad.set_action_callback(function(data) { self.keypad.set_action_callback(function(data) {
@ -266,15 +296,18 @@ self.action_callback(self.data);
if (current_popup) { if (current_popup) {
current_popup.keypad_action(data); current_popup.keypad_action(data);
} else if (current_screen.numpad && current_screen.numpad.keypad_action) {
} else if (
current_screen.numpad &&
current_screen.numpad.keypad_action
) {
current_screen.numpad.keypad_action(data); current_screen.numpad.keypad_action(data);
} }
}); });
}); });
}
},
}); });
return { return {
Keypad: Keypad
Keypad: Keypad,
}; };
}); });
Loading…
Cancel
Save