[IMP] website, *: improve customize dialog no-reload updates

* base

Before this commit, if an option was customized thanks to the customize
dialog, the page was not reloaded, only the new scss <link/> elements
were retrieved and replaced in the DOM.
There were two problems with this:
- The <script/> and <style/> tags were also retrieved for no reason (as
the whole result of t-call-assets was returned)
- This made use of a deprecated ir.qweb method that we want to remove
(see https://github.com/odoo/odoo/pull/33432)

This commit removes the use of the deprecated method by improving the
system: only the <link/>'s new URLs are returned on customization.

closes odoo/odoo#34040

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
qsm-odoo
2019-06-11 16:06:07 +00:00
parent b5091c7017
commit d7da1d648c
3 changed files with 17 additions and 7 deletions
+3 -3
View File
@@ -354,9 +354,9 @@ class Website(Home):
if get_bundle:
context = dict(request.context)
return {
'web.assets_common': request.env["ir.qweb"]._get_asset('web.assets_common', options=context),
'web.assets_frontend': request.env["ir.qweb"]._get_asset('web.assets_frontend', options=context),
'website.assets_editor': request.env["ir.qweb"]._get_asset('website.assets_editor', options=context),
'web.assets_common': request.env['ir.qweb']._get_asset_link_urls('web.assets_common', options=context),
'web.assets_frontend': request.env['ir.qweb']._get_asset_link_urls('web.assets_frontend', options=context),
'website.assets_editor': request.env['ir.qweb']._get_asset_link_urls('website.assets_editor', options=context),
}
return True
+10 -4
View File
@@ -611,11 +611,17 @@ var ThemeCustomizeDialog = Dialog.extend({
},
}).then(function (bundles) {
var $allLinks = $();
var defs = _.map(bundles, function (bundleContent, bundleName) {
var linkSelector = 'link[href*="' + bundleName + '"]';
var $links = $(linkSelector);
var defs = _.map(bundles, function (bundleURLs, bundleName) {
var $links = $('link[href*="' + bundleName + '"]');
$allLinks = $allLinks.add($links);
var $newLinks = $(bundleContent).filter(linkSelector);
var $newLinks = $();
_.each(bundleURLs, function (url) {
$newLinks = $newLinks.add($('<link/>', {
type: 'text/css',
rel: 'stylesheet',
href: url,
}));
});
var linksLoaded = new Promise(function (resolve, reject) {
var nbLoaded = 0;
+4
View File
@@ -307,6 +307,10 @@ class IrQWeb(models.AbstractModel, QWeb):
remains = [node for node in remains if (css and node[0] == 'link') or (js and node[0] != 'link')]
return remains + asset.to_node(css=css, js=js, debug=debug, async_load=async_load, defer_load=defer_load, lazy_load=lazy_load)
def _get_asset_link_urls(self, xmlid, options):
asset_nodes = self._get_asset_nodes(xmlid, options, js=False)
return [node[1]['href'] for node in asset_nodes if node[0] == 'link']
@tools.ormcache_context('xmlid', 'options.get("lang", "en_US")', keys=("website_id",))
def _get_asset_content(self, xmlid, options):
options = dict(options,