summaryrefslogtreecommitdiff
path: root/addons/web_editor
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-07-07 14:30:30 +0200
committerChristophe Simonis <chs@odoo.com>2017-07-07 14:30:30 +0200
commitbf51fe55a149fb642a410f579dc4b6dcbd794eac (patch)
treef4f208f06094bcef6541fd1fc034e0265de4ad21 /addons/web_editor
parentbf32940142beb879211b7034bb77a7845c9d0555 (diff)
parent0f2b2c4e2b99df8d68456016a4bea86e26c1c80e (diff)
[MERGE] forward port branch saas-16 up to 0f2b2c4e2b9
Diffstat (limited to 'addons/web_editor')
-rw-r--r--addons/web_editor/models/ir_http.py2
-rw-r--r--addons/web_editor/models/ir_ui_view.py2
-rw-r--r--addons/web_editor/static/src/js/backend.js107
-rw-r--r--addons/web_editor/static/src/js/base.js2
-rw-r--r--addons/web_editor/static/src/less/web_editor.ui.less7
-rw-r--r--addons/web_editor/static/src/xml/backend.xml29
-rw-r--r--addons/web_editor/static/tests/web_editor_tests.js40
7 files changed, 97 insertions, 92 deletions
diff --git a/addons/web_editor/models/ir_http.py b/addons/web_editor/models/ir_http.py
index 04845688ea9..d6e2b2d5ee6 100644
--- a/addons/web_editor/models/ir_http.py
+++ b/addons/web_editor/models/ir_http.py
@@ -15,7 +15,7 @@ class IrHttp(models.AbstractModel):
context['editable'] = True
if 'edit_translations' in request.httprequest.args and 'edit_translations' not in context:
context['edit_translations'] = True
- if context.get('lang') != "en_US" and 'translatable' not in context:
+ if context.get('edit_translations') and 'translatable' not in context:
context['translatable'] = True
request.context = context
return super(IrHttp, cls)._dispatch()
diff --git a/addons/web_editor/models/ir_ui_view.py b/addons/web_editor/models/ir_ui_view.py
index 8c60e7923f2..7cf9e2f3a27 100644
--- a/addons/web_editor/models/ir_ui_view.py
+++ b/addons/web_editor/models/ir_ui_view.py
@@ -49,7 +49,7 @@ class IrUiView(models.Model):
if value is not None:
# TODO: batch writes?
- if self.get_default_lang_code() and field != 'arch' and not isinstance(Model._fields[field], fields.Html):
+ if not self.env.context.get('lang') and self.get_default_lang_code():
Model.browse(int(el.get('data-oe-id'))).with_context(lang=self.get_default_lang_code()).write({field: value})
else:
Model.browse(int(el.get('data-oe-id'))).write({field: value})
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js
index 34ca6c9f5d4..06053dd1cea 100644
--- a/addons/web_editor/static/src/js/backend.js
+++ b/addons/web_editor/static/src/js/backend.js
@@ -10,7 +10,10 @@ var field_registry = require('web.field_registry');
var transcoder = require('web_editor.transcoder');
+var TranslatableFieldMixin = basic_fields.TranslatableFieldMixin;
+
var QWeb = core.qweb;
+var _t = core._t;
/**
@@ -18,11 +21,8 @@ var QWeb = core.qweb;
* Intended to display HTML content. This widget uses the summernote editor
* improved by odoo.
*
- * FIXME: this field has a custom handling of the translation feature, which
- * hasn't been re-introduced yet (because this feature hasn't been introduced
- * yet in the fields in general)
*/
-var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({
+var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMixin, {
className: 'oe_form_field oe_form_field_html_text',
supportedFieldTypes: ['html'],
@@ -133,6 +133,7 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({
if (history) {
history.reset();
}
+ this.$('.note-toolbar').append(this._renderTranslateButton());
},
/**
* @override
@@ -187,6 +188,19 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({
}
return value;
},
+ /**
+ * @override
+ * @private
+ * @returns {jQueryElement}
+ */
+ _renderTranslateButton: function () {
+ if (_t.database.multi_lang && this.field.translate && this.res_id) {
+ return $(QWeb.render('web_editor.FieldTextHtml.button.translate', {widget: this}))
+ .on('click', this._onTranslate.bind(this));
+ }
+ return $();
+ },
+
});
var FieldTextHtml = AbstractField.extend({
@@ -196,6 +210,7 @@ var FieldTextHtml = AbstractField.extend({
start: function () {
var self = this;
+ this.loaded = false;
this.callback = _.uniqueId('FieldTextHtml_');
window.odoo[this.callback+"_editor"] = function (EditorBar) {
setTimeout(function () {
@@ -206,8 +221,7 @@ var FieldTextHtml = AbstractField.extend({
self.on_content_loaded();
};
window.odoo[this.callback+"_updown"] = null;
- window.odoo[this.callback+"_downup"] = function (value) {
- self._setValue(value);
+ window.odoo[this.callback+"_downup"] = function () {
self.resize();
};
@@ -233,8 +247,6 @@ var FieldTextHtml = AbstractField.extend({
this.old_initialize_content();
var def = this._super.apply(this, arguments);
- // this.$translate.remove();
- // this.$translate = $();
return def;
},
getDatarecord: function () {
@@ -261,18 +273,13 @@ var FieldTextHtml = AbstractField.extend({
if (this.nodeOptions.template) {
attr.template = this.nodeOptions.template;
}
- if (this. mode === "edit") {
+ if (this.mode === "edit") {
attr.enable_editor = 1;
}
- if (this.field.translate) {
- attr.translatable = 1;
- }
if (session.debug) {
attr.debug = session.debug;
}
- attr.lang = attr.enable_editor ? 'en_US' : this.getSession().user_context.lang;
-
for (k in _attr) {
attr[k] = _attr[k];
}
@@ -306,26 +313,10 @@ var FieldTextHtml = AbstractField.extend({
this.document = this.$iframe.contents()[0];
this.$body = $("body", this.document);
this.$content = this.$body.find("#editable_area");
- // this._toggle_label();
- this.lang = this.$iframe.attr('src').match(/[?&]lang=([^&]+)/);
- this.lang = this.lang ? this.lang[1] : session.user_context.lang;
- this._dirty_flag = false;
this.render();
- setTimeout(function () {
- self.trigger_up('perform_model_rpc', {
- model: 'res.lang',
- method: 'search_read',
- args: [
- [['code', '!=', 'en_US']],
- ["name", "code"]
- ],
- on_success: function (res) {
- self.languages = res;
- self.add_button();
- setTimeout(self.resize,0);
- }
- });
- }, 0);
+ this.add_button();
+ this.loaded = true;
+ setTimeout(self.resize, 0);
},
on_editor_loaded: function (EditorBar) {
var self = this;
@@ -341,19 +332,6 @@ var FieldTextHtml = AbstractField.extend({
var self = this;
var $to = this.$body.find("#web_editor-top-edit, #wrapwrap").first();
- $(QWeb.render('FieldTextHtml.translate', {'widget': this}))
- .appendTo($to)
- .on('change', 'select', function () {
- var lang = $(this).val();
- var edit = self. mode === "edit";
- var trans = lang !== 'en_US';
- self.$iframe.attr("src", self.get_url({
- 'edit_translations': edit && trans,
- 'enable_editor': edit && !trans,
- 'lang': lang
- }));
- });
-
$(QWeb.render('web_editor.FieldTextHtml.fullscreen'))
.appendTo($to)
.on('click', '.o_fullscreen', function () {
@@ -369,9 +347,6 @@ var FieldTextHtml = AbstractField.extend({
});
},
render: function () {
- if (this.lang !== session.user_context.lang || this.$iframe.attr('src').match(/[?&]edit_translations=1/)) {
- return;
- }
var value = (this.value || "").replace(/^<p[^>]*>(\s*|<br\/?>)<\/p>$/, '');
if (!this.$content) {
return;
@@ -392,24 +367,34 @@ var FieldTextHtml = AbstractField.extend({
has_no_value: function () {
return this.value === false || !this.$content.html() || !this.$content.html().match(/\S/);
},
- // FIXME: not sure what this is supposed to do that is still relevant now
- // commit_value: function () {
- // if (this.lang !== 'en_US' && this.$body.find('.o_dirty').length) {
- // this.internal_set_value( this.view.datarecord[this.name] );
- // this._dirty_flag = false;
- // return this.editor.save();
- // } else if (this._dirty_flag && this.editor && this.editor.buildingBlock) {
- // this.editor.buildingBlock.clean_for_save();
- // this.internal_set_value( this.$content.html() );
- // }
- // },
destroy: function () {
$(window).off('resize', this.resize);
delete window.odoo[this.callback+"_editor"];
delete window.odoo[this.callback+"_content"];
delete window.odoo[this.callback+"_updown"];
delete window.odoo[this.callback+"_downup"];
- }
+ },
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ commitChanges: function () {
+ if (!this.loaded) {
+ return;
+ }
+ // switch to WYSIWYG mode if currently in code mode to get all changes
+ if (config.debug && this.mode === 'edit' && this.editor.rte) {
+ var layoutInfo = this.editor.rte.editable().data('layoutInfo');
+ $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false);
+ }
+ this.editor.buildingBlock.clean_for_save();
+ this._setValue(this.$content.html());
+ return this._super.apply(this, arguments);
+ },
});
field_registry
diff --git a/addons/web_editor/static/src/js/base.js b/addons/web_editor/static/src/js/base.js
index e4e2fcd6cad..4368f6de274 100644
--- a/addons/web_editor/static/src/js/base.js
+++ b/addons/web_editor/static/src/js/base.js
@@ -36,7 +36,7 @@ data.ready = function () {
// TODO find a better way to find if we are in the backend or not
// We don't load translation if we are in the backend since it's already done by the webclient
if (!$(document).find('.o_web_client').length) {
- load_translations();
+ return load_translations();
}
});
} else if(all_ready.state() === "resolved") { // can add async template
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 f83a73984c4..3ba3621db9f 100644
--- a/addons/web_editor/static/src/less/web_editor.ui.less
+++ b/addons/web_editor/static/src/less/web_editor.ui.less
@@ -1090,8 +1090,15 @@ body.editor_enable {
background-color: @odoo-brand-secondary;
#wrapwrap {
+ position: relative;
+ display: table;
+ table-layout: fixed;
+ width: 100%;
height: 100%;
+ > * {
+ display: table-row;
+ }
> main {
height: 100%;
diff --git a/addons/web_editor/static/src/xml/backend.xml b/addons/web_editor/static/src/xml/backend.xml
index 69f6e53d6de..082efdbc5a0 100644
--- a/addons/web_editor/static/src/xml/backend.xml
+++ b/addons/web_editor/static/src/xml/backend.xml
@@ -7,41 +7,14 @@
</div>
</t>
- <t t-name="web_editor.FieldTextHtml.button.reset">
- <div class="btn-group pull-right">
- <button class="o_reset_translation btn btn-default btn-sm btn-small" title="Reset from source"><span class="fa fa-upload"></span></button>
- </div>
- </t>
-
<t t-name="web_editor.FieldTextHtml.button.translate">
<div class="btn-group pull-right">
- <button t-if="widget.field.translate" class="oe_field_translate btn btn-default btn-sm btn-small" style="height: 24px; padding: 1px 3px 0px 5px">
+ <button t-if="widget.field.translate" class="o_field_translate btn btn-default btn-sm btn-small" style="height: 24px; padding: 1px 17px 0px 5px">
<span class="fa fa-language fa-lg oe_input_icon"/>
</button>
</div>
</t>
- <t t-name="web_editor.FieldTextHtml.translate">
- <div t-if="widget.recordData.id &amp;&amp; widget.languages.length" style="margin: 5px; position: fixed; top: 0; left: 0; z-index: 2000;">
- <select style="
- width: 148px;
- height: 22px;
- padding: 2px 4px;
- border: 1px solid #ccc;
- -moz-border-radius: 3px;
- -webkit-border-radius: 3px;
- border-radius: 3px;
- background: white;">
- <option value="en_US" t-att-selected="'en_US' == widget.lang ? 'selected' : null">
- <t t-if="!widget.get('effective_readonly')">English (edit mode)</t>
- <t t-if="widget.get('effective_readonly')">English</t>
- </option>
- <t t-foreach="widget.languages" t-as="lang">
- <option t-att-value="lang.code" t-att-selected="lang.code == widget.lang ? 'selected' : null"><t t-esc="lang.name"/></option>
- </t>
- </select>
- </div>
- </t>
<t t-name="web_editor.FieldTextHtml.fullscreen">
<span style="margin: 5px; position: fixed; top: 0; right: 0; z-index: 2000;">
<button class="o_fullscreen btn btn-primary" style="width: 24px; height: 24px; background-color: #337ab7; border: 1px solid #2e6da4; border-radius: 4px; padding: 0; position: relative;">
diff --git a/addons/web_editor/static/tests/web_editor_tests.js b/addons/web_editor/static/tests/web_editor_tests.js
index a053ad99043..283931e9b0d 100644
--- a/addons/web_editor/static/tests/web_editor_tests.js
+++ b/addons/web_editor/static/tests/web_editor_tests.js
@@ -3,6 +3,9 @@ odoo.define('web_editor.web_editor_tests', function (require) {
var FormView = require('web.FormView');
var testUtils = require('web.test_utils');
+var core = require('web.core');
+
+var _t = core._t;
QUnit.module('web_editor', {
beforeEach: function() {
@@ -87,6 +90,43 @@ QUnit.test('field html widget (with options inline-style)', function (assert) {
}, 0);
});
+QUnit.test('field html translatable', function (assert) {
+ assert.expect(3);
+
+ var multiLang = _t.database.multi_lang;
+ _t.database.multi_lang = true;
+
+ this.data['mass.mailing'].fields.body.translate = true;
+
+ var form = testUtils.createView({
+ View: FormView,
+ model: 'mass.mailing',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="body" widget="html"/>' +
+ '</form>',
+ res_id: 1,
+ mockRPC: function (route, args) {
+ if (route === '/web/dataset/call_button' && args.method === 'translate_fields') {
+ assert.deepEqual(args.args, ['mass.mailing',1,'body',{}], "should call 'call_button' route");
+ return $.when();
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ assert.strictEqual(form.$('.oe_form_field_html_text .o_field_translate').length, 0,
+ "should not have a translate button in readonly mode");
+
+ form.$buttons.find('.o_form_button_edit').click();
+ var $button = form.$('.oe_form_field_html_text .o_field_translate');
+ assert.strictEqual($button.length, 1, "should have a translate button");
+ $button.click();
+
+ form.destroy();
+ _t.database.multi_lang = multiLang;
+});
+
QUnit.test('field html_frame widget', function (assert) {
assert.expect(6);