[IMP] web_editor, website(_*): show all snippets even if module is not installed

* mail_channel, mass_mailing, twitter, event

- t-install attribute holds the technical name of the module that
  needs to be install to use a particular snippet.

- Disable the drag & drop feature for these dummy snippets.

- Move some images to website module.

- Installed snippets display at the top of the list.

- Hide not-installed module snippets if user don't have rights to install module.
This commit is contained in:
Kishan Gajjar
2017-07-04 10:54:20 +02:00
committed by qsm-odoo
parent 79c9f0a7a5
commit aaeef14903
12 changed files with 77 additions and 14 deletions
+13
View File
@@ -50,6 +50,18 @@ class QWeb(models.AbstractModel):
div = u'<div name="%s" data-oe-type="snippet" data-oe-thumbnail="%s">' % (escape(ir_qweb.unicodifier(name)), escape(ir_qweb.unicodifier(thumbnail)))
return [self._append(ast.Str(div))] + self._compile_node(el, options) + [self._append(ast.Str(u'</div>'))]
def _compile_directive_install(self, el, options):
if self.user_has_groups('base.group_system'):
module = self.env['ir.module.module'].search([('name', '=', el.attrib.get('t-install'))])
if not module or module.state == 'installed':
return []
name = el.attrib.get('string') or 'Snippet'
thumbnail = el.attrib.pop('t-thumbnail', 'oe-thumbnail')
div = u'<div name="%s" data-oe-type="snippet" data-module-id="%s" data-oe-thumbnail="%s"><section/></div>' % (escape(ir_qweb.unicodifier(name)), module.id, escape(ir_qweb.unicodifier(thumbnail)))
return [self._append(ast.Str(div))]
else:
return []
def _compile_directive_tag(self, el, options):
if el.get('t-placeholder'):
el.set('t-att-placeholder', el.attrib.pop('t-placeholder'))
@@ -60,6 +72,7 @@ class QWeb(models.AbstractModel):
def _directives_eval_order(self):
directives = super(QWeb, self)._directives_eval_order()
directives.insert(directives.index('call'), 'snippet')
directives.insert(directives.index('call'), 'install')
return directives
@@ -251,12 +251,25 @@ data.Class = Widget.extend({
$div.find('.oe_snippet_thumbnail_img').css('background-image', 'url(' + thumbnail + ')');
}
// end
var moduleID = $snippet.data('moduleId');
if (moduleID) {
$snippet.addClass('o_snippet_install');
var $installBtn = $('<a/>', {
class: 'btn btn-primary btn-sm o_install_btn',
target: '_blank',
href: '/web#id=' + moduleID + '&view_type=form&model=ir.module.module&action=base.open_module_tree',
text: _t("Install"),
});
$div.append($installBtn);
}
}
if (!$snippet.data("selector")) {
$("> *:not(.oe_snippet_thumbnail)", this).addClass('oe_snippet_body');
}
number++;
});
})
.not('[data-module-id]');
// hide scroll if no snippets defined
if (!number) {
@@ -86,6 +86,8 @@ html[lang] > body.editor_enable [data-oe-translation-state] {
// SNIPPET PANEL
#oe_snippets {
.o-w-preserve-btn();
.o-flex-display();
.o-flex-flow(column, nowrap);
.o-position-absolute(0, auto, 0, -@o-we-sidebar-width);
@@ -173,6 +175,19 @@ html[lang] > body.editor_enable [data-oe-translation-state] {
}
}
&.o_snippet_install {
.oe_snippet_thumbnail_img {
opacity: 0.5;
}
.btn.o_install_btn {
display: none;
.o-position-absolute(16px, 4px, auto, 4px);
}
&:hover .btn.o_install_btn {
display: block;
}
}
&:nth-child(2n+1) {
clear: left;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

+11
View File
@@ -732,6 +732,17 @@
</xpath>
</template>
<template id="external_snippets" inherit_id="website.snippets" priority="8">
<xpath expr="//div[@id='snippet_feature']//t[@t-snippet][last()]" position="after">
<t t-install="website_twitter" string="Twitter Scroller" t-thumbnail="/website/static/src/img/blocks/twitter_scroll.png"/>
</xpath>
<xpath expr="//div[@id='snippet_content']//t[@t-snippet][last()]" position="after">
<t t-install="website_event" string="Local Events" t-thumbnail="/website/static/src/img/blocks/block_local_event.png"/>
<t t-install="website_mail_channel" string="Discussion Group" t-thumbnail="/website/static/src/img/blocks/button_channel_subscribe.png"/>
<t t-install="mass_mailing" string="Newsletter" t-thumbnail="/website/static/src/img/blocks/newsletter_subscribe_form.png"/>
</xpath>
</template>
<template id="snippet_options">
<t t-call="web_editor.snippet_options"/>
@@ -624,9 +624,13 @@
</t>
</template>
<!-- External snippets -->
<template id="remove_external_snippets" inherit_id="website.external_snippets">
<xpath expr="//t[@t-install='website_event']" position="replace"/>
</template>
<!-- Snippets -->
<template id="country_events" name="Country Events" inherit_id="website.snippets">
<xpath expr="//div[@id='snippet_content']/div[@class='o_panel_body']" position="inside">
<xpath expr="//div[@id='snippet_content']//t[@t-snippet][last()]" position="after">
<div>
<div class="oe_snippet_thumbnail">
<div style="background: white;box-shadow:none;-webkit-box-shadow:none;" class="oe_snippet_thumbnail_img" >
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="subscribe" inherit_id="website.snippets" name="Snippet Subscribe">
<template id="remove_external_snippets" inherit_id="website.external_snippets">
<xpath expr="//t[@t-install='website_mail_channel']" position="replace"/>
</template>
<xpath expr="//div[@id='snippet_content']/div[@class='o_panel_body']" position="inside">
<template id="subscribe" inherit_id="website.snippets" name="Snippet Subscribe">
<xpath expr="//div[@id='snippet_content']//t[@t-snippet][last()]" position="after">
<div>
<div class="oe_snippet_thumbnail">
<img class="oe_snippet_thumbnail_img" src="/website_mail_channel/static/src/img/blocks/button_channel_subscribe.png"/>
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/button_channel_subscribe.png"/>
<span class="oe_snippet_thumbnail_title">Discussion Group</span>
</div>
@@ -32,9 +35,7 @@
<p class="js_mg_confirmation hidden well well-sm">
a confirmation email has been sent.
</p>
</div>
</div>
</xpath>
@@ -1,13 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="remove_external_snippets" inherit_id="website.external_snippets">
<xpath expr="//t[@t-install='mass_mailing']" position="replace"/>
</template>
<template id="snippets" inherit_id="website.snippets">
<xpath expr="//div[@id='snippet_feature']/div[@class='o_panel_body']" position="inside">
<xpath expr="//div[@id='snippet_feature']//t[@t-snippet][last()]" position="after">
<t groups="website_mass_mailing.group_website_popup_on_exit">
<t t-snippet="website_mass_mailing.s_newsletter_subscribe_popup" t-thumbnail="/website_mass_mailing/static/src/img/blocks/newsletter_subscribe_popup.png"/>
</t>
</xpath>
<xpath expr="//div[@id='snippet_content']/div[@class='o_panel_body']" position="inside">
<t t-snippet="website_mass_mailing.s_newsletter_subscribe_form" t-thumbnail="/website_mass_mailing/static/src/img/blocks/newsletter_subscribe_form.png"/>
<xpath expr="//div[@id='snippet_content']//t[@t-snippet][last()]" position="after">
<t t-snippet="website_mass_mailing.s_newsletter_subscribe_form" t-thumbnail="/website/static/src/img/blocks/newsletter_subscribe_form.png"/>
</xpath>
</template>
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="remove_external_snippets" inherit_id="website.external_snippets">
<xpath expr="//t[@t-install='website_twitter']" position="replace"/>
</template>
<template id="website_twitter_snippet" inherit_id="website.snippets" name="Twitter snippet">
<xpath expr="//div[@id='snippet_feature']/div[@class='o_panel_body']" position="inside">
<xpath expr="//div[@id='snippet_feature']//t[@t-snippet][last()]" position="after">
<div>
<div class="oe_snippet_thumbnail">
<img class="oe_snippet_thumbnail_img" src="/website_twitter/static/src/img/twitter_scroll.png"/>
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/twitter_scroll.png"/>
<span class="oe_snippet_thumbnail_title">Twitter Scroller</span>
</div>
<section class="oe_snippet_body twitter" data-screen-name="OpenERP" data-limit="15">
@@ -33,5 +35,4 @@
<script type="text/javascript" src="/website_twitter/static/src/js/website.twitter.editor.js"/>
</xpath>
</template>
</odoo>