From aaeef14903d4a3f359fcd6dd61a4f8ee41c947a4 Mon Sep 17 00:00:00 2001 From: Kishan Gajjar Date: Tue, 21 Mar 2017 11:48:02 +0530 Subject: [PATCH] [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. --- addons/web_editor/models/ir_qweb.py | 13 +++++++++++++ .../web_editor/static/src/js/snippets.editor.js | 15 ++++++++++++++- .../static/src/less/web_editor.ui.less | 15 +++++++++++++++ .../static/src/img/blocks/block_local_event.png | Bin 0 -> 514 bytes .../src/img/blocks/button_channel_subscribe.png | Bin .../src/img/blocks/newsletter_subscribe_form.png | Bin .../static/src/img/blocks}/twitter_scroll.png | Bin addons/website/views/snippets.xml | 11 +++++++++++ addons/website_event/views/event_templates.xml | 6 +++++- addons/website_mail_channel/views/snippets.xml | 11 ++++++----- .../views/snippets_templates.xml | 11 ++++++++--- .../views/website_twitter_snippet_templates.xml | 9 +++++---- 12 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 addons/website/static/src/img/blocks/block_local_event.png rename addons/{website_mail_channel => website}/static/src/img/blocks/button_channel_subscribe.png (100%) rename addons/{website_mass_mailing => website}/static/src/img/blocks/newsletter_subscribe_form.png (100%) rename addons/{website_twitter/static/src/img => website/static/src/img/blocks}/twitter_scroll.png (100%) diff --git a/addons/web_editor/models/ir_qweb.py b/addons/web_editor/models/ir_qweb.py index 71445d4919e..fcab2902a3b 100644 --- a/addons/web_editor/models/ir_qweb.py +++ b/addons/web_editor/models/ir_qweb.py @@ -50,6 +50,18 @@ class QWeb(models.AbstractModel): div = u'
' % (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'
'))] + 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'
' % (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 diff --git a/addons/web_editor/static/src/js/snippets.editor.js b/addons/web_editor/static/src/js/snippets.editor.js index e11e3205815..d0b6394ecd9 100644 --- a/addons/web_editor/static/src/js/snippets.editor.js +++ b/addons/web_editor/static/src/js/snippets.editor.js @@ -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 = $('', { + 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) { diff --git a/addons/web_editor/static/src/less/web_editor.ui.less b/addons/web_editor/static/src/less/web_editor.ui.less index 4f1eb7dc4be..f83a73984c4 100644 --- a/addons/web_editor/static/src/less/web_editor.ui.less +++ b/addons/web_editor/static/src/less/web_editor.ui.less @@ -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; } diff --git a/addons/website/static/src/img/blocks/block_local_event.png b/addons/website/static/src/img/blocks/block_local_event.png new file mode 100644 index 0000000000000000000000000000000000000000..a620d532344d175bfe48563d4265a55844215de2 GIT binary patch literal 514 zcmV+d0{#7oP)f^YioH-`~N( z!IzhpkdTmtg@xGI*wE0>$jHdPzP_)oucxP{jg5`%?d{gq*2Trew6wIWtgMNNiSO_4 z>+9>>+}y&#!s+Shk{pXP@#UmrTnih0tB?dpR!E+GvX8N*@uocg?UGz3A7M*eTws9it z$lITx-7>(k0J^d(Sh9N9RoK@owwgV~66*};hKse_s=fmpEKkeRV)i~l)VOB3R&Pw3 z2xl@E*rau>13r-6_3=5b`y_WpF1h5AOD?(OlKV6HfGdRF_3v^$*S9wefSqhds(zL4 zV7z;D-mTW_dl&Yo&K$*{7>*+P{}7*y%ssZlyKdv?Ox>8A@Q z(z|TUk2?mM7Rw|}E+?qdyZ1#dx#W`j4_y`_sw=!;Us>rD<7&|iX8-^I07*qoM6N<$ Ef*c + + + +