summaryrefslogtreecommitdiff
path: root/addons/website_event/static/src/js/display_timer_widget.js
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-08-19 09:55:26 +0000
committerThibault Delavallée <tde@odoo.com>2020-08-21 17:30:13 +0000
commitb0845c0f2b48d6c7029a34ae50fc95876630e7ed (patch)
treecab4c50786ae087fdf6dec70b0c12ddc0c39c62d /addons/website_event/static/src/js/display_timer_widget.js
parentd697966585e9686f4bfce8049c1d0a21abe8a279 (diff)
[REM] website_event_online: merge into website_event
PURPOSE Clean organization and models linked to Event Online feature introduced in semi stable saas-13.3 at odoo/odoo@981f95bbf46658eda9f2d33751b9310cc67d86aa and odoo/enterprise@14722028ae0773c3710ea48ce48ff44703e83b5a Also clean website event menu not being available in website event but only in website event track, which implies some extra-code to manage it. In short: merge website_event_online in website_event, website_event_track _(online/session) in website_event_track. RATIONALE _online modules have been added to extend content of website_event and website_event_track without having any impact on those module. First step of cleaning is to move this content directly in base module. track_session module is mainly a rewrite of track module. Second step of cleaning is to move its content directly in website_event_track. SPECIFICATIONS Move remaining content of website event online to website event. Update dependencies accordingly. LINKS Task ID-2319779 COM odoo/odoo#56067 ENT odoo/enterprise#12520 UPG odoo/upgrade#1654
Diffstat (limited to 'addons/website_event/static/src/js/display_timer_widget.js')
-rw-r--r--addons/website_event/static/src/js/display_timer_widget.js111
1 files changed, 111 insertions, 0 deletions
diff --git a/addons/website_event/static/src/js/display_timer_widget.js b/addons/website_event/static/src/js/display_timer_widget.js
new file mode 100644
index 00000000000..5f61273661f
--- /dev/null
+++ b/addons/website_event/static/src/js/display_timer_widget.js
@@ -0,0 +1,111 @@
+odoo.define('website_event.display_timer_widget', function (require) {
+'use strict';
+
+var core = require('web.core');
+var _t = core._t;
+var publicWidget = require('web.public.widget');
+
+publicWidget.registry.displayTimerWidget = publicWidget.Widget.extend({
+ selector: '.o_display_timer',
+
+ /**
+ * This widget allows to display a dom element at the end of a certain time laps.
+ * There are 2 timers available:
+ * - The main-timer: display the DOM element (using the displayClass) at the end of this timer.
+ * - The pre-timer: additional timer to display the main-timer. This pre-timer can be invisible or visible,
+ * depending of the startCountdownDisplay option. Once the pre-timer is over,
+ the main-timer is displayed.
+ * @override
+ */
+ start: function () {
+ var self = this;
+ return this._super.apply(this, arguments).then(function () {
+ self.options = self.$target.data();
+ self.preCountdownDisplay = self.options["preCountdownDisplay"];
+ self.preCountdownTime = self.options["preCountdownTime"];
+ self.preCountdownText = self.options["preCountdownText"];
+
+ self.mainCountdownTime = self.options["mainCountdownTime"];
+ self.mainCountdownText = self.options["mainCountdownText"];
+ self.mainCountdownDisplay = self.options["mainCountdownDisplay"];
+
+ self.displayClass = self.options["displayClass"];
+
+ if (self.preCountdownDisplay) {
+ $(self.$el).parent().removeClass('d-none');
+ }
+
+ self._checkTimer();
+ self.interval = setInterval(function () { self._checkTimer(); }, 1000);
+ });
+ },
+
+ /**
+ * This method removes 1 second to the current timer (pre-timer or main-timer)
+ * and call the method to update the DOM, unless main-timer is over. In that last case,
+ * the DOM element to show is displayed.
+ *
+ * @private
+ */
+ _checkTimer: function () {
+ var now = new Date();
+
+ var remainingPreSeconds = this.preCountdownTime - (now.getTime()/1000);
+ if (remainingPreSeconds <= 1) {
+ this.$('.o_countdown_text').text(this.mainCountdownText);
+ if (this.mainCountdownDisplay) {
+ $(this.$el).parent().removeClass('d-none');
+ }
+ var remainingMainSeconds = this.mainCountdownTime - (now.getTime()/1000);
+ if (remainingMainSeconds <= 1) {
+ clearInterval(this.interval);
+ $(this.displayClass).removeClass('d-none');
+ $(this.$el).parent().addClass('d-none');
+ } else {
+ this._updateCountdown(remainingMainSeconds);
+ }
+ } else {
+ this._updateCountdown(remainingPreSeconds);
+ }
+ },
+
+ /**
+ * This method update the DOM to display the remaining time.
+ * from seconds, the method extract the number of days, hours, minutes and seconds and
+ * override the different DOM elements values.
+ *
+ * @private
+ */
+ _updateCountdown: function (remainingTime) {
+ var remainingSeconds = remainingTime;
+ var days = Math.floor(remainingSeconds / 86400);
+
+ remainingSeconds = remainingSeconds % 86400;
+ var hours = Math.floor(remainingSeconds / 3600);
+
+ remainingSeconds = remainingSeconds % 3600;
+ var minutes = Math.floor(remainingSeconds / 60);
+
+ remainingSeconds = Math.floor(remainingSeconds % 60);
+
+ this.$("span.o_timer_days").text(days);
+ this.$("span.o_timer_hours").text(this._zeroPad(hours, 2));
+ this.$("span.o_timer_minutes").text(this._zeroPad(minutes, 2));
+ this.$("span.o_timer_seconds").text(this._zeroPad(remainingSeconds, 2));
+ },
+
+ /**
+ * Small tool to add leading zéros to the given number, in function of the needed number of leading zéros.
+ *
+ * @private
+ */
+ _zeroPad: function (num, places) {
+ var zero = places - num.toString().length + 1;
+ return new Array(+(zero > 0 && zero)).join("0") + num;
+ },
+
+});
+
+return publicWidget.registry.countdownWidget;
+
+});