summaryrefslogtreecommitdiff
path: root/addons/website_event/static/src/js
diff options
context:
space:
mode:
authorPatrick Hoste <pko@odoo.com>2020-03-03 14:24:00 +0000
committerPatrick Hoste <pko@odoo.com>2020-03-31 06:34:45 +0000
commitbd99cc24b145dcb2f4e7453050a5dc6d814f0c21 (patch)
tree4dd2e680d3f1e8d02e05b373e9562cd5fc8a18bd /addons/website_event/static/src/js
parentd2e02976e2934274cdc7a37616713ba6166ca1b7 (diff)
[IMP] website_event(_track): improve website and track menus behavior
PURPOSE Before this commit to activate the sub-menu, the tracks and the track proposal you had to do it on the event form view. After this commit you'll have to go on the event website page to change those options (through the customize dropdown) SPECIFICATION Remove the 'website_menu' / 'website_track' / 'website_track_proposal' from the event form view and create a toggle option in the customize dropdown on the event website page instead. LINKS Task ID : 2198660 PR : #46659
Diffstat (limited to 'addons/website_event/static/src/js')
-rw-r--r--addons/website_event/static/src/js/website_event_set_customize_options.js95
1 files changed, 95 insertions, 0 deletions
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 00000000000..4b593fcefcc
--- /dev/null
+++ b/addons/website_event/static/src/js/website_event_set_customize_options.js
@@ -0,0 +1,95 @@
+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();
+ },
+
+ _initCheckbox: function () {
+ this._rpc({
+ model: this.modelName,
+ method: 'read',
+ args: [[this.eventId], ['website_menu', 'website_url']],
+ }).then((data) => {
+ if (data[0]['website_menu']) {
+ this.$submenuInput.attr('checked', 'checked');
+ }
+ this.eventUrl = data[0]['website_url'];
+ });
+ },
+
+ _onDisplaySubmenuChange: function (ev) {
+ var checkboxValue = this.$submenuInput.is(':checked');
+ this._toggleSubmenuDisplay(checkboxValue);
+ },
+
+ _toggleSubmenuDisplay: function (val) {
+ var self = this;
+ this._rpc({
+ model: this.modelName,
+ method: 'toggle_website_menu',
+ args: [[this.eventId], val],
+ }).then(function () {
+ self._reloadEventPage();
+ });
+ },
+
+ _reloadEventPage: function () {
+ window.location = this.eventUrl;
+ },
+
+ _getEventObject: function() {
+ var repr = $('html').data('main-object');
+ var m = repr.match(/(.+)\((\d+),(.*)\)/);
+ return {
+ model: m[1],
+ id: m[2] | 0,
+ };
+ }
+
+});
+
+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,
+};
+
+});