odoo.define('website.theme', function (require) { 'use strict'; var config = require('web.config'); var core = require('web.core'); var ColorpickerDialog = require('web.colorpicker'); var Dialog = require('web.Dialog'); var widgets = require('web_editor.widget'); var websiteNavbarData = require('website.navbar'); var _t = core._t; var templateDef = null; var ThemeCustomizeDialog = Dialog.extend({ xmlDependencies: (Dialog.prototype.xmlDependencies || []) .concat(['/website/static/src/xml/website.editor.xml']), template: 'website.theme_customize', events: { 'change [data-xmlid], [data-enable], [data-disable]': '_onChange', 'click .checked [data-xmlid], .checked [data-enable], .checked [data-disable]': '_onChange', 'click .o_theme_customize_color': '_onColorClick', }, /** * @constructor */ init: function (parent, options) { options = options || {}; this._super(parent, _.extend({ title: _t("Customize this theme"), buttons: [], }, options)); this.defaultTab = options.tab || 0; }, /** * @override */ willStart: function () { if (templateDef === null) { templateDef = this._rpc({ model: 'ir.ui.view', method: 'read_template', args: ['website.theme_customize'], }).then(function (data) { return core.qweb.add_template(data); }); } return $.when(this._super.apply(this, arguments), templateDef); }, /** * @override */ start: function () { var self = this; this._generateDialogHTML(); this.$modal.addClass('o_theme_customize_modal'); // Enable the first option tab or the given default tab var $tabs = this.$('[data-toggle="tab"]'); this.opened().then(function () { $tabs.eq(self.defaultTab).tab('show'); var $colorPreview = self.$('.o_theme_customize_color_previews:visible'); var $primary = $colorPreview.find('.o_theme_customize_color[data-color="primary"]'); var $alpha = $colorPreview.find('.o_theme_customize_color[data-color="alpha"]'); var $secondary = $colorPreview.find('.o_theme_customize_color[data-color="secondary"]'); var $beta = $colorPreview.find('.o_theme_customize_color[data-color="beta"]'); var sameAlphaPrimary = $primary.find('.o_color_preview').css('background-color') === $alpha.find('.o_color_preview').css('background-color'); var sameBetaSecondary = $secondary.find('.o_color_preview').css('background-color') === $beta.find('.o_color_preview').css('background-color'); if (!sameAlphaPrimary) { $alpha.find('.o_color_name').text(_t("Extra Color")); $primary.removeClass('d-none').addClass('d-flex'); } if (!sameBetaSecondary) { $beta.find('.o_color_name').text(_t("Extra Color")); $secondary.removeClass('d-none').addClass('d-flex'); } if (!sameAlphaPrimary && sameBetaSecondary) { $beta.insertBefore($alpha); } else if (sameAlphaPrimary && !sameBetaSecondary) { $secondary.insertAfter($alpha); } }); // Hide the tab navigation if only one tab if ($tabs.length <= 1) { $tabs.closest('.nav').addClass('d-none'); } this.$inputs = this.$('[data-xmlid], [data-enable], [data-disable]'); return $.when( this._super.apply(this, arguments), this._loadViews() ); }, //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- /** * @private */ _generateDialogHTML: function () { var $contents = this.$el.children('content'); if ($contents.length === 0) { return; } $contents.remove(); this.$el.append(core.qweb.render('website.theme_customize_modal_layout')); var $navLinksContainer = this.$('.nav'); var $navContents = this.$('.tab-content'); _.each($contents, function (content) { var $content = $(content); var contentID = _.uniqueId('content-'); // Build the nav tab for the content $navLinksContainer.append($('
  • ', { class: 'nav-item mb-1', }).append($('', { href: '#' + contentID, class: 'nav-link', 'data-toggle': 'tab', text: $content.attr('string'), }))); // Build the tab pane for the content var $navContent = $(core.qweb.render('website.theme_customize_modal_content', { id: contentID, title: $content.attr('title'), })); $navContents.append($navContent); var $optionsContainer = $navContent.find('.o_options_container'); // Process content items _processItems($content.children(), $optionsContainer); }); this.$('[title]').tooltip(); function _processItems($items, $container) { var optionsName = _.uniqueId('option-'); _.each($items, function (item) { var $item = $(item); var $col; switch (item.tagName) { case 'OPT': var colorPalette = $item.data('colorPalette') === 'user'; var icon = $item.data('icon'); // Build the options template var $multiChoiceLabel = $(core.qweb.render('website.theme_customize_modal_option', { name: optionsName, id: $item.attr('id') || _.uniqueId('o_theme_customize_input_id_'), string: $item.attr('string'), icon: icon, color: $item.data('color'), font: $item.data('font'), colorPalette: colorPalette, xmlid: $item.data('xmlid'), enable: $item.data('enable'), disable: $item.data('disable'), reload: $item.data('reload'), })); $multiChoiceLabel.find('.o_theme_customize_color[data-color="primary"]').addClass('d-none').removeClass('d-flex'); $multiChoiceLabel.find('.o_theme_customize_color[data-color="secondary"]').addClass('d-none').removeClass('d-flex'); if ($container.hasClass('form-row')) { $col = $('
    ', {class: (icon ? 'col-4' : (colorPalette ? 'col-12' : 'col-6'))}); $col.append($multiChoiceLabel); $container.append($col); } else { $container.append($multiChoiceLabel); } break; case 'MORE': var collapseID = _.uniqueId('collapse-'); $col = $('
    ', { class: 'col-12', }).appendTo($container); var string = $item.attr('string'); if (string) { var $button = $('