diff --git a/addons/mail/static/src/js/field_char_emojis.js b/addons/mail/static/src/js/field_char_emojis.js new file mode 100644 index 00000000000..012a68c2ead --- /dev/null +++ b/addons/mail/static/src/js/field_char_emojis.js @@ -0,0 +1,18 @@ +odoo.define('mail.field_char_emojis', function (require) { +"use strict"; + +var basicFields = require('web.basic_fields'); +var registry = require('web.field_registry'); +var FieldEmojiCommon = require('mail.field_emojis_common'); +var MailEmojisMixin = require('mail.emoji_mixin'); + +/** + * Extension of the FieldChar that will add emojis support + */ +var FieldCharEmojis = basicFields.FieldChar.extend(MailEmojisMixin, FieldEmojiCommon); + +registry.add('char_emojis', FieldCharEmojis); + +return FieldCharEmojis; + +}); diff --git a/addons/mail/static/src/js/text_emojis_fields.js b/addons/mail/static/src/js/field_emojis_common.js similarity index 84% rename from addons/mail/static/src/js/text_emojis_fields.js rename to addons/mail/static/src/js/field_emojis_common.js index 1ef817faf08..79215ac7329 100644 --- a/addons/mail/static/src/js/text_emojis_fields.js +++ b/addons/mail/static/src/js/field_emojis_common.js @@ -1,10 +1,9 @@ -odoo.define('mail.text_emojis_field', function (require) { +odoo.define('mail.field_emojis_common', function (require) { "use strict"; var basicFields = require('web.basic_fields'); var core = require('web.core'); var emojis = require('mail.emojis'); -var registry = require('web.field_registry'); var MailEmojisMixin = require('mail.emoji_mixin'); var _onEmojiClickMixin = MailEmojisMixin._onEmojiClick; var QWeb = core.qweb; @@ -24,34 +23,10 @@ var FieldEmojiCommon = { }, /** - * This will add an emoji button that shows the emojis selection dropdown. - * - * We use 'on_attach_callback' because we need the element to be attached to the form first. - * That's because the $emojisIcon element needs to be rendered outside of this $el - * (which is an text element, that can't 'contain' any other elements). - * * @override */ on_attach_callback: function () { - if (!this.$emojisIcon) { - this.$emojisIcon = $(QWeb.render('mail.EmojisDropdown', {widget: this})); - this.$emojisIcon.find('.o_mail_emoji').on('click', this._onEmojiClick.bind(this)); - - if (this.$el.filter('span.o_field_translate').length) { - // multi-languages activated, place the button on the left of the translation button - this.$emojisIcon.addClass('o_mail_emojis_dropdown_translation'); - } - if (this.$el.filter('textarea').length) { - this.$emojisIcon.addClass('o_mail_emojis_dropdown_textarea'); - } - this.$el.last().after(this.$emojisIcon); - } - - if (this.mode === 'edit') { - this.$emojisIcon.show(); - } else { - this.$emojisIcon.hide(); - } + this._attachEmojisDropdown(); }, //-------------------------------------------------------------------------- @@ -122,22 +97,40 @@ var FieldEmojiCommon = { */ _triggerOnchange: function () { this.$input.trigger('change'); + }, + + /** + * This will add an emoji button that shows the emojis selection dropdown. + * + * Should be used inside 'on_attach_callback' because we need the element to be attached to the form first. + * That's because the $emojisIcon element needs to be rendered outside of this $el + * (which is an text element, that can't 'contain' any other elements). + * + * @private + */ + _attachEmojisDropdown: function () { + if (!this.$emojisIcon) { + this.$emojisIcon = $(QWeb.render('mail.EmojisDropdown', {widget: this})); + this.$emojisIcon.find('.o_mail_emoji').on('click', this._onEmojiClick.bind(this)); + + if (this.$el.filter('span.o_field_translate').length) { + // multi-languages activated, place the button on the left of the translation button + this.$emojisIcon.addClass('o_mail_emojis_dropdown_translation'); + } + if (this.$el.filter('textarea').length) { + this.$emojisIcon.addClass('o_mail_emojis_dropdown_textarea'); + } + this.$el.last().after(this.$emojisIcon); + } + + if (this.mode === 'edit') { + this.$emojisIcon.show(); + } else { + this.$emojisIcon.hide(); + } } }; -/** - * Extension of the FieldText that will add emojis support - */ -var FieldTextEmojis = basicFields.FieldText.extend(MailEmojisMixin, FieldEmojiCommon); - -/** - * Extension of the FieldChar that will add emojis support - */ -var FieldCharEmojis = basicFields.FieldChar.extend(MailEmojisMixin, FieldEmojiCommon); - -registry.add('text_emojis', FieldTextEmojis); -registry.add('char_emojis', FieldCharEmojis); - -return {FieldTextEmojis: FieldTextEmojis, FieldCharEmojis: FieldCharEmojis}; +return FieldEmojiCommon; }); diff --git a/addons/mail/static/src/js/field_text_emojis.js b/addons/mail/static/src/js/field_text_emojis.js new file mode 100644 index 00000000000..8ed14ecfa03 --- /dev/null +++ b/addons/mail/static/src/js/field_text_emojis.js @@ -0,0 +1,18 @@ +odoo.define('mail.field_text_emojis', function (require) { +"use strict"; + +var basicFields = require('web.basic_fields'); +var registry = require('web.field_registry'); +var FieldEmojiCommon = require('mail.field_emojis_common'); +var MailEmojisMixin = require('mail.emoji_mixin'); + +/** + * Extension of the FieldText that will add emojis support + */ +var FieldTextEmojis = basicFields.FieldText.extend(MailEmojisMixin, FieldEmojiCommon); + +registry.add('text_emojis', FieldTextEmojis); + +return FieldTextEmojis; + +}); diff --git a/addons/mail/static/src/scss/emojis.scss b/addons/mail/static/src/scss/emojis.scss index 1a686e0fae7..f85c0141565 100644 --- a/addons/mail/static/src/scss/emojis.scss +++ b/addons/mail/static/src/scss/emojis.scss @@ -17,6 +17,15 @@ $o-mail-emoji-height: 2rem; } } +.o_form_view { + // Emojis widgets should hide the emoji dropdown button when the field is invisible. + // This is necessary because the button is added *after* the main element (and not inside) + // (see '_attachEmojisDropdown' for more details) + .o_invisible_modifier + .o_mail_add_emoji{ + display: none !important; + } +} + .o_mail_emojis_dropdown { height: $o-mail-emoji-height; width: 40px; diff --git a/addons/mail/views/assets.xml b/addons/mail/views/assets.xml index 4b1877277e0..e3dd42c366e 100644 --- a/addons/mail/views/assets.xml +++ b/addons/mail/views/assets.xml @@ -38,7 +38,9 @@