summaryrefslogtreecommitdiff
path: root/addons/website_event/static/src/js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website_event/static/src/js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website_event/static/src/js')
-rw-r--r--addons/website_event/static/src/js/display_timer_widget.js111
-rw-r--r--addons/website_event/static/src/js/register_toaster_widget.js31
-rw-r--r--addons/website_event/static/src/js/tours/event_tour.js61
-rw-r--r--addons/website_event/static/src/js/tours/website_event.js49
-rw-r--r--addons/website_event/static/src/js/website_event.editor.js49
-rw-r--r--addons/website_event/static/src/js/website_event.js93
-rw-r--r--addons/website_event/static/src/js/website_event_set_customize_options.js122
-rw-r--r--addons/website_event/static/src/js/website_event_ticket_details.js55
-rw-r--r--addons/website_event/static/src/js/website_geolocation.js41
9 files changed, 612 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 00000000..5f612736
--- /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;
+
+});
diff --git a/addons/website_event/static/src/js/register_toaster_widget.js b/addons/website_event/static/src/js/register_toaster_widget.js
new file mode 100644
index 00000000..891f6155
--- /dev/null
+++ b/addons/website_event/static/src/js/register_toaster_widget.js
@@ -0,0 +1,31 @@
+odoo.define('website_event.register_toaster_widget', function (require) {
+'use strict';
+
+let core = require('web.core');
+let _t = core._t;
+let publicWidget = require('web.public.widget');
+
+publicWidget.registry.RegisterToasterWidget = publicWidget.Widget.extend({
+ selector: '.o_wevent_register_toaster',
+
+ /**
+ * This widget allows to display a toast message on the page.
+ *
+ * @override
+ */
+ start: function () {
+ const message = this.$el.data('message');
+ if (message && message.length) {
+ this.displayNotification({
+ title: _t("Register"),
+ message: message,
+ type: 'info'
+ });
+ }
+ return this._super.apply(this, arguments);
+ },
+});
+
+return publicWidget.registry.RegisterToasterWidget;
+
+});
diff --git a/addons/website_event/static/src/js/tours/event_tour.js b/addons/website_event/static/src/js/tours/event_tour.js
new file mode 100644
index 00000000..421146c1
--- /dev/null
+++ b/addons/website_event/static/src/js/tours/event_tour.js
@@ -0,0 +1,61 @@
+odoo.define('website_event.event_steps', function (require) {
+"use strict";
+
+var core = require('web.core');
+var _t = core._t;
+
+var EventAdditionalTourSteps = require('event.event_steps');
+
+EventAdditionalTourSteps.include({
+
+ init: function() {
+ this._super.apply(this, arguments);
+ },
+
+ _get_website_event_steps: function () {
+ this._super.apply(this, arguments);
+ return [{
+ trigger: '.o_event_form_view button[name="is_published"]',
+ content: _t("Use this <b>shortcut</b> to easily access your event web page."),
+ position: 'bottom',
+ }, {
+ trigger: 'li#edit-page-menu a',
+ extra_trigger: '.o_wevent_event',
+ content: _t("With the Edit button, you can <b>customize</b> the web page visitors will see when registering."),
+ position: 'bottom',
+ }, {
+ trigger: 'div[name="Image - Text"] .oe_snippet_thumbnail',
+ extra_trigger: '.o_wevent_event',
+ content: _t("<b>Drag and Drop</b> this snippet below the event title."),
+ position: 'bottom',
+ run: 'drag_and_drop #o_wevent_event_main_col',
+ }, {
+ trigger: 'button[data-action="save"]',
+ extra_trigger: '.o_wevent_event',
+ content: _t("Don't forget to click <b>save</b> when you're done."),
+ position: 'bottom',
+ }, {
+ trigger: 'label.js_publish_btn',
+ extra_trigger: '.o_wevent_event',
+ content: _t("Looking great! Let's now <b>publish</b> this page so that it becomes <b>visible</b> on your website!"),
+ position: 'bottom',
+ }, {
+ trigger: 'a.css_edit_dynamic',
+ extra_trigger: '.js_publish_management[data-object="event.event"] .js_publish_btn .css_unpublish:visible',
+ content: _t("Want to change your event configuration? Let's go back to the event form."),
+ position: 'bottom',
+ run: function (actions) {
+ actions.click('div.dropdown-menu a#edit-in-backend');
+ },
+ }, {
+ trigger: 'a#edit-in-backend',
+ extra_trigger: '.o_wevent_event',
+ content: _t("This shortcut will bring you right back to the event form."),
+ position: 'bottom'
+ }];
+ }
+});
+
+return EventAdditionalTourSteps;
+
+});
diff --git a/addons/website_event/static/src/js/tours/website_event.js b/addons/website_event/static/src/js/tours/website_event.js
new file mode 100644
index 00000000..b07c83a3
--- /dev/null
+++ b/addons/website_event/static/src/js/tours/website_event.js
@@ -0,0 +1,49 @@
+odoo.define("website_event.tour", function (require) {
+ "use strict";
+
+ var core = require("web.core");
+ var tour = require("web_tour.tour");
+
+ var _t = core._t;
+
+ tour.register("event", {
+ url: "/",
+ }, [{
+ content: _t("Click here to add new content to your website."),
+ trigger: '#new-content-menu > a',
+ position: 'bottom',
+ }, {
+ trigger: "a[data-action=new_event]",
+ content: _t("Click here to create a new event."),
+ position: "bottom",
+ }, {
+ trigger: '.modal-dialog #editor_new_event input[type=text]',
+ content: _t("Create a name for your new event and click <em>\"Continue\"</em>. e.g: Technical Training"),
+ position: "left",
+ }, {
+ trigger: '.modal-footer button.btn-primary.btn-continue',
+ extra_trigger: '#editor_new_event input[type=text][value!=""]',
+ content: _t("Click <em>Continue</em> to create the event."),
+ position: "right",
+ }, {
+ trigger: "#snippet_structure .oe_snippet:eq(2) .oe_snippet_thumbnail",
+ content: _t("Drag this block and drop it in your page."),
+ position: "bottom",
+ run: "drag_and_drop",
+ }, {
+ trigger: "button[data-action=save]",
+ content: _t("Once you click on save, your event is updated."),
+ position: "bottom",
+ extra_trigger: ".o_dirty",
+ }, {
+ trigger: ".js_publish_management .js_publish_btn",
+ extra_trigger: "body:not(.editor_enable)",
+ content: _t("Click to publish your event."),
+ position: "top",
+ }, {
+ trigger: ".css_edit_dynamic",
+ extra_trigger: ".js_publish_management .js_publish_btn .css_unpublish:visible",
+ content: _t("Click here to customize your event further."),
+ position: "bottom",
+ }]);
+});
diff --git a/addons/website_event/static/src/js/website_event.editor.js b/addons/website_event/static/src/js/website_event.editor.js
new file mode 100644
index 00000000..48f3a995
--- /dev/null
+++ b/addons/website_event/static/src/js/website_event.editor.js
@@ -0,0 +1,49 @@
+odoo.define('website_event.editor', function (require) {
+"use strict";
+
+var core = require('web.core');
+var wUtils = require('website.utils');
+var WebsiteNewMenu = require('website.newMenu');
+
+var _t = core._t;
+
+WebsiteNewMenu.include({
+ actions: _.extend({}, WebsiteNewMenu.prototype.actions || {}, {
+ new_event: '_createNewEvent',
+ }),
+
+ //--------------------------------------------------------------------------
+ // Actions
+ //--------------------------------------------------------------------------
+
+ /**
+ * Asks the user information about a new event to create, then creates it
+ * and redirects the user to this new event.
+ *
+ * @private
+ * @returns {Promise} Unresolved if there is a redirection
+ */
+ _createNewEvent: function () {
+ var self = this;
+ return wUtils.prompt({
+ id: "editor_new_event",
+ window_title: _t("New Event"),
+ input: _t("Event Name"),
+ }).then(function (result) {
+ var eventName = result.val;
+ if (!eventName) {
+ return;
+ }
+ return self._rpc({
+ route: '/event/add_event',
+ params: {
+ event_name: eventName,
+ },
+ }).then(function (url) {
+ window.location.href = url;
+ return new Promise(function () {});
+ });
+ });
+ },
+});
+});
diff --git a/addons/website_event/static/src/js/website_event.js b/addons/website_event/static/src/js/website_event.js
new file mode 100644
index 00000000..11990e97
--- /dev/null
+++ b/addons/website_event/static/src/js/website_event.js
@@ -0,0 +1,93 @@
+odoo.define('website_event.website_event', function (require) {
+
+var ajax = require('web.ajax');
+var core = require('web.core');
+var Widget = require('web.Widget');
+var publicWidget = require('web.public.widget');
+
+var _t = core._t;
+
+// Catch registration form event, because of JS for attendee details
+var EventRegistrationForm = Widget.extend({
+
+ /**
+ * @override
+ */
+ start: function () {
+ var self = this;
+ var res = this._super.apply(this.arguments).then(function () {
+ $('#registration_form .a-submit')
+ .off('click')
+ .click(function (ev) {
+ self.on_click(ev);
+ });
+ });
+ return res;
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {Event} ev
+ */
+ on_click: function (ev) {
+ ev.preventDefault();
+ ev.stopPropagation();
+ var $form = $(ev.currentTarget).closest('form');
+ var $button = $(ev.currentTarget).closest('[type="submit"]');
+ var post = {};
+ $('#registration_form table').siblings('.alert').remove();
+ $('#registration_form select').each(function () {
+ post[$(this).attr('name')] = $(this).val();
+ });
+ var tickets_ordered = _.some(_.map(post, function (value, key) { return parseInt(value); }));
+ if (!tickets_ordered) {
+ $('<div class="alert alert-info"/>')
+ .text(_t('Please select at least one ticket.'))
+ .insertAfter('#registration_form table');
+ return new Promise(function () {});
+ } else {
+ $button.attr('disabled', true);
+ return ajax.jsonRpc($form.attr('action'), 'call', post).then(function (modal) {
+ var $modal = $(modal);
+ $modal.modal({backdrop: 'static', keyboard: false});
+ $modal.find('.modal-body > div').removeClass('container'); // retrocompatibility - REMOVE ME in master / saas-19
+ $modal.appendTo('body').modal();
+ $modal.on('click', '.js_goto_event', function () {
+ $modal.modal('hide');
+ $button.prop('disabled', false);
+ });
+ $modal.on('click', '.close', function () {
+ $button.prop('disabled', false);
+ });
+ });
+ }
+ },
+});
+
+publicWidget.registry.EventRegistrationFormInstance = publicWidget.Widget.extend({
+ selector: '#registration_form',
+
+ /**
+ * @override
+ */
+ start: function () {
+ var def = this._super.apply(this, arguments);
+ this.instance = new EventRegistrationForm(this);
+ return Promise.all([def, this.instance.attachTo(this.$el)]);
+ },
+ /**
+ * @override
+ */
+ destroy: function () {
+ this.instance.setElement(null);
+ this._super.apply(this, arguments);
+ this.instance.setElement(this.$el);
+ },
+});
+
+return EventRegistrationForm;
+});
diff --git a/addons/website_event/static/src/js/website_event_set_customize_options.js b/addons/website_event/static/src/js/website_event_set_customize_options.js
new file mode 100644
index 00000000..a6d9f749
--- /dev/null
+++ b/addons/website_event/static/src/js/website_event_set_customize_options.js
@@ -0,0 +1,122 @@
+odoo.define('website_event.set_customize_options', function (require) {
+"use strict";
+
+var CustomizeMenu = require('website.customizeMenu');
+var publicWidget = require('web.public.widget');
+
+var EventSpecificOptions = publicWidget.Widget.extend({
+ template: 'website_event.customize_options',
+ xmlDependencies: ['/website_event/static/src/xml/customize_options.xml'],
+ events: {
+ 'change #display-website-menu': '_onDisplaySubmenuChange',
+ },
+
+ /**
+ * @override
+ */
+ start: function () {
+ this.$submenuInput = this.$('#display-website-menu');
+ this.modelName = this._getEventObject().model;
+ this.eventId = this._getEventObject().id;
+ this._initCheckbox();
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ _onDisplaySubmenuChange: function (ev) {
+ var checkboxValue = this.$submenuInput.is(':checked');
+ this._toggleSubmenuDisplay(checkboxValue);
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ _getCheckboxFields: function () {
+ return ['website_menu', 'website_url'];
+ },
+
+ _getCheckboxFieldMatch: function (checkboxField) {
+ if (checkboxField === 'website_menu') {
+ return this.$submenuInput;
+ }
+ },
+
+ _getEventObject: function() {
+ var repr = $('html').data('main-object');
+ var m = repr.match(/(.+)\((\d+),(.*)\)/);
+ return {
+ model: m[1],
+ id: m[2] | 0,
+ };
+ },
+
+ _initCheckbox: function () {
+ var self = this;
+ this._rpc({
+ model: this.modelName,
+ method: 'read',
+ args: [
+ [this.eventId],
+ this._getCheckboxFields()
+ ],
+ }).then((data) => {
+ self._initCheckboxCallback(data);
+ });
+ },
+
+ _initCheckboxCallback: function (rpcData) {
+ if (rpcData[0]['website_menu']) {
+ var submenuInput = this._getCheckboxFieldMatch('website_menu');
+ submenuInput.attr('checked', 'checked');
+ }
+ this.eventUrl = rpcData[0]['website_url'];
+ },
+
+ _reloadEventPage: function () {
+ window.location = this.eventUrl;
+ },
+
+ _toggleSubmenuDisplay: function (val) {
+ var self = this;
+ this._rpc({
+ model: this.modelName,
+ method: 'toggle_website_menu',
+ args: [[this.eventId], val],
+ }).then(function () {
+ self._reloadEventPage();
+ });
+ },
+
+});
+
+CustomizeMenu.include({
+ _getEventObject: function() {
+ var repr = $('html').data('main-object');
+ var m = repr.match(/(.+)\((\d+),(.*)\)/);
+ return {
+ model: m[1],
+ id: m[2] | 0,
+ };
+ },
+
+ _loadCustomizeOptions: function () {
+ var self = this;
+ var def = this._super.apply(this, arguments);
+ return def.then(function () {
+ if (!self.__eventOptionsLoaded && self._getEventObject().model === 'event.event') {
+ self.__eventOptionsLoaded = true;
+ self.eventOptions = new EventSpecificOptions(self);
+ self.eventOptions.insertAfter(self.$el.find('.dropdown-divider:first()'));
+ }
+ });
+ },
+});
+
+return {
+ EventSpecificOptions: EventSpecificOptions,
+};
+
+});
diff --git a/addons/website_event/static/src/js/website_event_ticket_details.js b/addons/website_event/static/src/js/website_event_ticket_details.js
new file mode 100644
index 00000000..8ad2e307
--- /dev/null
+++ b/addons/website_event/static/src/js/website_event_ticket_details.js
@@ -0,0 +1,55 @@
+odoo.define('website_event.ticket_details', function (require) {
+ var publicWidget = require('web.public.widget');
+
+ publicWidget.registry.ticketDetailsWidget = publicWidget.Widget.extend({
+ selector: '.o_wevent_js_ticket_details',
+ events: {
+ 'click .o_wevent_registration_btn': '_onTicketDetailsClick',
+ 'change .custom-select': '_onTicketQuantityChange'
+ },
+ start: function (){
+ this.foldedByDefault = this.$el.data('foldedByDefault') === 1;
+ return this._super.apply(this, arguments);
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _getTotalTicketCount: function (){
+ var ticketCount = 0;
+ this.$('.custom-select').each(function (){
+ ticketCount += parseInt($(this).val());
+ });
+ return ticketCount;
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {*} ev
+ */
+ _onTicketDetailsClick: function (ev){
+ ev.preventDefault();
+ if (this.foldedByDefault){
+ $(ev.currentTarget).toggleClass('btn-primary text-left pl-0');
+ $(ev.currentTarget).siblings().toggleClass('d-none');
+ this.$('.close').toggleClass('d-none');
+ }
+ },
+ /**
+ * @private
+ */
+ _onTicketQuantityChange: function (){
+ this.$('button.btn-primary').attr('disabled', this._getTotalTicketCount() === 0);
+ }
+ });
+
+return publicWidget.registry.ticketDetailsWidget;
+});
diff --git a/addons/website_event/static/src/js/website_geolocation.js b/addons/website_event/static/src/js/website_geolocation.js
new file mode 100644
index 00000000..0c93dbbb
--- /dev/null
+++ b/addons/website_event/static/src/js/website_geolocation.js
@@ -0,0 +1,41 @@
+odoo.define('website_event.geolocation', function (require) {
+'use strict';
+
+var publicWidget = require('web.public.widget');
+
+publicWidget.registry.visitor = publicWidget.Widget.extend({
+ selector: ".oe_country_events, .country_events",
+ disabledInEditableMode: false,
+
+ /**
+ * @override
+ */
+ start: function () {
+ var defs = [this._super.apply(this, arguments)];
+ var self = this;
+ var $eventList = this.$('.country_events_list');
+ this._originalContent = $eventList[0].outerHTML;
+ defs.push(this._rpc({route: '/event/get_country_event_list'}).then(function (data) {
+ if (data) {
+ self._$loadedContent = $(data);
+
+ self._$loadedContent.attr('contentEditable', false);
+ self._$loadedContent.addClass('o_temp_auto_element');
+ self._$loadedContent.attr('data-temp-auto-element-original-content', self._originalContent);
+
+ $eventList.replaceWith(self._$loadedContent);
+ }
+ }));
+ return Promise.all(defs);
+ },
+ /**
+ * @override
+ */
+ destroy: function () {
+ this._super.apply(this, arguments);
+ if (this._$loadedContent) {
+ this._$loadedContent.replaceWith(this._originalContent);
+ }
+ },
+});
+});