Permalink
Browse files

[FIX] hr_attendance : fix kiosk mode - js review

The main goal here is to avoid using a global variable.
The greeting message _onBarcodeScanned bus can be stoped right after
the barcode_scanned as every time a barcode is scanned, it creates
a new instance of the greeting message.

Some other JS guidelines are also applied here.

Special thanks to Martin Geubelle (@mge-odoo) for helping me on this.

Task ID 1878251
Closes PR #
  • Loading branch information...
dbeguin committed Sep 20, 2018
1 parent b1251b4 commit 86ca3d91f68541f1c30fe8791e19263f3d37dfe6
@@ -5,7 +5,6 @@ var AbstractAction = require('web.AbstractAction');
var core = require('web.core');
var _t = core._t;
var previously_barcode_scanned;
var GreetingMessage = AbstractAction.extend({
@@ -55,17 +54,19 @@ var GreetingMessage = AbstractAction.extend({
},
willStart: function() {
if (this.attendance != undefined){
this._rpc({
var self = this;
var def;
if (this.attendance && this.attendance.employee_id) {
def = this._rpc({
model: 'hr.employee',
method: 'read',
args: [this.attendance.employee_id[0], ['barcode']],
})
.then(function (employee) {
previously_barcode_scanned = employee[0].barcode;
self.AttendanceBarcode = employee[0].barcode;
});
}
return this._super.apply(this, arguments);
return $.when(this._super.apply(this, arguments), def);
},
start: function() {
@@ -154,8 +155,8 @@ var GreetingMessage = AbstractAction.extend({
if (this.return_to_main_menu) { // in case of multiple scans in the greeting message view, delete the timer, a new one will be created.
clearTimeout(this.return_to_main_menu);
}
if (previously_barcode_scanned != barcode){
previously_barcode_scanned = barcode;
if (this.AttendanceBarcode !== barcode){
core.bus.off('barcode_scanned', this, this._onBarcodeScanned);
this._rpc({
model: 'hr.employee',
method: 'attendance_scan',
@@ -58,6 +58,7 @@ var KioskMode = AbstractAction.extend({
},
destroy: function () {
core.bus.off('barcode_scanned', this, this._onBarcodeScanned);
clearInterval(this.clock_start);
clearInterval(this._interval);
this._super.apply(this, arguments);

0 comments on commit 86ca3d9

Please sign in to comment.