From 4c3afa60788766edbc1e3aad7da56691df0f2189 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Mon, 23 Sep 2013 15:13:01 +0200 Subject: [PATCH] [IMP] Activate translation when language is not the default one bzr revid: fme@openerp.com-20130923131301-mjr0tmth2z1qamfa --- addons/website/controllers/main.py | 2 +- .../static/src/js/website.translator.js | 57 ++++++++++--------- addons/website/static/src/xml/website.xml | 1 - addons/website/views/views.xml | 20 +++++-- 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 8c3814735c7..3aa97b8f3f3 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -35,7 +35,7 @@ PIL_MIME_MAPPING = {'PNG': 'image/png', 'JPEG': 'image/jpeg', 'GIF': 'image/gif' # Completely arbitrary limits MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT = IMAGE_LIMITS = (1024, 768) class Website(openerp.addons.web.controllers.main.Home): - @website.route('/', type='http', auth="admin") + @website.route('/', type='http', auth="admin", multilang=True) def index(self, **kw): return self.page("website.homepage") diff --git a/addons/website/static/src/js/website.translator.js b/addons/website/static/src/js/website.translator.js index ac4c6d298d2..a4a5344aa85 100644 --- a/addons/website/static/src/js/website.translator.js +++ b/addons/website/static/src/js/website.translator.js @@ -5,36 +5,36 @@ website.templates.push('/website/static/src/xml/website.translator.xml'); website.EditorBar.include({ - events: _.extend({}, website.EditorBar.prototype.events, { - 'click a[data-action=js_website_translator]': function (ev) { - var self = this; - ev.preventDefault(); - if (!localStorage['website_translator_nodialog']) { - var dialog = new website.TranslatorDialog(); - dialog.appendTo($(document.body)); - dialog.on('activate', this, function () { - dialog.$el.modal('hide'); - this.translateMode(); - }); - } else { - this.translateMode(); - } - }, - }), - temporaryHack: function() { - // TODO: refactor once xmo's feature branch is merged - debugger - this.$buttons.edit.prop('disabled', true); + start: function () { + var self = this; + return this._super.apply(this, arguments).then(function () { + // TODO: refactor once xmo's feature branch is merged + // and make t-field's work as well as text translation + self.$('button[data-action=edit]').text("Translate"); + self.$('[data-action=snippet]').hide(); + self.$('#customize-menu-button').hide(); + }); + }, + edit: function () { + var self = this; + if (!localStorage['website_translator_nodialog']) { + var dialog = new website.TranslatorDialog(); + dialog.appendTo($(document.body)); + dialog.on('activate', this, function () { + dialog.$el.modal('hide'); + this.translate(); + }); + } else { + this.translate(); + } + }, + translate: function () { + var self = this; + // this.edit(); this.$('#website-top-view').hide(); this.$('#website-top-edit').show(); $('.css_non_editable_mode_hidden').removeClass("css_non_editable_mode_hidden"); - this.$el.find('[data-action=snippet]').hide(); - this.save = this.saveTranslations; - }, - translateMode: function () { - var self = this; - this.temporaryHack(); - // this.edit(); -- Will need a translation mode + this.translations = null; openerp.jsonRpc('/website/get_view_translations', 'call', { 'xml_id': $(document.documentElement).data('view-xmlid'), @@ -88,8 +88,9 @@ node.contentEditable = true; $(node).data('initial_content', node.childNodes[0].data); }, - saveTranslations: function () { + save: function () { var trans = {}; + // this._super.apply(this, arguments); $('.oe_translatable_text.oe_dirty').each(function () { var $node = $(this); var text = $node.text(); diff --git a/addons/website/static/src/xml/website.xml b/addons/website/static/src/xml/website.xml index 04c2403eda2..c2f7abe6ed2 100644 --- a/addons/website/static/src/xml/website.xml +++ b/addons/website/static/src/xml/website.xml @@ -22,7 +22,6 @@
  • Promote
  • -
  • Translate