diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-05-04 11:48:02 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2017-05-04 17:19:25 +0200 |
| commit | 8ed4513a0a2937e79abb53a046241db0ff3573e9 (patch) | |
| tree | 6ba7932b4ad48e4791fc651062cfec23d28df9ef /addons/web/static/src/js/fields/basic_fields.js | |
| parent | 9ba0767f983763895ad1655184cffce6ffa0e027 (diff) | |
[FIX] web: add translate button for char and text fields
The button allowing the user to translate fields (existing in
previous versions) was not present.
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 7b48574fb44..0cb7742ffa1 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -26,6 +26,47 @@ var view_dialogs = require('web.view_dialogs'); var qweb = core.qweb; var _t = core._t; +var TranslatableFieldMixin = { + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + * @returns {jQuery} + */ + _renderTranslateButton: function () { + if (_t.database.multi_lang && this.field.translate && this.res_id) { + return $('<button>', { + type: 'button', + 'class': 'o_field_translate fa fa-globe btn btn-link', + }) + .on('click', this._onTranslate.bind(this)); + } + return $(); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * open the translation view for the current field + * + * @private + */ + _onTranslate: function () { + this._rpc({ + route: '/web/dataset/call_button', + params: { + model: 'ir.translation', + method: 'translate_fields', + args: [this.model, this.res_id, this.name, this.record.getContext()], + } + }).then(this.do_action.bind(this)); + }, +}; + var DebouncedField = AbstractField.extend({ events: _.extend({}, AbstractField.prototype.events, { 'input': '_onInput', @@ -260,10 +301,26 @@ var InputField = DebouncedField.extend({ }, }); -var FieldChar = InputField.extend({ +var FieldChar = InputField.extend(TranslatableFieldMixin, { className: 'o_field_char', tagName: 'span', supportedFieldTypes: ['char'], + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Add translation button + * + * @override + * @private + */ + _renderEdit: function () { + var def = this._super.apply(this, arguments); + this.$el = this.$el.add(this._renderTranslateButton()); + return def; + }, }); var FieldDate = InputField.extend({ @@ -722,7 +779,7 @@ var FieldFloatTime = FieldFloat.extend({ }, }); -var FieldText = DebouncedField.extend({ +var FieldText = DebouncedField.extend(TranslatableFieldMixin, { className: 'o_field_text', supportedFieldTypes: ['text'], @@ -749,6 +806,8 @@ var FieldText = DebouncedField.extend({ this.$textarea.attr('placeholder', this.attrs.placeholder); } dom.autoresize(this.$textarea, {parent: this}); + + this.$el = this.$el.add(this._renderTranslateButton()); } return this._super(); |
