[MOV] web,im_livechat: Move clipboard widget to web
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
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);
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
// 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: $o-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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="CopyClipboardText">
|
||||
<button class="btn btn-xs btn-primary o_clipboard_button o_btn_text_copy">
|
||||
<span class="fa fa-clipboard">Copy Text</span>
|
||||
</button>
|
||||
</t>
|
||||
|
||||
<t t-name="CopyClipboardChar">
|
||||
<button class="btn btn-xs btn-primary o_clipboard_button o_btn_char_copy">
|
||||
<span class="fa fa-clipboard">Copy Text</span>
|
||||
</button>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
@@ -1,48 +0,0 @@
|
||||
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: '<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<div>' +
|
||||
'<field name="script_external" widget="CopyClipboardText"/>' +
|
||||
'<field name="web_page" widget="CopyClipboardChar"/>' +
|
||||
'</div>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -8,14 +8,6 @@
|
||||
<template id="assets_backend" name="im_livechat assets backend" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/im_livechat/static/src/js/im_livechat_backend.js"></script>
|
||||
<script type="text/javascript" src="/im_livechat/static/src/js/copy_clipboard.js"></script>
|
||||
<link rel="stylesheet" type="text/scss" href="/im_livechat/static/src/scss/copy_clipboard.scss"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="qunit_suite" name="im_livechat tests" inherit_id="web.qunit_suite">
|
||||
<xpath expr="//script[contains(@src, '/web/static/tests/views/form_tests.js')]" position="after">
|
||||
<script type="text/javascript" src="/im_livechat/static/tests/copy_clipboard_tests.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1064,6 +1064,77 @@ var UrlWidget = InputField.extend({
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
var AbstractFieldBinary = AbstractField.extend({
|
||||
events: _.extend({}, AbstractField.prototype.events, {
|
||||
'change .o_input_file': 'on_file_change',
|
||||
@@ -2673,6 +2744,8 @@ return {
|
||||
PriorityWidget: PriorityWidget,
|
||||
StatInfo: StatInfo,
|
||||
UrlWidget: UrlWidget,
|
||||
TextCopyClipboard: TextCopyClipboard,
|
||||
CharCopyClipboard: CharCopyClipboard,
|
||||
JournalDashboardGraph: JournalDashboardGraph,
|
||||
AceEditor: AceEditor,
|
||||
};
|
||||
|
||||
@@ -34,6 +34,8 @@ registry
|
||||
.add('email', basic_fields.FieldEmail)
|
||||
.add('phone', basic_fields.FieldPhone)
|
||||
.add('url', basic_fields.UrlWidget)
|
||||
.add('CopyClipboardText', basic_fields.TextCopyClipboard)
|
||||
.add('CopyClipboardChar', basic_fields.CharCopyClipboard)
|
||||
.add('image', basic_fields.FieldBinaryImage)
|
||||
.add('binary', basic_fields.FieldBinaryFile)
|
||||
.add('pdf_viewer', basic_fields.FieldPdfViewer)
|
||||
|
||||
@@ -406,4 +406,26 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy to clipboard
|
||||
&.o_field_copy {
|
||||
position: relative;
|
||||
border-radius: 5px;
|
||||
border: 1px solid $btn-primary-border;
|
||||
font-size: $font-size-small;
|
||||
color: $o-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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -930,6 +930,16 @@
|
||||
t-att-border="widget.readonly ? 0 : 1"
|
||||
t-att-name="widget.name"/>
|
||||
</t>
|
||||
<t t-name="CopyClipboardText">
|
||||
<button class="btn btn-xs btn-primary o_clipboard_button o_btn_text_copy">
|
||||
<span class="fa fa-clipboard">Copy Text</span>
|
||||
</button>
|
||||
</t>
|
||||
<t t-name="CopyClipboardChar">
|
||||
<button class="btn btn-xs btn-primary o_clipboard_button o_btn_char_copy">
|
||||
<span class="fa fa-clipboard">Copy Text</span>
|
||||
</button>
|
||||
</t>
|
||||
<t t-name="FieldBinaryFile">
|
||||
<a t-if="widget.mode === 'readonly'" href="javascript:void(0)" class="o_form_uri"/>
|
||||
|
||||
|
||||
@@ -1291,6 +1291,44 @@ QUnit.module('basic_fields', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
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: '<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<div>' +
|
||||
'<field name="script_external" widget="CopyClipboardText"/>' +
|
||||
'<field name="web_page" widget="CopyClipboardChar"/>' +
|
||||
'</div>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
QUnit.module('FieldText');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user