Skip to content

Commit

Permalink
[IMP] web_editor: add enterprise snippet option
Browse files Browse the repository at this point in the history
  • Loading branch information
dep-odoo committed Aug 18, 2017
1 parent 2f3f7f2 commit b68cd5f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 23 deletions.
1 change: 1 addition & 0 deletions addons/web/__manifest__.py
Expand Up @@ -24,6 +24,7 @@
"static/src/xml/rainbow_man.xml",
"static/src/xml/report.xml",
"static/src/xml/web_calendar.xml",
"static/src/xml/enterprise_upgrade.xml"
],
'bootstrap': True, # load translations for login screen
}
19 changes: 0 additions & 19 deletions addons/web/static/src/xml/base.xml
Expand Up @@ -1375,23 +1375,4 @@
</li>
</t>

<t t-name="EnterpriseUpgrade">
<div class="row">
<div class="col-xs-6">
Get this feature and much more with Odoo Enterprise!
<ul class="list-unstyled">
<li><i class="fa fa-check"></i> Access to all Enterprise Apps</li>
<li><i class="fa fa-check"></i> New design</li>
<li><i class="fa fa-check"></i> Mobile support</li>
<li><i class="fa fa-check"></i> Upgrade to future versions</li>
<li><i class="fa fa-check"></i> Bugfixes guarantee</li>
<li><a href="http://www.odoo.com/editions" target="_blank"><i class="fa fa-plus"></i> And more</a></li>
</ul>
</div>
<div class="col-xs-6">
<img class="img-responsive" t-att-src='_s + "/web/static/src/img/enterprise_upgrade.jpg"' draggable="false"/>
</div>
</div>
</t>

</templates>
23 changes: 23 additions & 0 deletions addons/web/static/src/xml/enterprise_upgrade.xml
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">

<t t-name="EnterpriseUpgrade">
<div class="row">
<div class="col-xs-6">
Get this feature and much more with Odoo Enterprise!
<ul class="list-unstyled">
<li><i class="fa fa-check"></i> Access to all Enterprise Apps</li>
<li><i class="fa fa-check"></i> New design</li>
<li><i class="fa fa-check"></i> Mobile support</li>
<li><i class="fa fa-check"></i> Upgrade to future versions</li>
<li><i class="fa fa-check"></i> Bugfixes guarantee</li>
<li><a href="http://www.odoo.com/editions" target="_blank"><i class="fa fa-plus"></i> And more</a></li>
</ul>
</div>
<div class="col-xs-6">
<img class="img-responsive" t-att-src='_s + "/web/static/src/img/enterprise_upgrade.jpg"' draggable="false"/>
</div>
</div>
</t>

</templates>
9 changes: 6 additions & 3 deletions addons/web_editor/models/ir_qweb.py
Expand Up @@ -53,11 +53,14 @@ def _compile_directive_snippet(self, el, options):
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)))
if not module and el.attrib.get('ent'):
div = u'<div name="%s" data-oe-type="snippet" data-oe-ent="true" data-oe-thumbnail="%s"><section/></div>' % (escape(ir_qweb.unicodifier(name)), escape(ir_qweb.unicodifier(thumbnail)))
else:
if not module or module.state == 'installed':
return []
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 []
Expand Down
41 changes: 40 additions & 1 deletion addons/web_editor/static/src/js/editor/snippets.editor.js
Expand Up @@ -3,10 +3,12 @@ odoo.define('web_editor.snippet.editor', function (require) {

var core = require('web.core');
var dom = require('web.dom');
var Dialog = require('web.Dialog');
var Widget = require('web.Widget');
var options = require('web_editor.snippets.options');

var _t = core._t;
var qweb = core.qweb;

var globalSelector = {
closest: function () { return $(); },
Expand Down Expand Up @@ -500,6 +502,7 @@ var SnippetEditor = Widget.extend({
var SnippetsMenu = Widget.extend({
id: 'oe_snippets',
activeSnippets: [],
xmlDependencies: ['/web/static/src/xml/enterprise_upgrade.xml'],
custom_events: {
activate_insertion_zones: '_onActivateInsertionZones',
call_for_each_child_snippet: '_onCallForEachChildSnippet',
Expand Down Expand Up @@ -1016,6 +1019,42 @@ var SnippetsMenu = Widget.extend({
));
$snippet.prepend($thumbnail);


var isEntSnippet = $snippet.data('oe-ent');
if (isEntSnippet) {
$snippet.addClass('o_snippet_install');
var $installBtn = $('<a/>', {
class: 'btn btn-primary btn-sm o_install_btn',
click: function(){
var message = $(qweb.render('EnterpriseUpgrade'));
var buttons = [
{
text: _t("Upgrade now"),
classes: 'btn-primary',
click: function(){
window.open("https://www.odoo.com/odoo-enterprise/upgrade", "_blank");
},
close: true,
},
{
text: _t("Cancel"),
close: true,
},
];
new Dialog(this, {
size: 'medium',
buttons: buttons,
$content: $('<div>', {
html: message,
}),
title: _t("Odoo Enterprise"),
}).open();
},
text: _t("Install"),
});
$thumbnail.append($installBtn);
}

// Create the install button (t-install feature) if necessary
var moduleID = $snippet.data('moduleId');
if (moduleID) {
Expand All @@ -1029,7 +1068,7 @@ var SnippetsMenu = Widget.extend({
$thumbnail.append($installBtn);
}
})
.not('[data-module-id]');
.not('[data-module-id],[data-oe-ent]');

// Hide scroll if no snippets defined
if (!this.$snippets.length) {
Expand Down
Binary file added addons/website/static/src/img/s_website_form.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions addons/website/views/snippets.xml
Expand Up @@ -735,6 +735,7 @@
<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"/>
<t t-install="website_form_editor" ent="True" string="Form Builder" t-thumbnail="/website/static/src/img/s_website_form.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"/>
Expand Down

0 comments on commit b68cd5f

Please sign in to comment.