diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_attendance/static/src/js/kiosk_mode.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/hr_attendance/static/src/js/kiosk_mode.js')
| -rw-r--r-- | addons/hr_attendance/static/src/js/kiosk_mode.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/addons/hr_attendance/static/src/js/kiosk_mode.js b/addons/hr_attendance/static/src/js/kiosk_mode.js new file mode 100644 index 00000000..6ce0c026 --- /dev/null +++ b/addons/hr_attendance/static/src/js/kiosk_mode.js @@ -0,0 +1,85 @@ +odoo.define('hr_attendance.kiosk_mode', function (require) { +"use strict"; + +var AbstractAction = require('web.AbstractAction'); +var ajax = require('web.ajax'); +var core = require('web.core'); +var Session = require('web.session'); + +var QWeb = core.qweb; + + +var KioskMode = AbstractAction.extend({ + events: { + "click .o_hr_attendance_button_employees": function() { + this.do_action('hr_attendance.hr_employee_attendance_action_kanban', { + additional_context: {'no_group_by': true}, + }); + }, + }, + + start: function () { + var self = this; + core.bus.on('barcode_scanned', this, this._onBarcodeScanned); + self.session = Session; + var def = this._rpc({ + model: 'res.company', + method: 'search_read', + args: [[['id', '=', this.session.company_id]], ['name']], + }) + .then(function (companies){ + self.company_name = companies[0].name; + self.company_image_url = self.session.url('/web/image', {model: 'res.company', id: self.session.company_id, field: 'logo',}); + self.$el.html(QWeb.render("HrAttendanceKioskMode", {widget: self})); + self.start_clock(); + }); + // Make a RPC call every day to keep the session alive + self._interval = window.setInterval(this._callServer.bind(this), (60*60*1000*24)); + return Promise.all([def, this._super.apply(this, arguments)]); + }, + + _onBarcodeScanned: function(barcode) { + var self = this; + core.bus.off('barcode_scanned', this, this._onBarcodeScanned); + this._rpc({ + model: 'hr.employee', + method: 'attendance_scan', + args: [barcode, ], + }) + .then(function (result) { + if (result.action) { + self.do_action(result.action); + } else if (result.warning) { + self.do_warn(result.warning); + core.bus.on('barcode_scanned', self, self._onBarcodeScanned); + } + }, function () { + core.bus.on('barcode_scanned', self, self._onBarcodeScanned); + }); + }, + + start_clock: function() { + this.clock_start = setInterval(function() {this.$(".o_hr_attendance_clock").text(new Date().toLocaleTimeString(navigator.language, {hour: '2-digit', minute:'2-digit', second:'2-digit'}));}, 500); + // First clock refresh before interval to avoid delay + this.$(".o_hr_attendance_clock").show().text(new Date().toLocaleTimeString(navigator.language, {hour: '2-digit', minute:'2-digit', second:'2-digit'})); + }, + + destroy: function () { + core.bus.off('barcode_scanned', this, this._onBarcodeScanned); + clearInterval(this.clock_start); + clearInterval(this._interval); + this._super.apply(this, arguments); + }, + + _callServer: function () { + // Make a call to the database to avoid the auto close of the session + return ajax.rpc("/hr_attendance/kiosk_keepalive", {}); + }, + +}); + +core.action_registry.add('hr_attendance_kiosk_mode', KioskMode); + +return KioskMode; + +}); |
