Files
odoo_source/addons/website_theme_install/views/views.xml
T
Joren Van Onder 4f6ec1cd2a [IMP] website,*: support multiple websites
This implements support to administer multiple websites. Although the
core functionality already existed, managing multiple websites was
fairly technical.

In the interest of database updates and migration this attempts to
keep duplicated data to a minimum. To do this the usual generic
records are rendered unless some website-specific record exists that
replaces it. Copy-on-write (COW) is used to create these
website-specific records. Through this mechanism creating a
website-specific record is delayed until necessary. A COW mechanism
has been implemented on 4 models: ir.ui.view, website.page,
website.menu and ir.attachment. These COW mechanisms are activated
when editing data through the website (aka frontend). These frontend
edits (e.g. with web_editor) will be website-specific, possibly
creating a website-specific record when necessary. When editing data
in the backend nothing special will happen, even when editing a
generic record. Note that because of this mechanism also facilitates
the ability to create new, uncustomized websites because the generic
data is kept.

Support is provided for a website to have any theme. Themes are fairly
complex to handle. Standalone themes can depend on other standalone
themes (e.g. theme_beauty depends on theme_loftspace) and themes
usually modify some data of the themes they depend on. Because a theme
can be installed on multiple websites, using website_id m2o fields
does not work well. It would require duplicate data, making updates
and migration harder. Because of this, data for themes (ir.ui.view and
ir.attachment specifically) have a theme_id m2o. website has a
theme_ids m2m that identifies all theme modules currently installed on
it. Through these fields we figure out what to render. A theme is only
fully uninstalled when it's no longer active on any website. The
advantage of this approach is that upgrading or migrating theme data
is no different from the single-website case.

The website.published.mixin class was modified to handle multiple
websites. A wizard was added in the backend to easily manage this for
multiple website.

Although not used anywhere in this commit, a 'website_id' variable has
been added in the evaluation context of ir.rule. It allows to easily
make any model multi-website aware, all that's needed is a custom
website_id m2o field on a model and a custom record rule.
2018-08-13 19:51:10 +02:00

111 lines
6.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Custom module kanban : install button (even if already installed) which redirects to website after (fake or not) installation + live preview button -->
<record model="ir.ui.view" id="theme_view_kanban">
<field name="name">Themes Kanban</field>
<field name="model">ir.module.module</field>
<field name="arch" type="xml">
<kanban create="false" class="o_theme_kanban" default_order="state,sequence,name">
<field name="icon"/>
<field name="name"/>
<field name="state"/>
<field name="url"/>
<field name="image_ids"/>
<field name="category_id"/>
<field name="display_name"/>
<field name="is_installed_on_current_website"/>
<templates>
<div t-name="kanban-box" t-attf-class="o_theme_preview mb16 mt16 #{record.is_installed_on_current_website.raw_value? 'o_theme_installed' : ''}">
<t t-set="has_image" t-value="record.image_ids.raw_value.length > 0"/>
<t t-set="has_screenshot" t-value="record.image_ids.raw_value.length > 1"/>
<t t-set="image_url" t-value="has_image ? 'web/image/' + record.image_ids.raw_value[0] : record.icon.value"/>
<div class="o_theme_preview_top bg-white mb4">
<div class="o_browser_bar"/>
<i states="installed" t-if="record.is_installed_on_current_website.raw_value" class="text-center bg-white text-success img-circle fa fa-check-circle" role="img" aria-label="Installed" title="Installed"/>
<div t-attf-class="bg-gray-lighter #{has_screenshot? 'o_theme_screenshot' : (has_image ? 'o_theme_cover' : 'o_theme_logo')}" t-attf-style="background-image: url(#{image_url});"/>
<div t-if="record.is_installed_on_current_website.raw_value" class="o_button_area">
<button type="object" name="button_immediate_uninstall" class="btn btn-primary">Uninstall theme</button>
</div>
<div t-else="" class="o_button_area">
<button type="object" name="button_choose_theme" class="btn btn-primary">Use this theme</button>
<hr t-if="record.url.value"/>
<a role="button" t-if="record.url.value" class="btn btn-secondary" t-att-href="record.url.value" target="_blank">Live Preview</a>
</div>
</div>
<div class="o_theme_preview_bottom clearfix">
<h5 t-if="record.display_name.value" class="text-uppercase float-left">
<img class="float-left mr4" t-att-src="record.icon.value" height="16" width="16" alt="Theme preview"/>
<b><t t-esc="record.display_name.value.replace(('Theme'), '').replace(('theme'), '')"/></b>
</h5>
<h6 t-if="record.category_id.value" class="text-muted float-right">
<b><t t-esc="record.category_id.value"/></b>
</h6>
</div>
</div>
</templates>
</kanban>
</field>
</record>
<record model="ir.ui.view" id="theme_view_search">
<field name="name">Themes Search</field>
<field name="model">ir.module.module</field>
<field name="priority">50</field>
<field name="arch" type="xml">
<search>
<field name="name" filter_domain="['|', '|', ('summary', 'ilike', self), ('shortdesc', 'ilike', self), ('name', 'ilike', self)]" string="Theme"/>
<field name="category_id" filter_domain="['|', '|', ('summary', 'ilike', self), ('shortdesc', 'ilike', self), ('category_id', 'ilike', self)]" string="Category"/>
<group>
<filter string="Author" name="author" domain="[]" context="{'group_by':'author'}"/>
<filter string="Category" name="category" domain="[]" context="{'group_by':'category_id'}"/>
</group>
</search>
</field>
</record>
<!-- themes should be installed through website_theme_install -->
<record id="base.open_module_tree" model="ir.actions.act_window">
<field name="domain">['!', ('name', '=like', 'theme_%')]</field>
</record>
<!-- Actions to list themes with custom kanban (launched on module installation) -->
<record id="theme_install_kanban_action" model="ir.actions.act_window">
<field name="name">Choose a theme for this website</field>
<field name="res_model">ir.module.module</field>
<field name="view_mode">kanban</field>
<field name="view_id" ref="theme_view_kanban"/>
<field name="search_view_id" ref="theme_view_search"/>
<field name="domain" eval="[
('category_id', 'not in', [ref('base.module_category_theme_hidden', False)]),
'|', ('category_id', '=', ref('base.module_category_theme', False)), ('category_id.parent_id', '=', ref('base.module_category_theme', False))
]"/>
</record>
<record id="theme_install_todo_action" model="ir.actions.server">
<field name="name">Config: Choose Your Theme</field>
<field name="model_id" ref="model_ir_module_module"/>
<field name="state">code</field>
<field name="code">
model.update_list()
action = {
'type': 'ir.actions.act_url',
'url': '/web?reload#action=website_theme_install.theme_install_kanban_action', # the ?reload option is there to fool the webclient into thinking it is a different location and so to force a reload
'target': 'self',
}
</field>
</record>
<record id="theme_install_todo" model="ir.actions.todo">
<field name="action_id" ref="theme_install_todo_action"/>
<field name="sequence">0</field>
</record>
<!-- Add link to theme install in default customize modal -->
<template id="customize_modal" inherit_id="website.theme_customize" priority="1">
<xpath expr="//div" position="replace">
<div>
Please <a href="/web#action=website_theme_install.theme_install_kanban_action">install a theme</a> to customize your website.
</div>
</xpath>
</template>
</odoo>