From 6610d05549e347fbb548e606fa66cfb113df9e67 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 24 Feb 2016 13:13:12 +0100 Subject: [REF] web_editor,website,mass_mailing: JS/XML update * Adapt DOM selectors * Refactore dialog XMLs to have odoo styling * New editor options (background-position, ...) * Various improvements --- addons/website/static/src/js/website.editor.js | 113 ++++++------------------- 1 file changed, 25 insertions(+), 88 deletions(-) (limited to 'addons/website/static/src/js/website.editor.js') diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index a670f53bef1..b40c2deac9f 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -23,47 +23,16 @@ website.TopBar.include({ }, start: function () { var self = this; - $("#wrapwrap").on('click', '.o_editable, [data-oe-model]', function (event) { - var $this = $(event.srcElement); - var tag = $this[0] && $this[0].tagName.toLowerCase(); - if (!(tag === 'a' || tag === "button") && !$this.parents("a, button").length) { - self.$('[data-action="edit"]').parent().effect('bounce', {distance: 18, times: 5}, 250); - } - }); - $("#wrapwrap").find("[data-oe-model] .oe_structure.oe_empty, [data-oe-model].oe_structure.oe_empty, [data-oe-type=html]:empty") .filter(".oe_not_editable") .filter(".oe_no_empty") - .addClass("oe_empty") - .attr("data-oe-placeholder", _t("Press The Top-Left Edit Button")); + .addClass("oe_empty"); if (location.search.indexOf("enable_editor") >= 0 && $('html').attr('lang') === "en_US") { this.$el.addClass('editing_mode'); } - self.init_components() - - self.resize() - $(window).on("resize", function(){ - self.resize() - }) - - return this._super(); - }, - init_components: function(){ - $(".switch").each(function(){ - var $el = $(this) - $el.on('click', function(){ - var $i = $el.find('.switch_input') - $el.toggleClass('checked') - if($i.prop("checked")){ - $i.prop("checked", false); - } else { - $i.prop("checked", true); - } - return false; - }) - }); + return this._super.apply(this, arguments); }, edit: function () { this.$('button[data-action=edit]').prop('disabled', true); @@ -71,31 +40,6 @@ website.TopBar.include({ editor.editor_bar = new editor.Class(this); editor.editor_bar.prependTo(document.body); }, - resize: function() { - var wW = $(window).width(), - $sys = $('#oe_systray'), - $nav = $('#website_main_menu_navbar'); - - // Adapt dropdown-menu orientation to fit screen size - $sys.find('> li.wb_dropdown, >li.dropdown').each(function(){ - var $el = $(this), - offset = $el.offset(), - width = $el.width(); - var centerX = offset.left + width / 2; - if(centerX > wW/2){ - $el.addClass('right') - } else { - $el.removeClass('right') - } - }) - // Resize oe_systray - var totalWidth = null; - $nav.find('>*').not($sys).each(function(index) { - totalWidth += parseInt($(this).outerWidth() , 10); - }); - $sys.width((wW - totalWidth)-50).addClass('ready') - - } }); /* ----- Customize Template ---- */ @@ -105,7 +49,7 @@ website.TopBarCustomize = Widget.extend({ 'mousedown a.dropdown-toggle': 'load_menu', 'click ul a[data-view-id]': 'do_customize', }, - start: function() { + start: function () { var self = this; this.$menu = self.$el.find('ul'); this.view_name = $(document.documentElement).data('view-xmlid'); @@ -119,43 +63,36 @@ website.TopBarCustomize = Widget.extend({ if(this.loaded) { return; } - ajax.jsonRpc('/website/customize_template_get', 'call', { 'key': this.view_name }).then( - function(result) { - _.each(result, function (item) { - if (item.key === "website.debugger" && !window.location.search.match(/[&?]debug(&|$)/)) return; - if (item.header) { - self.$menu.append(''); - } else { - self.$menu.append(_.str.sprintf( - '
  • '+ - '' + - '' + - '' + - ' %s'+ - '' + - '
  • ', - item.id, item.active ? 'checked' : '', item.id, item.id, item.active ? 'true' : 'false', item.name)); - } - }); - self.loaded = true; - } - ); + ajax.jsonRpc('/website/customize_template_get', 'call', { + key: this.view_name, + }).then(function (result) { + _.each(result, function (item) { + if (item.key === "website.debugger" && !window.location.search.match(/[&?]debug(&|$)/)) return; + if (item.header) { + self.$menu.append(''); + } else { + var $li = $('
  • ', {role: 'presentation'}) + .append($('', {href: '#', 'data-view-id': item.id, role: 'menuitem'}) + .append(qweb.render('web_editor.components.switch', {id: 'switch-' + item.id, label: item.name}))); + $li.find('input').prop('checked', !!item.active); + self.$menu.append($li); + } + }); + self.loaded = true; + }); }, - do_customize: function (event) { - var view_id = $(event.currentTarget).data('view-id'); - $('#website_loading').addClass('active') + do_customize: function (e) { + e.preventDefault(); + var view_id = $(e.currentTarget).data('view-id'); return ajax.jsonRpc('/web/dataset/call_kw', 'call', { model: 'ir.ui.view', method: 'toggle', args: [], kwargs: { ids: [parseInt(view_id, 10)], - context: base.get_context() + context: base.get_context(), } - }).then( function() { + }).then(function () { window.location.reload(); }); }, -- cgit v1.2.3