[IMP] web: field phone widget deals with SMS by default

Task 2123526

Before this task, the phone widget on char fields was not
displaying the send sms button by default

After this task, the default behavior of the phone
widget is to display the send sms button
This commit is contained in:
Lucas Perais (lpe)
2020-01-27 09:31:52 +00:00
parent 87397d0080
commit d41d627569
3 changed files with 46 additions and 8 deletions
@@ -8,11 +8,35 @@ var session = require('web.session');
var _t = core._t;
/**
* Override of FieldPhone to use add a button calling SMS composer if option activated
* Override of FieldPhone to add a button calling SMS composer if option activated (default)
*/
var Phone = basic_fields.FieldPhone;
Phone.include({
/**
* By default, enable_sms is activated
*
* @override
*/
init() {
this._super.apply(this, arguments);
this.enableSMS = 'enable_sms' in this.attrs.options ? this.attrs.options.enable_sms : true;
// reinject in nodeOptions (and thus in this.attrs) to signal the property
this.attrs.options.enable_sms = this.enableSMS;
},
/**
* When the send SMS button is displayed, $el becomes a div wrapping
* the original links.
* This method makes sure we always focus the phone number
*
* @override
*/
getFocusableElement() {
if (this.enableSMS && this.mode === 'readonly') {
return this.$('.' + this.className);
}
return this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
@@ -24,6 +48,7 @@ Phone.include({
*/
_onClickSMS: function (ev) {
ev.preventDefault();
ev.stopPropagation();
var context = session.user_context;
context = _.extend({}, context, {
@@ -54,7 +79,7 @@ Phone.include({
*/
_renderReadonly: function () {
var def = this._super.apply(this, arguments);
if (this.nodeOptions.enable_sms) {
if (this.enableSMS) {
var $composerButton = $('<a>', {
title: _t('Send SMS Text Message'),
href: '',
@@ -111,7 +111,7 @@ QUnit.module('basic_fields', {
assert.containsN(list, '.o_data_row', 3,
"should have 3 record");
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop',
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yopSMS',
"value should be displayed properly");
var $phoneLink = list.$('a.o_form_uri.o_field_widget');
@@ -132,7 +132,7 @@ QUnit.module('basic_fields', {
await testUtils.dom.click(list.$buttons.find('.o_list_button_save'));
$cell = list.$('tbody td:not(.o_list_record_selector)').first();
assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore');
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new',
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'newSMS',
"value should be properly updated");
$phoneLink = list.$('a.o_form_uri.o_field_widget');
assert.strictEqual($phoneLink.length, 3,
@@ -4812,7 +4812,8 @@ QUnit.module('basic_fields', {
});
QUnit.test('phone field in editable list view on normal screens', async function (assert) {
assert.expect(8);
assert.expect(11);
var doActionCount = 0;
var list = await createView({
View: ListView,
@@ -4824,11 +4825,18 @@ QUnit.module('basic_fields', {
size_class: config.device.SIZES.LG,
},
},
intercepts: {
do_action(ev) {
assert.equal(ev.data.action.res_model, 'sms.composer',
'The action to send an SMS should have been executed');
doActionCount += 1;
}
}
});
assert.containsN(list, 'tbody td:not(.o_list_record_selector)', 5);
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop',
"value should be displayed properly");
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yopSMS',
"value should be displayed properly with a link to send SMS");
assert.containsN(list, 'a.o_field_widget.o_form_uri', 5,
"should have the correct classnames");
@@ -4845,11 +4853,16 @@ QUnit.module('basic_fields', {
await testUtils.dom.click(list.$buttons.find('.o_list_button_save'));
$cell = list.$('tbody td:not(.o_list_record_selector)').first();
assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore');
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new',
assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'newSMS',
"value should be properly updated");
assert.containsN(list, 'a.o_field_widget.o_form_uri', 5,
"should still have links with correct classes");
await testUtils.dom.click(list.$('tbody td:not(.o_list_record_selector) .o_field_phone_sms').first());
assert.equal(doActionCount, 1, 'Only one action should have been executed');
assert.containsNone(list, '.o_selected_row',
'None of the list element should have been activated');
list.destroy();
});