diff options
Diffstat (limited to 'addons/timer/static/src')
| -rw-r--r-- | addons/timer/static/src/js/timer.js | 63 | ||||
| -rw-r--r-- | addons/timer/static/src/js/timer_mixin.js | 119 | ||||
| -rw-r--r-- | addons/timer/static/src/js/timer_toggle_button.js | 3 | ||||
| -rw-r--r-- | addons/timer/static/src/scss/timer_button.scss | 26 |
4 files changed, 1 insertions, 210 deletions
diff --git a/addons/timer/static/src/js/timer.js b/addons/timer/static/src/js/timer.js deleted file mode 100644 index 0042ebfaead..00000000000 --- a/addons/timer/static/src/js/timer.js +++ /dev/null @@ -1,63 +0,0 @@ -odoo.define('timer.timer', function (require) { -"use strict"; - -var fieldRegistry = require('web.field_registry'); -var AbstractField = require('web.AbstractField'); -var Timer = require('timer.Timer'); - -var TimerFieldWidget = AbstractField.extend({ - - /** - * @override - * @private - */ - isSet: function () { - return true; - }, - /** - * @override - * @private - */ - _render: function () { - this._super.apply(this, arguments); - this._startTimeCounter(); - }, - /** - * @override - */ - destroy: function () { - this._super.apply(this, arguments); - clearInterval(this.timer); - }, - /** - * @private - */ - _startTimeCounter: async function () { - if (this.record.data.timer_start) { - const serverTime = this.record.data.timer_pause || await this._getServerTime(); - this.time = Timer.createTimer(0, this.record.data.timer_start, serverTime); - this.$el.text(this.time.toString()); - this.timer = setInterval(() => { - if (this.record.data.timer_pause) { - clearInterval(this.timer); - } else { - this.time.addSecond(); - this.$el.text(this.time.toString()); - } - }, 1000); - } else if (!this.record.data.timer_pause){ - clearInterval(this.timer); - } - }, - _getServerTime: function () { - return this._rpc({ - model: 'timer.timer', - method: 'get_server_time', - args: [] - }); - } -}); - -fieldRegistry.add('timer_timer', TimerFieldWidget); - -}); diff --git a/addons/timer/static/src/js/timer_mixin.js b/addons/timer/static/src/js/timer_mixin.js deleted file mode 100644 index 7a70e81341e..00000000000 --- a/addons/timer/static/src/js/timer_mixin.js +++ /dev/null @@ -1,119 +0,0 @@ -odoo.define('timer.Timer', function (require) { -"use strict"; - - /** - * This class improves the timer display using the - * unit_amount field on account.analytic.line. - */ - class Timer { - constructor(hours, minutes, seconds) { - this.hours = hours; - this.minutes = minutes; - this.seconds = seconds; - } - - /** - * Convert float to time - * @param {number} float - */ - static convertFloatToTime(float) { - if (float === 0) { - return new Timer(0, 0, 0); - } - - let minutes = float % 1; - const hours = float - minutes; - minutes *= 60; - - return new Timer(hours, Math.round(minutes), 0); - } - - /** - * Create timer - * @param {number} unit_amount - * @param {String} timer_start - * @param {String} serverTime - */ - static createTimer(unit_amount, timer_start, serverTime) { - const timer = this.convertFloatToTime(unit_amount); - - timer.addTime( - moment.utc( - Math.abs(moment.utc(serverTime) - .diff(moment.utc(timer_start)) - )).format("HH:mm:ss") - ); - - return timer; - } - - addHours(hours) { - this.hours += hours; - } - - addMinutes(minutes) { - minutes += this.minutes; - - this.minutes = minutes % 60; - this.addHours(Math.floor(minutes / 60)); - } - - addSeconds(seconds) { - seconds += this.seconds; - this.seconds = seconds % 60; - this.addMinutes(Math.floor(seconds / 60)); - } - - display2digits(number) { - return number > 9 ? "" + number : "0" + number; - } - - addSecond() { - this.seconds += 1; - if (this.seconds === 60) { - this.minutes += 1; - this.seconds = 0; - - if (this.minutes === 60) { - this.hours += 1; - this.minutes = 0; - } - } - } - - addTime(time) { - if (typeof time == 'string' && time.indexOf(':') !== -1) { - let [hour, minute, second] = time.split(':'); - - hour = parseInt(hour); - minute = parseInt(minute); - second = (second === undefined) ? 0 : parseInt(second); - - this.addSeconds(second); - this.addMinutes(minute); - this.addHours(hour); - } - } - - convertToFloat() { - return (this.hours * 60 + this.minutes) * 60 / 3600; - } - - convertToSeconds() { - return (this.hours * 60 + this.minutes) * 60 + this.seconds; - } - - toString() { - const time = { - hours: this.display2digits(this.hours), - minutes: this.display2digits(this.minutes), - seconds: this.display2digits(this.seconds) - }; - - return `${time.hours}:${time.minutes}:${time.seconds}`; - } - } - - return Timer; - -}); diff --git a/addons/timer/static/src/js/timer_toggle_button.js b/addons/timer/static/src/js/timer_toggle_button.js index 78274e05e0c..d189d996502 100644 --- a/addons/timer/static/src/js/timer_toggle_button.js +++ b/addons/timer/static/src/js/timer_toggle_button.js @@ -52,12 +52,11 @@ const TimerToggleButton = FieldToggleBoolean.extend({ */ _onToggleButton: async function (event) { const context = this.record.getContext(); - const prevent_deletion = this.attrs.options && this.attrs.options.prevent_deletion || false; event.stopPropagation(); const result = await this._rpc({ model: this.model, method: this._getActionButton(), - context: $.extend({}, context, {prevent_deletion: prevent_deletion}), + context: context, args: [this.res_id] }); diff --git a/addons/timer/static/src/scss/timer_button.scss b/addons/timer/static/src/scss/timer_button.scss deleted file mode 100644 index 8b269fa8b20..00000000000 --- a/addons/timer/static/src/scss/timer_button.scss +++ /dev/null @@ -1,26 +0,0 @@ -.o-timer-button { - &:focus { - border: none !important; - outline: 0 !important; - } - - & > i { - transition: 0.3s; - - &.o-timer-play-button { - color: $link-color !important; - } - - &.o-timer-stop-button { - color: $red !important; - } - } - - &:hover > i.o-timer-play-button { - color: $link-hover-color !important; - } - - &:hover > i.o-timer-stop-button { - color: darken($red, 15%) !important; - } -} |
