Skip to content
Permalink
Browse files

TEMP

  • Loading branch information...
kea14 committed Apr 17, 2019
1 parent b8afd91 commit b6d843266a613b7f574e5ab70567573b724c2edc
@@ -6,6 +6,7 @@ var dom = require('web.dom');
var Widget = require('web.Widget');
var options = require('web_editor.snippets.options');
var Wysiwyg = require('web_editor.wysiwyg');
var Dialog = require('web.Dialog');

var _t = core._t;

@@ -30,6 +31,7 @@ var SnippetEditor = Widget.extend({
custom_events: {
cover_update: '_onCoverUpdate',
option_update: '_onOptionUpdate',
remove_mega_menu: '_onRemoveMegaMenu',
},

/**
@@ -343,6 +345,40 @@ var SnippetEditor = Widget.extend({

return Promise.all(defs);
},
/**
* Called when a Mega Menu is removed
*
* @private
*/
_removeMegaMenu: function () {
var $dropdownMegaMenu = this.$target.closest('.dropdown_mega_menu');
var self = this;
new Dialog(this, {
title: _t("Confirmation"),
$content: $(core.qweb.render('website.remove_mega_menu_dialog')),
buttons: [
{
text: _t("Delete this mega menu"),
classes: 'btn-primary',
click: function () {
self.trigger_up('add_mega_menu_to_remove', {
id: $dropdownMegaMenu.data('oe-id'),
});
$dropdownMegaMenu.siblings('a').removeClass('dropdown-toggle');
$dropdownMegaMenu.closest('.nav-item').removeClass('dropdown position-static');
self.trigger_up('cover_will_change');
self.trigger_up('request_history_undo_record', {$target: self.$target});
self.removeSnippet();
this.close();
}
},
{
text: _t("Discard"),
close: true,
},
]
}).open();
},

//--------------------------------------------------------------------------
// Handlers
@@ -555,10 +591,14 @@ var SnippetEditor = Widget.extend({
* @param {Event} ev
*/
_onRemoveClick: function (ev) {
ev.preventDefault();
this.trigger_up('cover_will_change');
this.trigger_up('request_history_undo_record', {$target: this.$target});
this.removeSnippet();
if (this.$target.hasClass('s_mega_menu') || this.$target.hasClass('dropdown_mega_menu')) {
this._removeMegaMenu();
} else {
ev.preventDefault();
this.trigger_up('cover_will_change');
this.trigger_up('request_history_undo_record', {$target: this.$target});
this.removeSnippet();
}
},
});

@@ -27,7 +27,7 @@ def _default_sequence(self):
child_id = fields.One2many('website.menu', 'parent_id', string='Child Menus')
parent_path = fields.Char(index=True)
is_visible = fields.Boolean(compute='_compute_visible', string='Is Visible')
mega_menu_content = fields.Html('Mega Menu Content', translate=html_translate)
mega_menu_content = fields.Html('Mega Menu Content', translate=html_translate, default=False)

@api.multi
def name_get(self):
@@ -143,6 +143,8 @@ def replace_id(old_id, new_id):
# new menu are prefixed by new-
if isinstance(mid, str):
new_menu = self.create({'name': menu['name'], 'website_id': website_id})
if menu['is_mega_menu']:
self.toggle_mega_menu(new_menu)
replace_id(mid, new_menu.id)
for menu in data['data']:
menu_id = self.browse(menu['id'])
@@ -163,9 +165,20 @@ def replace_id(old_id, new_id):
return True

@api.multi
def toggle_mega_menu(self):
def toggle_mega_menu(self, new_menu):
if new_menu:
self = new_menu
if self.mega_menu_content:
self.mega_menu_content = False
else:
self.mega_menu_content = self.env['ir.ui.view'].render_template('website.default_mega_menu')
return {'is_mega_menu': self.mega_menu_content}
return {
'id': self.id,
'name': self.name,
'url': self.page_id.url if self.page_id else self.url,
'new_window': self.new_window,
'sequence': self.sequence,
'parent_id': self.parent_id.id,
'children': [],
'is_mega_menu': bool(self.mega_menu_content),
}
@@ -24,6 +24,7 @@ var EditorMenu = Widget.extend({
},
custom_events: {
request_save: '_onSnippetRequestSave',
add_mega_menu_to_remove: '_onAddMegaMenuToRemove',
},

/**
@@ -47,6 +48,7 @@ var EditorMenu = Widget.extend({
start: function () {
var self = this;
this.$el.css({width: '100%'});
this.megaMenuToRemove = [];
return this._super().then(function () {
self.trigger_up('edit_mode');
self.$el.css({width: ''});
@@ -111,6 +113,13 @@ var EditorMenu = Widget.extend({
*/
save: function (reload) {
var self = this;
_.each(this.megaMenuToRemove, function (menuID) {
self._rpc({
model: 'website.menu',
method: 'toggle_mega_menu',
args: [menuID, null],
});
});
this.trigger_up('edition_will_stopped');
return this.wysiwyg.save().then(function (result) {
var $wrapwrap = $('#wrapwrap');
@@ -215,10 +224,14 @@ var EditorMenu = Widget.extend({
* @private
*/
_onSaveClick: function () {
// Close all dropdowns menu to avoid saving opened + edited dropdown
$('.dropdown-menu').dropdown('hide');
this.save();
},
/**
* @private
*/
_onAddMegaMenuToRemove: function (result) {
this.megaMenuToRemove.push(result.data.id);
},
});

return EditorMenu;
@@ -1540,47 +1540,17 @@ options.registry.anchorName = options.Class.extend({
},
});

var MegaMenuDialog = weWidgets.Dialog.extend({
xmlDependencies: weWidgets.Dialog.prototype.xmlDependencies.concat(
['/website/static/src/xml/website.editor.xml']
),
template: 'website.dialog.megaMenu',
events: _.extend({}, weWidgets.Dialog.prototype.events || {}, {
'click select[name="dropdown_width"]': '_onClickDropdownWidth',
}),
options.registry.megaMenu = options.Class.extend({
xmlDependencies: ['/website/static/src/xml/website.editor.xml'],

/**
* @constructor
*/
init: function (parent, options) {
this._super(parent, _.extend({
title: _t("Mega Menu Settings"),
}, options || {}));
},
/**
* @override
*/
start: function () {
return this._super.apply(this, arguments);
this.megaMenuDropdownID = this.$target.closest('.dropdown_mega_menu').data('oe-id');
this.$navLink = this.$target.closest('.dropdown_mega_menu').siblings('a');
},

//------------------------------------------------------------------
// Handlers
//------------------------------------------------------------------

/**
* @private
*/
_onClickDropdownWidth: function (ev) {
var $divDropdownPosition = $('div.dropdown_position');
$divDropdownPosition.toggleClass('d-none', $(ev.currentTarget).val() === 'w-100');
$divDropdownPosition.find('[name="dropdown_content_position"]').attr({'max': 100 - $(ev.currentTarget).find(':selected').attr('data-value')});
},
});
options.registry.megaMenu = options.Class.extend({
xmlDependencies: ['/website/static/src/xml/website.editor.xml'],
// preventChildPropagation: true,

//--------------------------------------------------------------------------
// Options
//--------------------------------------------------------------------------
@@ -1590,11 +1560,11 @@ options.registry.megaMenu = options.Class.extend({
*/
openMegaMenuDialog: function (previewMode, value, $opt) {
var self = this;
new MegaMenuDialog(this, {
new Dialog(this, {
title: _t("Mega Menu"),
$content: $(qweb.render('website.dialog.megaMenu', {
currentAlignment: self.$target.attr('data-dropdown-alignment'),
currentWidth: self.$target.attr('data-dropdown-width'),
currentPosition: self.$target.attr('data-dropdown-position'),
})),
buttons: [
{
@@ -1603,27 +1573,25 @@ options.registry.megaMenu = options.Class.extend({
click: function () {
var $dropdownContentAlignment = $('[name="dropdown_content_alignment"]');
var $dropdownWidth = $('[name="dropdown_width"]');
var $dropdownPosition = $('[name="dropdown_content_position"]');
var $dropdownMenu = self.$target.parent();
var $container = self.$target.find('.container');
var containerWidth = $dropdownWidth.val() === 'container';

$dropdownMenu.toggleClass('position-static', !containerWidth);
$container
.removeClass('text-center').removeClass('text-left').removeClass('text-right')
.addClass($dropdownContentAlignment.val());
$dropdownMenu
.removeClass('w-100').removeClass('w-75').removeClass('w-50')
.addClass($dropdownWidth.val());
if (!$dropdownMenu.hasClass('w-100')) {
$dropdownMenu.css({'left': $dropdownPosition.val() + '%'});
} else {
$dropdownMenu.css({'left': ''});
}
self.$target.attr({
'data-dropown-alignment': $dropdownContentAlignment.val(),
'data-dropdown-width': $dropdownWidth.val(),
'data-dropdown-position': $dropdownPosition.val(),
});
self.$target.trigger('content_changed');
.addClass($dropdownContentAlignment.val())
.toggleClass('container', !containerWidth)
.toggleClass('container-fluid', containerWidth)
.toggleClass('mega_menu_max_content', containerWidth);
self.$target
.toggleClass('dropdown-menu-right', containerWidth)
.toggleClass('w-100', !containerWidth)
.attr({
'data-dropdown-alignment': $dropdownContentAlignment.val(),
'data-dropdown-width': $dropdownWidth.val(),
});
$dropdownMenu.trigger('content_changed');
this.close();
}
},
@@ -100,7 +100,6 @@ var WysiwygMultizone = Wysiwyg.extend({
},
'show.bs.dropdown li.dropdown': '_onShowDropdown',
'hide.bs.dropdown .dropdown': '_onHideDropdown',
'hidden.bs.dropdown li.dropdown': '_onHiddenDropdown',
'click div.dropdown-menu, div.oe_overlay_options': '_onClickInDropdown',
'click': '_onClick',
}),
@@ -197,6 +196,11 @@ var WysiwygMultizone = Wysiwyg.extend({
self.$('[data-oe-readonly]').addClass('o_not_editable').attr('contenteditable', false);
self.$('.oe_structure').attr('contenteditable', false).addClass('o_fake_not_editable');
self.$('[data-oe-field][data-oe-type="image"]').attr('contenteditable', false).addClass('o_fake_not_editable');

// Showing Mega Menu snippets if one Mega Menu dropdown is already opened
if (self.$('.dropdown_mega_menu').hasClass('show')) {
self._toggleMegaMenuSnippetsAtStart();
}
});
},
/**
@@ -477,6 +481,14 @@ var WysiwygMultizone = Wysiwyg.extend({
},
});
},
/**
* Toggle visibility of Mega Menu snippets.
*
* @private
*/
_toggleMegaMenuSnippetsAtStart: _.debounce(function () {
this.snippets.trigger('toggle_mega_menu_snippets', true);
}, 1500),

//--------------------------------------------------------------------------
// Handler
@@ -595,12 +607,6 @@ var WysiwygMultizone = Wysiwyg.extend({
}
delete this.dropdownClickedElement;
},
/**
* @override
*/
_onHiddenDropdown: function (ev) {
this.snippets.trigger('toggle_mega_menu_snippets', false);
},
/**
* @override
*/
@@ -613,6 +619,7 @@ var WysiwygMultizone = Wysiwyg.extend({
_onClick: function (ev) {
var container = $('[data-oe-field="mega_menu_content"], .oe_overlay_options');
if (!container.is(ev.target) && container.has(ev.target).length === 0) {
this.snippets.trigger('toggle_mega_menu_snippets', false);
$(ev.currentTarget).find('.dropdown-menu').removeClass('show');
}
},
@@ -596,7 +596,7 @@ var EditMenuDialog = weWidgets.Dialog.extend({
parent_id: false,
sequence: 0,
children: [],
hide_mega_menu: true,
is_mega_menu: false,
};
self.flat[new_menu.id] = new_menu;
self.$('.oe_menu_editor').append(
@@ -651,18 +651,34 @@ var EditMenuDialog = weWidgets.Dialog.extend({
_onConvertMegaMenuButtonClick: function (ev) {
var $menu = $(ev.currentTarget).closest('[data-menu-id]');
var menuID = $menu.data('menu-id') | 0;
this._rpc({
model: 'website.menu',
method: 'toggle_mega_menu',
args: [this.flat[menuID].id],
}).then(function (response) {
var $inputGroup = $(ev.currentTarget).closest('.input-group');
if (response.is_mega_menu) {
$inputGroup.find('.align-items-center').append('<span class="badge badge-primary">Mega Menu</span>');
} else {
$inputGroup.find('.badge').remove();
}
});
if (menuID === 0) {
menuID = $(ev.currentTarget).closest('li').data('menu-id');
this.flat[menuID].is_mega_menu = !this.flat[menuID].is_mega_menu;
renderMenu(this.flat[menuID]);
} else {
this._rpc({
model: 'website.menu',
method: 'toggle_mega_menu',
args: [this.flat[menuID].id, null],
}).then(function (response) {
renderMenu(response);
});
}

function renderMenu(data) {
var menuData = {
id: data.id,
name: data.name,
url: data.url,
new_window: data.new_window,
parent_id: false,
sequence: 0,
children: [],
is_mega_menu: data.is_mega_menu,
};
$(ev.currentTarget).closest('.input-group')
.replaceWith(qweb.render('website.contentMenu.dialog.submenu', { submenu: menuData }));
}
},
});

@@ -185,6 +185,7 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({
* @param {OdooEvent} ev
*/
_onEditionWillStop: function (ev) {
$('.dropdown_mega_menu').dropdown('hide');
this.$editorMessageElements.removeAttr('data-editor-message');
this.trigger_up('widgets_stop_request', {
$target: this._targetForEdition(),
@@ -1154,3 +1154,7 @@ table.table_desc tr td {
.modal-footer > .float-left {
margin-right: auto;
}

.mega_menu_max_content {
width: max-content;
}
Oops, something went wrong.

0 comments on commit b6d8432

Please sign in to comment.
You can’t perform that action at this time.