diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-03-22 20:05:14 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-03-22 20:05:14 +0100 |
| commit | cdbee48888a9028ed54abc2c764d2b560e0af099 (patch) | |
| tree | 72dcd7ea458cd6ce14d2e365ee82bea53947dc4a /addons/web/static | |
| parent | 7d86bdca2111e3aeec8d165814b086c43b62998e (diff) | |
| parent | 39d9c362c5b67a6c5a5d589daa13941e21358b1d (diff) | |
[MERGE] forward port branch 11.0 up to 39d9c362c5b
Diffstat (limited to 'addons/web/static')
5 files changed, 91 insertions, 19 deletions
diff --git a/addons/web/static/src/js/libs/jquery.js b/addons/web/static/src/js/libs/jquery.js index 0b12b4fed0d..4bcab8eb866 100644 --- a/addons/web/static/src/js/libs/jquery.js +++ b/addons/web/static/src/js/libs/jquery.js @@ -11,6 +11,9 @@ $.extend($.expr[':'], { containsLike: function (element, index, matches){ return element.innerHTML.toUpperCase().indexOf(matches[3].toUpperCase()) >= 0; }, + containsTextLike: function (element, index, matches){ + return element.innerText.toUpperCase().indexOf(matches[3].toUpperCase()) >= 0; + }, containsExact: function (element, index, matches){ return $.trim(element.innerHTML) === matches[3]; }, diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js index 977674c022a..e8367e79c26 100644 --- a/addons/web/static/src/js/views/basic/basic_renderer.js +++ b/addons/web/static/src/js/views/basic/basic_renderer.js @@ -256,7 +256,7 @@ var BasicRenderer = AbstractRenderer.extend({ // If the view is in edit mode and that a widget have to switch // its "readonly" state, we have to re-render it completely if ('readonly' in modifiers && element.widget) { - var mode = modifiers.readonly ? 'readonly' : modifiersData.baseMode; + var mode = modifiers.readonly ? 'readonly' : modifiersData.baseModeByRecord[record.id]; if (mode !== element.widget.mode) { self._rerenderFieldWidget(element.widget, record, { keepBaseMode: true, @@ -416,16 +416,17 @@ var BasicRenderer = AbstractRenderer.extend({ * @param {Object} [options.callback] the callback to call on registration * and on modifiers updates * @param {boolean} [options.keepBaseMode=false] this function registers the - * 'baseMode' of the node; this is a field widget specific settings which + * 'baseMode' of the node on a per record basis; + * this is a field widget specific settings which * represents the generic mode of the widget, regardless of its modifiers * (the interesting case is the list view: all widgets are supposed to be * in the baseMode 'readonly', except the ones that are in the line that * is currently being edited). - * With option 'keepBaseMode' set to true, the current baseMode of the + * With option 'keepBaseMode' set to true, the baseMode of the record's * node isn't overridden (this is particularily useful when a field widget * is re-rendered because its readonly modifier changed, as in this case, * we don't want to change its base mode). - * @param {string} [options.mode] the 'baseMode' of the node is set to this + * @param {string} [options.mode] the 'baseMode' of the record's node is set to this * value (if not given, it is set to this.mode, the mode of the renderer) * @returns {Object} for code efficiency, returns the last evaluated * modifiers for the given node and record. @@ -443,15 +444,16 @@ var BasicRenderer = AbstractRenderer.extend({ modifiers: modifiers, evaluatedModifiers: {}, elementsByRecord: {}, + baseModeByRecord : {}, }; if (!_.isEmpty(modifiers)) { // Register only if modifiers might change (TODO condition might be improved here) this.allModifiersData.push(modifiersData); } } - // Compute node's base mode if necessary - if (!options.keepBaseMode) { - modifiersData.baseMode = options.mode || this.mode; + // Compute the record's base mode + if (!modifiersData.baseModeByRecord[record.id] || !options.keepBaseMode) { + modifiersData.baseModeByRecord[record.id] = options.mode || this.mode; } // Evaluate if necessary diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js index 8155862dbb4..2d9c02b8ebc 100644 --- a/addons/web/static/src/js/views/list/list_editable_renderer.js +++ b/addons/web/static/src/js/views/list/list_editable_renderer.js @@ -504,8 +504,8 @@ ListRenderer.include({ var $row = this._super.apply(this, arguments); if (this.addTrashIcon) { var $icon = this.isMany2Many ? - $('<i>', {class: 'fa fa-times', name: 'unlink'}) : - $('<i>', {class: 'fa fa-trash-o', name: 'delete'}); + $('<button>', {class: 'fa fa-times o_list_record_remove', name: 'unlink', 'aria-label': _t('Unlink row ') + (index+1)}) : + $('<button>', {class: 'fa fa-trash-o o_list_record_remove', name: 'delete', 'aria-label': _t('Delete row ') + (index+1)}); var $td = $('<td>', {class: 'o_list_record_remove'}).append($icon); $row.append($td); } diff --git a/addons/web/static/src/less/list_view.less b/addons/web/static/src/less/list_view.less index 98a1d56fac0..22e046bf923 100644 --- a/addons/web/static/src/less/list_view.less +++ b/addons/web/static/src/less/list_view.less @@ -70,6 +70,14 @@ width: 1px; // to prevent the column to expand } + .o_list_record_delete_btn { + padding: 0px; + background-style: none; + border-style: none; + height: 0px; + display: table-cell; + } + // Decoration of the row .text-bf { font-weight: bold; diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 100c2436377..6528969bbb7 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -2261,6 +2261,65 @@ QUnit.module('relational_fields', { QUnit.module('FieldOne2Many'); + QUnit.test('one2many list editable with cell readonly modifier', function (assert) { + assert.expect(4); + + this.data.partner.records[0].p = [2]; + this.data.partner.records[1].turtles = [1,2]; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<field name="p">' + + '<tree editable="bottom">' + + '<field name="turtles" invisible="1"/>' + + '<field name="foo" attrs="{"readonly" : [("turtles", "!=", [])] }"/>' + + '<field name="qux" attrs="{"readonly" : [("turtles", "!=", [])] }"/>' + + '</tree>' + + '</field>' + + '</form>', + res_id: 1, + mockRPC: function (route, args) { + if (route === '/web/dataset/call_kw/partner/write') { + assert.deepEqual(args.args[1].p[1][2], {foo: 'ff', qux: 99}, + 'The right values should be written'); + } + return this._super(route, args); + } + }); + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_field_x2many_list_row_add a').click(); + + var $targetInput = $('.o_selected_row .o_input[name=foo]'); + assert.equal($targetInput[0], document.activeElement, + 'The first input of the line should have the focus'); + + // Simulating hitting the 'f' key twice + $targetInput.val('f').trigger('input'); + $targetInput.val($targetInput.val() + 'f').trigger('input'); + + assert.equal($targetInput[0], document.activeElement, + 'The first input of the line should still have the focus'); + + // Simulating a TAB key + $targetInput.trigger($.Event('keydown', {which: 9, keyCode:9})); + + var $secondTarget = $('.o_selected_row .o_input[name=qux]'); + + assert.equal($secondTarget[0], document.activeElement, + 'The second input of the line should have the focus after the TAB press'); + + + $secondTarget.val(9).trigger('input'); + $secondTarget.val($secondTarget.val() + 9).trigger('input'); + + form.$buttons.find('.o_form_button_save').click(); + + form.destroy(); + }); + QUnit.test('one2many basic properties', function (assert) { assert.expect(6); @@ -3891,13 +3950,13 @@ QUnit.module('relational_fields', { }); form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('td.o_list_record_remove i').length, 2, + assert.strictEqual(form.$('td.o_list_record_remove button').length, 2, "should have 2 remove buttons"); - assert.ok(form.$('td.o_list_record_remove i').first().hasClass('fa fa-times'), + assert.ok(form.$('td.o_list_record_remove button').first().hasClass('fa fa-times'), "should have X icons to remove (unlink) records"); - form.$('td.o_list_record_remove i').first().click(); + form.$('td.o_list_record_remove button').first().click(); assert.strictEqual(form.$('td.o_list_record_remove i').length, 1, "should have 1 remove button (a record is supposed to have been unlinked)"); @@ -3937,13 +3996,13 @@ QUnit.module('relational_fields', { }); form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('td.o_list_record_remove i').length, 2, + assert.strictEqual(form.$('td.o_list_record_remove button').length, 2, "should have 2 remove buttons"); - assert.ok(form.$('td.o_list_record_remove i').first().hasClass('fa fa-trash-o'), + assert.ok(form.$('td.o_list_record_remove button').first().hasClass('fa fa-trash-o'), "should have trash bin icons to remove (delete) records"); - form.$('td.o_list_record_remove i').first().click(); + form.$('td.o_list_record_remove button').first().click(); assert.strictEqual(form.$('td.o_list_record_remove i').length, 1, "should have 1 remove button (a record is supposed to have been deleted)"); @@ -6689,8 +6748,8 @@ QUnit.module('relational_fields', { form.$('input.o_field_integer[name="int_field"]').val('0').trigger('input'); // remove and start over - form.$('.o_list_record_remove:first i').click(); - form.$('.o_list_record_remove:first i').click(); + form.$('.o_list_record_remove:first button').click(); + form.$('.o_list_record_remove:first button').click(); // enable the many2many onchange form.$('input.o_field_integer[name="int_field"]').val('10').trigger('input'); @@ -8423,7 +8482,7 @@ QUnit.module('relational_fields', { mode: 'edit', }, }); - form.$('.o_list_record_remove:first i').click(); + form.$('.o_list_record_remove:first button').click(); assert.strictEqual(form.$('.o_data_row').text(), 'from onchange', 'onchange has been properly applied'); form.destroy(); @@ -8463,7 +8522,7 @@ QUnit.module('relational_fields', { mode: 'edit', }, }); - form.$('.o_list_record_remove:first i').click(); + form.$('.o_list_record_remove:first button').click(); assert.strictEqual(form.$('.o_data_row').text(), 'from onchange id2from onchange id3', 'onchange has been properly applied'); form.destroy(); |
