From d137b0aec0ca34d152e3d81dffe2c30bc891119a Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 10 Jul 2014 14:01:03 +0200 Subject: [PATCH] [ADD] Option to list asset bundles in templates editor --- addons/website/controllers/main.py | 5 +- addons/website/models/ir_ui_view.py | 11 ++-- addons/website/static/src/css/editor.css | 30 +++++------ addons/website/static/src/css/editor.sass | 4 ++ addons/website/static/src/js/website.ace.js | 50 +++++++++++-------- addons/website/static/src/xml/website.ace.xml | 3 ++ 6 files changed, 61 insertions(+), 42 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index fe86088fad0..89dbef0f230 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -203,10 +203,11 @@ class Website(openerp.addons.web.controllers.main.Home): return request.redirect(redirect) @http.route('/website/customize_template_get', type='json', auth='user', website=True) - def customize_template_get(self, xml_id, full=False): + def customize_template_get(self, xml_id, full=False, bundles=False): """ Lists the templates customizing ``xml_id``. By default, only returns optional templates (which can be toggled on and off), if ``full=True`` returns all templates customizing ``xml_id`` + ``bundles=True`` returns also the asset bundles """ imd = request.registry['ir.model.data'] view_model, view_theme_id = imd.get_object_reference( @@ -217,7 +218,7 @@ class Website(openerp.addons.web.controllers.main.Home): user_groups = set(user.groups_id) views = request.registry["ir.ui.view"]\ - ._views_get(request.cr, request.uid, xml_id, context=request.context) + ._views_get(request.cr, request.uid, xml_id, bundles=bundles, context=request.context) done = set() result = [] for v in views: diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index ad3597b7309..61de01c4b96 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -37,7 +37,7 @@ class view(osv.osv): # Returns all views (called and inherited) related to a view # Used by translation mechanism, SEO and optional templates - def _views_get(self, cr, uid, view_id, options=True, context=None, root=True): + def _views_get(self, cr, uid, view_id, options=True, bundles=False, context=None, root=True): """ For a given view ``view_id``, should return: * the view itself @@ -57,13 +57,16 @@ class view(osv.osv): result = [view] node = etree.fromstring(view.arch) - for child in node.xpath("//t[@t-call]"): + xpath = "//t[@t-call]" + if bundles: + xpath += "| //t[@t-call-assets]" + for child in node.xpath(xpath): try: - called_view = self._view_obj(cr, uid, child.get('t-call'), context=context) + called_view = self._view_obj(cr, uid, child.get('t-call', child.get('t-call-assets')), context=context) except ValueError: continue if called_view not in result: - result += self._views_get(cr, uid, called_view, options=options, context=context) + result += self._views_get(cr, uid, called_view, options=options, bundles=bundles, context=context) extensions = view.inherit_children_ids if not options: diff --git a/addons/website/static/src/css/editor.css b/addons/website/static/src/css/editor.css index d38f26fd332..ac7ddbbccb5 100644 --- a/addons/website/static/src/css/editor.css +++ b/addons/website/static/src/css/editor.css @@ -23,8 +23,8 @@ .navbar.navbar-inverse .cke_top { background: transparent; border: none; - -webkit-box-shadow: none; -moz-box-shadow: none; + -webkit-box-shadow: none; box-shadow: none; -ms-filter: "alpha(opacity=50)"; } @@ -57,13 +57,11 @@ padding: 2px; margin: 0; z-index: 20000; - background: #414141, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #646060), color-stop(100%, #262626)); - background: #414141, -webkit-linear-gradient(#646060, #262626); background: #414141, -moz-linear-gradient(#646060, #262626); - background: #414141, -o-linear-gradient(#646060, #262626); + background: #414141, -webkit-linear-gradient(#646060, #262626); background: #414141, linear-gradient(#646060, #262626); - -webkit-box-sizing: border-box; -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; box-sizing: border-box; } .oe_website_editorbar li { @@ -225,8 +223,9 @@ ul.oe_menu_editor .disclose { /* ---- RTE ---- {{{ */ .oe_editable .btn, .btn.oe_editable { - -webkit-user-select: auto; -moz-user-select: auto; + -ms-user-select: auto; + -webkit-user-select: auto; user-select: auto; cursor: text !important; } @@ -384,10 +383,8 @@ ul.oe_menu_editor .disclose { height: 660px; background-color: black; border: 2px solid #1c1f1f; - -webkit-border-radius: 10px; -moz-border-radius: 10px; - -ms-border-radius: 10px; - -o-border-radius: 10px; + -webkit-border-radius: 10px; border-radius: 10px; margin: auto; top: 0; @@ -410,13 +407,13 @@ ul.oe_menu_editor .disclose { color: #1c1f1f; } .oe_mobile_preview.modal .modal-content .modal-header .close { - color: lightgrey; - filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); + color: lightgray; + filter: progid:DXImageTransform.Microsoft.Alpha(enabled=false); opacity: 1; } .oe_mobile_preview.modal .modal-content .modal-header .close:hover { color: #e00101; - filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); + filter: progid:DXImageTransform.Microsoft.Alpha(enabled=false); opacity: 1; } .oe_mobile_preview.modal .modal-content .modal-body { @@ -447,10 +444,8 @@ ul.oe_menu_editor .disclose { } .oe_seo_configuration .oe_seo_keyword { padding: 0.2em 0.4em 0.2em 0.5em; - -webkit-border-radius: 0.4em; -moz-border-radius: 0.4em; - -ms-border-radius: 0.4em; - -o-border-radius: 0.4em; + -webkit-border-radius: 0.4em; border-radius: 0.4em; } .oe_seo_configuration li.oe_seo_preview_g { @@ -554,3 +549,8 @@ ul.oe_menu_editor .disclose { filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0); opacity: 0; } + +.oe_include_bundles { + font-weight: normal; + padding: 0 8px; +} diff --git a/addons/website/static/src/css/editor.sass b/addons/website/static/src/css/editor.sass index b40907bc66c..802b6299545 100644 --- a/addons/website/static/src/css/editor.sass +++ b/addons/website/static/src/css/editor.sass @@ -477,6 +477,10 @@ $infobar_height: 20px z-index: -1000 +opacity(0) +.oe_include_bundles + font-weight: normal + padding: 0 8px + // }}} // vim:tabstop=4:shiftwidth=4:softtabstop=4:fdm=marker: diff --git a/addons/website/static/src/js/website.ace.js b/addons/website/static/src/js/website.ace.js index 1fb0b93c830..03c6747ddd1 100644 --- a/addons/website/static/src/js/website.ace.js +++ b/addons/website/static/src/js/website.ace.js @@ -70,6 +70,7 @@ template: 'website.ace_view_editor', events: { 'change #ace-view-list': 'displaySelectedView', + 'click .js_include_bundles': 'loadTemplates', 'click button[data-action=save]': 'saveViews', 'click button[data-action=format]': 'formatXml', 'click button[data-action=close]': 'close', @@ -83,26 +84,7 @@ var self = this; self.aceEditor = ace.edit(self.$('#ace-view-editor')[0]); self.aceEditor.setTheme("ace/theme/monokai"); - var viewId = $(document.documentElement).data('view-xmlid'); - openerp.jsonRpc('/website/customize_template_get', 'call', { - 'xml_id': viewId, - 'full': true, - }).then(function (views) { - self.loadViews.call(self, views); - self.open.call(self); - var curentHash = window.location.hash; - var indexOfView = curentHash.indexOf("?view="); - if (indexOfView >= 0) { - var viewId = parseInt(curentHash.substring(indexOfView + 6, curentHash.length), 10); - self.$('#ace-view-list').val(viewId).change(); - } else { - if (views.length >= 2) { - var mainTemplate = views[1]; - self.$('#ace-view-list').val(mainTemplate.id).trigger('change'); - } - window.location.hash = hash; - } - }); + self.loadTemplates(); var $editor = self.$('.ace_editor'); function resizeEditor (target) { @@ -150,8 +132,34 @@ resizeEditor(readEditorWidth()); resizeEditorHeight(this.getParent().$el.outerHeight()+2); }, + loadTemplates: function () { + var self = this; + var args = { + xml_id: $(document.documentElement).data('view-xmlid'), + full: true, + bundles: this.$('.js_include_bundles')[0].checked + }; + return openerp + .jsonRpc('/website/customize_template_get', 'call', args) + .then(function (views) { + self.loadViews.call(self, views); + self.open.call(self); + var curentHash = window.location.hash; + var indexOfView = curentHash.indexOf("?view="); + if (indexOfView >= 0) { + var viewId = parseInt(curentHash.substring(indexOfView + 6, curentHash.length), 10); + self.$('#ace-view-list').val(viewId).change(); + } else { + if (views.length >= 2) { + var mainTemplate = views[1]; + self.$('#ace-view-list').val(mainTemplate.id).trigger('change'); + } + window.location.hash = hash; + } + }); + }, loadViews: function (views) { - var $viewList = this.$('#ace-view-list'); + var $viewList = this.$('#ace-view-list').empty(); _(this.buildViewGraph(views)).each(function (view) { if (!view.id) { return; } diff --git a/addons/website/static/src/xml/website.ace.xml b/addons/website/static/src/xml/website.ace.xml index 23f3ca0c2e4..28b9dd83192 100644 --- a/addons/website/static/src/xml/website.ace.xml +++ b/addons/website/static/src/xml/website.ace.xml @@ -6,6 +6,9 @@ +