diff --git a/addons/im_livechat/__manifest__.py b/addons/im_livechat/__manifest__.py index b7b2517a956..70d5065531d 100644 --- a/addons/im_livechat/__manifest__.py +++ b/addons/im_livechat/__manifest__.py @@ -34,9 +34,7 @@ Help your customers with this chat, and analyse their feedback. 'data/mail_shortcode_demo.xml', ], 'depends': ["mail", "rating"], - 'qweb': [ - 'static/src/xml/im_livechat_backend.xml', - ], + 'qweb': ['static/src/xml/*.xml'], 'installable': True, 'auto_install': False, 'application': True, diff --git a/addons/im_livechat/static/src/js/copy_clipboard.js b/addons/im_livechat/static/src/js/copy_clipboard.js new file mode 100644 index 00000000000..0d35e6b35f3 --- /dev/null +++ b/addons/im_livechat/static/src/js/copy_clipboard.js @@ -0,0 +1,86 @@ +odoo.define('im_livechat.copy_clipboard', function (require) { +"use strict"; + +var core = require('web.core'); +var field_registry = require('web.field_registry'); +var qweb = core.qweb; + +var _t = core._t; +var FieldText = field_registry.get('text'); +var FieldChar = field_registry.get('char'); + +var CopyClipboard = { + + /** + * @override + */ + destroy: function () { + this._super.apply(this, arguments); + this.clipboard.destroy(); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Instatiates the Clipboad lib. + */ + _initClipboard: function () { + var self = this; + var $clipboardBtn = this.$('.o_clipboard_button'); + $clipboardBtn.tooltip({title: _t('Copied !'), trigger: 'manual', placement: 'right'}); + this.clipboard = new Clipboard($clipboardBtn.get(0), { + text: function () { + return self.value.trim(); + } + }); + this.clipboard.on('success', function () { + _.defer(function () { + $clipboardBtn.tooltip('show'); + _.delay(function () { + $clipboardBtn.tooltip('hide'); + }, 800); + }); + }); + }, +}; + +var TextCopyClipboard = FieldText.extend(CopyClipboard, { + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + _render: function() { + this._super.apply(this, arguments); + this.$el.addClass('o_field_copy'); + this.$el.append($(qweb.render('CopyClipboardText'))); + this._initClipboard(); + } +}); + +var CharCopyClipboard = FieldChar.extend(CopyClipboard, { + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + _render: function() { + this._super.apply(this, arguments); + this.$el.addClass('o_field_copy'); + this.$el.append($(qweb.render('CopyClipboardChar'))); + this._initClipboard(); + } +}); + +field_registry + .add('CopyClipboardText', TextCopyClipboard) + .add('CopyClipboardChar', CharCopyClipboard); +}); diff --git a/addons/im_livechat/static/src/js/im_livechat_backend.js b/addons/im_livechat/static/src/js/im_livechat_backend.js index b69d7a28b8c..4d1e514c01b 100644 --- a/addons/im_livechat/static/src/js/im_livechat_backend.js +++ b/addons/im_livechat/static/src/js/im_livechat_backend.js @@ -28,4 +28,4 @@ chat_manager.bus.on('new_message', null, function (msg) { }); }); -}); +}); \ No newline at end of file diff --git a/addons/im_livechat/static/src/less/copy_clipboard.less b/addons/im_livechat/static/src/less/copy_clipboard.less new file mode 100644 index 00000000000..1d56022f28e --- /dev/null +++ b/addons/im_livechat/static/src/less/copy_clipboard.less @@ -0,0 +1,20 @@ +// less properties for copy widget +.o_field_copy { + position: relative; + border-radius: 5px; + border: 1px solid @btn-primary-border; + font-size: @font-size-small; + color: @odoo-brand-optional; + font-weight: @badge-font-weight; + text-align: center; + .o_clipboard_button { + &.o_btn_text_copy { + position: absolute; + top: 0; + right: 0; + } + &.o_btn_char_copy { + padding-top: 2px; + } + } +} diff --git a/addons/im_livechat/static/src/xml/copy_clipboard.xml b/addons/im_livechat/static/src/xml/copy_clipboard.xml new file mode 100644 index 00000000000..a6c1cb8a197 --- /dev/null +++ b/addons/im_livechat/static/src/xml/copy_clipboard.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/addons/im_livechat/static/tests/copy_clipboard_tests.js b/addons/im_livechat/static/tests/copy_clipboard_tests.js new file mode 100644 index 00000000000..d0320ce7690 --- /dev/null +++ b/addons/im_livechat/static/tests/copy_clipboard_tests.js @@ -0,0 +1,48 @@ +odoo.define('im_livechat.copy_clipboard_tests', function (require) { +"use strict"; + +var FormView = require('web.FormView'); +var testUtils = require('web.test_utils'); + +var createView = testUtils.createView; + +QUnit.module('copy_clipboard', { + beforeEach: function () { + this.data = { + partner: { + fields: { + script_external: {string: "Script External", type: "text"}, + web_page: {string: "Web page link", type: "char"} + }, + records: [{ + id: 1, + script_external:'Random Text', + web_page: 'web page links' + },], + }, + }; + } +}); + +QUnit.test('im_livechat: Copy to clipboard button', function (assert) { + assert.expect(2); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '
' + + '' + + '' + + '
' + + '
' + + '
', + }); + assert.strictEqual(form.$('.o_clipboard_button.o_btn_text_copy').length, 1,"Should have copy button on text type field"); + assert.strictEqual(form.$('.o_clipboard_button.o_btn_char_copy').length, 1,"Should have copy button on char type field"); + form.destroy(); +}); + +}); diff --git a/addons/im_livechat/views/im_livechat_channel_templates.xml b/addons/im_livechat/views/im_livechat_channel_templates.xml index e40a311c892..ffe225e5709 100644 --- a/addons/im_livechat/views/im_livechat_channel_templates.xml +++ b/addons/im_livechat/views/im_livechat_channel_templates.xml @@ -8,9 +8,16 @@ +