diff options
| author | Ankit Sathvara <asa@odoo.com> | 2017-11-07 15:31:14 +0530 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-03-02 15:45:42 +0100 |
| commit | 6be9fa39674786dd75bb74cdbc6c8c6b4d3eccbb (patch) | |
| tree | cce8552c8f727a0bc8f23ef698527fc86d49614c | |
| parent | 0ecfd7bf3e6f2751833ef7435f66dba0f564f5ad (diff) | |
[IMP] web,hr: Phone widget is always clickable
With this commit, when a phone number is clicked (in readonly),
- if voip is not installed, it opens an app according to the user
choice (e.g. skype), and on mobile, it opens the phone app to
call the number
- if voip is installed, in desktop, it opens voip, and on mobile,
it still opens the phone app to call the number, because webRTC
is not supported.
This commit also makes the employee form view use the phone widget
for the 'Work Phone' and 'Work Mobile' fields.
Task #30369
| -rw-r--r-- | addons/hr/views/hr_views.xml | 4 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 53 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 52 | ||||
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 14 |
4 files changed, 26 insertions, 97 deletions
diff --git a/addons/hr/views/hr_views.xml b/addons/hr/views/hr_views.xml index 7e29db54ca1..cf3b08e03a2 100644 --- a/addons/hr/views/hr_views.xml +++ b/addons/hr/views/hr_views.xml @@ -62,8 +62,8 @@ options='{"always_reload": True, "highlight_first_line": True}'/> <field name="work_location"/> <field name="work_email" widget="email"/> - <field name="mobile_phone"/> - <field name="work_phone"/> + <field name="mobile_phone" widget="phone"/> + <field name="work_phone" widget="phone"/> </group> <group string="Position"> <field name="department_id"/> diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 061345683b6..67e5f9b559c 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -8,7 +8,6 @@ odoo.define('web.basic_fields', function (require) { */ var AbstractField = require('web.AbstractField'); -var config = require('web.config'); var core = require('web.core'); var crash_manager = require('web.crash_manager'); var datepicker = require('web.datepicker'); @@ -973,72 +972,22 @@ var FieldPhone = FieldEmail.extend({ className: 'o_field_phone', prefix: 'tel', - /** - * The phone widget is an extension of email, with the distinction that, in - * some cases, we do not want to show a clickable widget in readonly. - * In particular, we only want to make it clickable if the device can call - * this particular number. This is controlled by the _canCall function. - * - * @override - */ - init: function () { - this._super.apply(this, arguments); - if (this.mode === 'readonly' && !this._canCall()) { - this.tagName = 'span'; - } - }, - /** - * Returns the associated link only if there is one. - * - * @override - */ - getFocusableElement: function () { - if (this.mode !== 'readonly' || this._canCall()) { - return this._super.apply(this, arguments); - } - return $(); - }, - //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- /** - * In readonly, we only make the widget clickable if the device can call it. - * Additionally, we obfuscate the phone number to prevent Skype from seeing it. - * * @override * @private */ _renderReadonly: function () { this._super(); - if (this._canCall()) { - // Split phone number into two to prevent Skype app from finding it - var text = this.$el.text(); - var part1 = _.escape(text.substr(0, text.length/2)); - var part2 = _.escape(text.substr(text.length/2)); - this.$el.html(part1 + "­" + part2); - } else { - this.$el.removeClass('o_form_uri'); - } + // This class should technically be there in case of a very very long // phone number, but it breaks the o_row mechanism, which is more // important right now. this.$el.removeClass('o_text_overflow'); }, - - /** - * Phone fields are clickable in readonly on small screens ~= on phones. - * This can be overriden by call-capable modules to display a clickable - * link in different situations, like always regardless of screen size, - * or only allow national calls for example. - * - * @override - * @private - */ - _canCall: function () { - return config.device.isMobile; - } }); var UrlWidget = InputField.extend({ diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 9f2e30d8529..11f39bc8147 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -3061,8 +3061,8 @@ QUnit.module('basic_fields', { var $phoneLink = form.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 1, "should have a anchor with correct classes"); - assert.strictEqual($phoneLink.text(), 'y\u00ADop', - "value should be displayed properly as text with the skype obfuscation"); + assert.strictEqual($phoneLink.text(), 'yop', + "value should be displayed properly"); assert.strictEqual($phoneLink.attr('href'), 'tel:yop', "should have proper tel prefix"); @@ -3079,8 +3079,8 @@ QUnit.module('basic_fields', { // save form.$buttons.find('.o_form_button_save').click(); $phoneLink = form.$('a.o_form_uri.o_field_widget'); - assert.strictEqual($phoneLink.text(), 'n\u00ADew', - "new value should be displayed properly as text with the skype obfuscation"); + assert.strictEqual($phoneLink.text(), 'new', + "new value should be displayed properly"); assert.strictEqual($phoneLink.attr('href'), 'tel:new', "should still have proper tel prefix"); @@ -3104,8 +3104,8 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').length, 5, "should have 5 cells"); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'y\u00ADop', - "value should be displayed properly as text with the skype obfuscation"); + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop', + "value should be displayed properly"); var $phoneLink = list.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 5, @@ -3125,7 +3125,7 @@ QUnit.module('basic_fields', { list.$buttons.find('.o_list_button_save').click(); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'n\u00ADew', + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new', "value should be properly updated"); $phoneLink = list.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 5, @@ -3137,14 +3137,6 @@ QUnit.module('basic_fields', { }); QUnit.test('phone field in form view on normal screens', function (assert) { - // The behavior of this widget is completely altered by voip so this - // test is irrelevant and fails if voip is installed. The enterprise - // module is responsible for testing its own behavior in its own tests. - if ('voip.user_agent' in odoo.__DEBUG__.services) { - assert.expect(0); - return; - } - assert.expect(5); var form = createView({ @@ -3166,11 +3158,11 @@ QUnit.module('basic_fields', { }, }); - var $phone = form.$('span.o_field_widget:not(.o_form_uri)'); + var $phone = form.$('a.o_field_widget.o_form_uri'); assert.strictEqual($phone.length, 1, - "should have a simple span rather than a link"); + "should have rendered the phone number as a link with correct classes"); assert.strictEqual($phone.text(), 'yop', - "value should be displayed properly as text without skype obfuscation"); + "value should be displayed properly"); // switch to edit mode and check the result form.$buttons.find('.o_form_button_edit').click(); @@ -3184,21 +3176,13 @@ QUnit.module('basic_fields', { // save form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('span.o_field_widget:not(.o_form_uri)').text(), 'new', - "new value should be displayed properly as text without skype obfuscation"); + assert.strictEqual(form.$('a.o_field_widget.o_form_uri').text(), 'new', + "new value should be displayed properly"); form.destroy(); }); QUnit.test('phone field in editable list view on normal screens', function (assert) { - // The behavior of this widget is completely altered by voip so this - // test is irrelevant and fails if voip is installed. The enterprise - // module is responsible for testing its own behavior in its own tests. - if ('voip.user_agent' in odoo.__DEBUG__.services) { - assert.expect(0); - return; - } - assert.expect(8); var list = createView({ @@ -3216,10 +3200,10 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').length, 5, "should have 5 cells"); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop', - "value should be displayed properly as text without skype obfuscation"); + "value should be displayed properly"); - assert.strictEqual(list.$('span.o_field_widget:not(.o_form_uri)').length, 5, - "should have spans with correct classes"); + assert.strictEqual(list.$('a.o_field_widget.o_form_uri').length, 5, + "should have the correct classnames"); // Edit a line and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); @@ -3235,8 +3219,8 @@ QUnit.module('basic_fields', { assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new', "value should be properly updated"); - assert.strictEqual(list.$('span.o_field_widget:not(.o_form_uri)').length, 5, - "should still have spans with correct classes"); + assert.strictEqual(list.$('a.o_field_widget.o_form_uri').length, 5, + "should still have links with correct classes"); list.destroy(); }); @@ -3271,7 +3255,7 @@ QUnit.module('basic_fields', { // save form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_widget').text().split('\u00AD').join(''), val, + assert.strictEqual(form.$('.o_field_widget').text(), val, "value should have been correctly escaped"); form.destroy(); diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index bd1e5d0ffea..d3b21d265d7 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -3818,14 +3818,6 @@ QUnit.module('Views', { }); QUnit.test('navigation with tab key in readonly form view', function (assert) { - // The behavior of the phone widget is completely altered by voip so - // this test fails if voip is installed. The enterprise module is - // responsible for testing its own behavior in its own tests. - if ('voip.user_agent' in odoo.__DEBUG__.services) { - assert.expect(0); - return; - } - assert.expect(3); this.data.partner.records[1].product_id = 37; @@ -3851,15 +3843,19 @@ QUnit.module('Views', { // focus first field, trigger tab form.$('[name="trululu"]').focus(); form.$('[name="trululu"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); + form.$('[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); assert.strictEqual(form.$('[name="product_id"]')[0], document.activeElement, "product_id should be focused"); form.$('[name="product_id"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); + form.$('[name="foo"]:eq(1)').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); assert.strictEqual(form.$('[name="display_name"]')[0], document.activeElement, - "display_name should be focused (emails are focusable but phone aren't)"); + "display_name should be focused"); // simulate shift+tab on active element $(document.activeElement).trigger($.Event('keydown', {which: $.ui.keyCode.TAB, shiftKey: true})); $(document.activeElement).trigger($.Event('keydown', {which: $.ui.keyCode.TAB, shiftKey: true})); + $(document.activeElement).trigger($.Event('keydown', {which: $.ui.keyCode.TAB, shiftKey: true})); + $(document.activeElement).trigger($.Event('keydown', {which: $.ui.keyCode.TAB, shiftKey: true})); assert.strictEqual(document.activeElement, form.$('[name="trululu"]')[0], "first many2one should be focused"); |
