[MOV] im_livechat: move Timer outside of public_livechat.js
Task-2212347 Part-of: odoo/odoo#87597
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
odoo.define('im_livechat.legacy.mail.model.Timer', function (require) {
|
||||
"use strict";
|
||||
|
||||
var Class = require('web.Class');
|
||||
|
||||
/**
|
||||
* This class creates a timer which, when times out, calls a function.
|
||||
*/
|
||||
var Timer = Class.extend({
|
||||
|
||||
/**
|
||||
* Instantiate a new timer. Note that the timer is not started on
|
||||
* initialization (@see start method).
|
||||
*
|
||||
* @param {Object} params
|
||||
* @param {number} params.duration duration of timer before timeout in
|
||||
* milli-seconds.
|
||||
* @param {function} params.onTimeout function that is called when the
|
||||
* timer times out.
|
||||
*/
|
||||
init: function (params) {
|
||||
this._duration = params.duration;
|
||||
this._timeout = undefined;
|
||||
this._timeoutCallback = params.onTimeout;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clears the countdown of the timer.
|
||||
*/
|
||||
clear: function () {
|
||||
clearTimeout(this._timeout);
|
||||
},
|
||||
/**
|
||||
* Resets the timer, i.e. resets its duration.
|
||||
*/
|
||||
reset: function () {
|
||||
this.clear();
|
||||
this.start();
|
||||
},
|
||||
/**
|
||||
* Starts the timer, i.e. after a certain duration, it times out and calls
|
||||
* a function back.
|
||||
*/
|
||||
start: function () {
|
||||
this._timeout = setTimeout(this._onTimeout.bind(this), this._duration);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handler
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Called when the timer times out, calls back a function on timeout.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_onTimeout: function () {
|
||||
this._timeoutCallback();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
return Timer;
|
||||
|
||||
});
|
||||
@@ -634,76 +634,6 @@ return {
|
||||
|
||||
});
|
||||
|
||||
odoo.define('im_livechat.legacy.mail.model.Timer', function (require) {
|
||||
"use strict";
|
||||
|
||||
var Class = require('web.Class');
|
||||
|
||||
/**
|
||||
* This class creates a timer which, when times out, calls a function.
|
||||
*/
|
||||
var Timer = Class.extend({
|
||||
|
||||
/**
|
||||
* Instantiate a new timer. Note that the timer is not started on
|
||||
* initialization (@see start method).
|
||||
*
|
||||
* @param {Object} params
|
||||
* @param {number} params.duration duration of timer before timeout in
|
||||
* milli-seconds.
|
||||
* @param {function} params.onTimeout function that is called when the
|
||||
* timer times out.
|
||||
*/
|
||||
init: function (params) {
|
||||
this._duration = params.duration;
|
||||
this._timeout = undefined;
|
||||
this._timeoutCallback = params.onTimeout;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clears the countdown of the timer.
|
||||
*/
|
||||
clear: function () {
|
||||
clearTimeout(this._timeout);
|
||||
},
|
||||
/**
|
||||
* Resets the timer, i.e. resets its duration.
|
||||
*/
|
||||
reset: function () {
|
||||
this.clear();
|
||||
this.start();
|
||||
},
|
||||
/**
|
||||
* Starts the timer, i.e. after a certain duration, it times out and calls
|
||||
* a function back.
|
||||
*/
|
||||
start: function () {
|
||||
this._timeout = setTimeout(this._onTimeout.bind(this), this._duration);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handler
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Called when the timer times out, calls back a function on timeout.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_onTimeout: function () {
|
||||
this._timeoutCallback();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
return Timer;
|
||||
|
||||
});
|
||||
|
||||
odoo.define('im_livechat.legacy.mail.model.Timers', function (require) {
|
||||
"use strict";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user