From 8c25a35cc6fc5380efa52ea0ec737883b63703e3 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 26 Sep 2013 15:17:08 +0200 Subject: [PATCH] [FIX] Save translations and t-fields bzr revid: fme@openerp.com-20130926131708-16xmpbrx0vxlgbtw --- addons/website/static/src/js/website.editor.js | 2 +- .../website/static/src/js/website.translator.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index 41280199e45..8b15422b90d 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -282,7 +282,7 @@ }); }).get(); return $.when.apply(null, defs).then(function () { - window.location.href = window.location.href.replace(/unable_editor(=[^&]*)?|#.*/g, ''); + website.reload(); }); }, /** diff --git a/addons/website/static/src/js/website.translator.js b/addons/website/static/src/js/website.translator.js index 087e5c9f543..14821af3072 100644 --- a/addons/website/static/src/js/website.translator.js +++ b/addons/website/static/src/js/website.translator.js @@ -8,6 +8,7 @@ website.EditorBar.include({ start: function () { var self = this; + this.initial_content = {}; return this._super.apply(this, arguments).then(function () { self.$('button[data-action=edit]').text("Translate"); self.$('[data-action=snippet]').hide(); @@ -70,12 +71,15 @@ if (ev.type == 'paste') { self.sanitizeNode($node[0]); } - if ($node.data('initial_content') !== $node.text()) { + if (self.getInitialContent($node[0]) !== $node.text()) { $node.addClass('oe_dirty').removeClass('oe_translatable_todo'); } }, 0); }); }, + getInitialContent: function (node) { + return this.initial_content[node.attributes['data-oe-nodeid'].value]; + }, sanitizeNode: function (node) { node.text(node.text()); }, @@ -99,9 +103,13 @@ node.className += ' oe_translatable_todo'; } node.contentEditable = true; - $(node).data('initial_content', content); + var nid = _.uniqueId(); + $(node).attr('data-oe-nodeid', nid); + this.initial_content[nid] = content; }, save: function () { + var self = this; + var mysuper = this._super; var trans = {}; // this._super.apply(this, arguments); $('.oe_translatable_text.oe_dirty').each(function () { @@ -111,7 +119,7 @@ trans[data.oeTranslationViewId] = []; } trans[data.oeTranslationViewId].push({ - initial_content: data.initial_content, + initial_content: self.getInitialContent(this), new_content: $node.text(), translation_id: data.oeTranslationId || null }); @@ -120,7 +128,7 @@ 'data': trans, 'lang': website.get_context()['lang'], }).then(function () { - website.reload(); + mysuper.call(self); }).fail(function () { // TODO: bootstrap alert with error message alert("Could not save translation");