diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-06-03 15:49:31 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-06-03 15:49:31 +0200 |
| commit | c8d7ad9a6bc55af465392d772ae15e981d0f80c7 (patch) | |
| tree | e9423fa8d28f85b8ad6a1a16e59afadb8db441e9 /addons/web | |
| parent | 8085f259c87f1e6b7f9cf89067f56b327b8936e3 (diff) | |
| parent | 995aa1685eece9ff1070a637d19d511fb1f80260 (diff) | |
[MERGE] forward port branch saas-12.2 up to 995aa1685ee
Diffstat (limited to 'addons/web')
16 files changed, 282 insertions, 50 deletions
diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js index c27311d4df5..f412ae1c467 100644 --- a/addons/web/static/src/js/chrome/abstract_web_client.js +++ b/addons/web/static/src/js/chrome/abstract_web_client.js @@ -492,7 +492,11 @@ var AbstractWebClient = Widget.extend(ServiceProviderMixin, KeyboardNavigationMi new RainbowMan(data).appendTo(this.$el); } else { // For instance keep title blank, as we don't have title in data - this.notification_manager.notify('', data.message, true); + this.call('notification', 'notify', { + title: "", + message: data.message, + sticky: false + }); } } else { throw new Error('Unknown effect type: ' + type); diff --git a/addons/web/static/src/js/chrome/action_manager_act_window.js b/addons/web/static/src/js/chrome/action_manager_act_window.js index 00edadb312a..c43044d5457 100644 --- a/addons/web/static/src/js/chrome/action_manager_act_window.js +++ b/addons/web/static/src/js/chrome/action_manager_act_window.js @@ -58,7 +58,10 @@ ActionManager.include({ * @param {string} [state.view_type] */ loadState: function (state) { + var callersArguments = arguments; + var self = this; var action; + var def; var options = { clear_breadcrumbs: true, pushState: false, @@ -113,11 +116,20 @@ ActionManager.include({ action = lastAction; options.viewType = state.view_type; } + } else if (state.sa) { + def = this._rpc({ + route: '/web/session/get_session_action', + params: {key: state.sa}, + }).then(function (sessionAction) { + action = sessionAction; + }); } - if (action) { - return this.doAction(action, options); - } - return this._super.apply(this, arguments); + return Promise.all([def]).then(function () { + if (action) { + return self.doAction(action, options); + } + return self._super.apply(self, callersArguments); + }); }, //-------------------------------------------------------------------------- diff --git a/addons/web/static/src/js/core/ajax.js b/addons/web/static/src/js/core/ajax.js index 8e7216c7b00..8529c4135f7 100644 --- a/addons/web/static/src/js/core/ajax.js +++ b/addons/web/static/src/js/core/ajax.js @@ -27,11 +27,17 @@ function _genericJsonRpc (fct_name, params, settings, fct) { core.bus.trigger('rpc:result', data, result); if (result.error !== undefined) { if (result.error.data.arguments[0] !== "bus.Bus not available in test mode") { + var func = console.error; if (result.error.data.exception_type === "user_error") { - console.log("Server application error", JSON.stringify(result.error)); - } else { - console.error("Server application error", JSON.stringify(result.error)); + func = console.log; } + func( + "Server application error\n", + "Error code:", result.error.code, "\n", + "Error message:", result.error.message, "\n", + "Error data message:\n", result.error.data.message, "\n", + "Error data debug:\n", result.error.data.debug + ); } return Promise.reject({type: "server", error: result.error}); } else { diff --git a/addons/web/static/src/js/tools/test_menus.js b/addons/web/static/src/js/tools/test_menus.js index 4b7ee4b2e02..82a4ed26c0e 100644 --- a/addons/web/static/src/js/tools/test_menus.js +++ b/addons/web/static/src/js/tools/test_menus.js @@ -44,8 +44,12 @@ } } - // Main function that starts orchestration of tests function clickEverywhere(){ + setTimeout(_clickEverywhere, 1000); + } + + // Main function that starts orchestration of tests + function _clickEverywhere(){ console.log("Starting ClickEverywhere test"); var startTime = performance.now(); createWebClientHooks(); diff --git a/addons/web/static/src/js/views/calendar/calendar_controller.js b/addons/web/static/src/js/views/calendar/calendar_controller.js index 61a966972aa..b3a04ec9a2b 100644 --- a/addons/web/static/src/js/views/calendar/calendar_controller.js +++ b/addons/web/static/src/js/views/calendar/calendar_controller.js @@ -160,7 +160,8 @@ var CalendarController = AbstractController.extend({ * @returns {Promise} */ _updateRecord: function (record) { - return this.model.updateRecord(record).then(this.reload.bind(this, {})); + var reload = this.reload.bind(this, {}); + return this.model.updateRecord(record).then(reload, reload); }, //-------------------------------------------------------------------------- diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js index 0ad1b61e4d7..c3934d930d7 100644 --- a/addons/web/static/src/js/views/calendar/calendar_model.js +++ b/addons/web/static/src/js/views/calendar/calendar_model.js @@ -310,7 +310,7 @@ return AbstractModel.extend({ * Toggle the sidebar (containing the mini calendar) */ toggleFullWidth: function () { - var fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') !== 'true'; + var fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') !== true; this.call('local_storage', 'setItem', 'calendar_fullWidth', fullWidth); }, /** @@ -442,7 +442,7 @@ return AbstractModel.extend({ */ _loadCalendar: function () { var self = this; - this.data.fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') === 'true'; + this.data.fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') === true; this.data.fc_options = this._getFullCalendarOptions(); var defs = _.map(this.data.filters, this._loadFilter.bind(this)); 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 b384b122f5f..dc312d34f5a 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 @@ -911,48 +911,48 @@ ListRenderer.include({ _resequence: function (event, ui) { var self = this; var movedRecordID = ui.item.data('id'); - var rows = this.state.data; - var row = self._getRecord(movedRecordID); - var index0 = rows.indexOf(row); - var index1 = ui.item.index(); - var lower = Math.min(index0, index1); - var upper = Math.max(index0, index1) + 1; - - var order = _.findWhere(self.state.orderedBy, {name: self.handleField}); - var asc = !order || order.asc; - var reorderAll = false; - var sequence = (asc ? -1 : 1) * Infinity; - - // determine if we need to reorder all lines - _.each(rows, function (row, index) { - if ((index < lower || index >= upper) && - ((asc && sequence >= row.data[self.handleField]) || - (!asc && sequence <= row.data[self.handleField]))) { - reorderAll = true; - } - sequence = row.data[self.handleField]; - }); + self.unselectRow().then(function () { + var rows = self.state.data; + var row = self._getRecord(movedRecordID); + var index0 = rows.indexOf(row); + var index1 = ui.item.index(); + var lower = Math.min(index0, index1); + var upper = Math.max(index0, index1) + 1; + + var order = _.findWhere(self.state.orderedBy, {name: self.handleField}); + var asc = !order || order.asc; + var reorderAll = false; + var sequence = (asc ? -1 : 1) * Infinity; + + // determine if we need to reorder all lines + _.each(rows, function (row, index) { + if ((index < lower || index >= upper) && + ((asc && sequence >= row.data[self.handleField]) || + (!asc && sequence <= row.data[self.handleField]))) { + reorderAll = true; + } + sequence = row.data[self.handleField]; + }); - if (reorderAll) { - rows = _.without(rows, row); - rows.splice(index1, 0, row); - } else { - rows = rows.slice(lower, upper); - rows = _.without(rows, row); - if (index0 > index1) { - rows.unshift(row); + if (reorderAll) { + rows = _.without(rows, row); + rows.splice(index1, 0, row); } else { - rows.push(row); + rows = rows.slice(lower, upper); + rows = _.without(rows, row); + if (index0 > index1) { + rows.unshift(row); + } else { + rows.push(row); + } } - } - var sequences = _.pluck(_.pluck(rows, 'data'), self.handleField); - var rowIDs = _.pluck(rows, 'id'); + var sequences = _.pluck(_.pluck(rows, 'data'), self.handleField); + var rowIDs = _.pluck(rows, 'id'); - if (!asc) { - rowIDs.reverse(); - } - this.unselectRow().then(function () { + if (!asc) { + rowIDs.reverse(); + } self.trigger_up('resequence', { rowIDs: rowIDs, offset: _.min(sequences), diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js index 75c52ce81a7..282b1799dde 100644 --- a/addons/web/static/src/js/widgets/date_picker.js +++ b/addons/web/static/src/js/widgets/date_picker.js @@ -13,6 +13,7 @@ var DateWidget = Widget.extend({ type_of_date: "date", events: { 'change.datetimepicker': 'changeDatetime', + 'error.datetimepicker': 'errorDatetime', 'change .o_datepicker_input': 'changeDatetime', 'click input': '_onInputClicked', 'input input': '_onInput', @@ -109,6 +110,12 @@ var DateWidget = Widget.extend({ } }, /** + * Library clears the wrong date format so just ignore error + */ + errorDatetime: function (e) { + return false; + }, + /** * Focuses the datepicker input. This function must be called in order to * prevent 'input' events triggered by the lib to bubble up, and to cause * unwanted effects (like triggering 'field_changed' events) diff --git a/addons/web/static/src/scss/bootstrap_review.scss b/addons/web/static/src/scss/bootstrap_review.scss index edf942df3a4..5ac87936996 100644 --- a/addons/web/static/src/scss/bootstrap_review.scss +++ b/addons/web/static/src/scss/bootstrap_review.scss @@ -30,6 +30,15 @@ &:last-child { @include border-bottom-radius($card-inner-border-radius); } + + &.row { + // The 'row' class should not be used on a 'card-body' element but if + // it is done, our custom bg color would overflow the card. As a fix + // for those cases (normally only one at the time this fix is made), + // remove the background color. + // TODO remove me in master. + background-color: transparent !important; + } } .accordion { .collapsing, .collapse.show { diff --git a/addons/web/static/src/scss/form_view_extra.scss b/addons/web/static/src/scss/form_view_extra.scss index 277537beab4..0d59483c2d8 100644 --- a/addons/web/static/src/scss/form_view_extra.scss +++ b/addons/web/static/src/scss/form_view_extra.scss @@ -140,7 +140,7 @@ border-right: 1px solid #ddd; } .o_td_label + td { - padding: 2px 36px 2px 8px; + padding: 0px 36px 0px 8px; } .o_field_widget.o_text_overflow { width: 1px!important; // hack to make the table layout believe it is a small element (so that the table does not grow too much) ... diff --git a/addons/web/static/src/scss/kanban_view.scss b/addons/web/static/src/scss/kanban_view.scss index c1b05807ddf..c046a7fffb7 100644 --- a/addons/web/static/src/scss/kanban_view.scss +++ b/addons/web/static/src/scss/kanban_view.scss @@ -236,6 +236,7 @@ font-weight: 500; background-color: transparent; color: inherit; + box-shadow: none; @include o-kanban-tag-color; span { diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index d382b686b68..fcbfb4fd781 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -1177,6 +1177,30 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test('state.sa should load action from session', async function (assert) { + assert.expect(1); + + var actionManager = await createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + mockRPC: function (route, args) { + if (route === '/web/session/get_session_action') { + return Promise.resolve(1); + } + return this._super.apply(this, arguments); + }, + }); + actionManager.loadState({ + sa: 1, + }); + + assert.strictEqual(actionManager.$('.o_kanban_view').length, 1, + "should have rendered a kanban view"); + + actionManager.destroy(); + }); + QUnit.module('Concurrency management'); QUnit.test('drop previous actions if possible', async function (assert) { diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index f0bd135973c..091b0baccd2 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -2549,6 +2549,25 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('date field should remove the date if the date is not valid', async function (assert) { + assert.expect(1); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners"><field name="date"/></form>', + res_id: 4, + }); + // switch to edit mode + await testUtils.form.clickEdit(form); + // set an invalid date + var $input = form.$('.o_field_widget[name=date] input'); + $input.val('mmmh').trigger('change'); + assert.strictEqual($input.text(), "", "The date field should be empty"); + form.destroy(); + }); + QUnit.test('date field value should not set on first click', async function (assert) { assert.expect(2); diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js index 34e09541d54..fd7d3b8997d 100644 --- a/addons/web/static/tests/views/calendar_tests.js +++ b/addons/web/static/tests/views/calendar_tests.js @@ -1,11 +1,13 @@ odoo.define('web.calendar_tests', function (require) { "use strict"; +var AbstractStorageService = require('web.AbstractStorageService'); var CalendarView = require('web.CalendarView'); var CalendarRenderer = require('web.CalendarRenderer'); var Dialog = require('web.Dialog'); var fieldUtils = require('web.field_utils'); var mixins = require('web.mixins'); +var RamStorage = require('web.RamStorage'); var testUtils = require('web.test_utils'); var session = require('web.session'); @@ -2603,6 +2605,45 @@ QUnit.module('Views', { calendar.destroy(); }); + QUnit.test('calendar sidebar toggle', async function (assert) { + assert.expect(5); + + var calendar = await createView({ + View: CalendarView, + model: 'event', + data: this.data, + arch: + '<calendar date_start="start_date">'+ + '<field name="name"/>'+ + '</calendar>', + services: { + local_storage: AbstractStorageService.extend({storage: new RamStorage()}), + }, + }); + + var fullWidth = calendar.call('local_storage', 'getItem', 'calendar_fullWidth'); + assert.strictEqual(fullWidth, undefined, + "calendar_fullWidth should be undefined in local storage"); + assert.containsNone(calendar, '.o_calendar_sidebar_container.o_sidebar_hidden', + "sidebar should be opened"); + + // click on close + await testUtils.dom.click(calendar.$('.o_calendar_sidebar_toggler')); + fullWidth = calendar.call('local_storage', 'getItem', 'calendar_fullWidth'); + assert.strictEqual(fullWidth, true, + "calendar_fullWidth should be true in local storage"); + assert.containsOnce(calendar, '.o_calendar_sidebar_container.o_sidebar_hidden', + "sidebar should be hidden"); + + // reload calendar view and check calendar view has still full width + calendar.reload(); + await testUtils.nextTick(); + assert.containsOnce(calendar, '.o_calendar_sidebar_container.o_sidebar_hidden', + "sidebar should be hidden"); + + calendar.destroy(); + }); + }); }); diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index d0f5035e1f1..b4e0f08e529 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -8085,6 +8085,68 @@ QUnit.module('Views', { await testUtils.nextTick(); form.destroy(); }); + + QUnit.test('resequence list lines when discardable lines are present', async function (assert) { + assert.expect(8); + + var onchangeNum = 0; + + this.data.partner.onchanges = { + p: function (obj) { + onchangeNum++; + obj.foo = obj.p.length.toString(); + }, + }; + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form>' + + '<field name="foo"/>' + + '<field name="p"/>' + + '</form>', + archs: { + 'partner,false,list': + '<tree editable="bottom">' + + '<field name="int_field" widget="handle"/>' + + '<field name="display_name" required="1"/>' + + '</tree>', + }, + }); + + assert.strictEqual(onchangeNum, 1, "one onchange happens when form is opened"); + assert.strictEqual(form.$('[name="foo"]').val(), "0", "onchange worked there is 0 line"); + + // Add one line + form.$('.o_field_x2many_list_row_add a').click(); + form.$('.o_field_one2many input:first').focus(); + form.$('.o_field_one2many input:first').val('first line').trigger('input'); + form.$('input[name="foo"]').click(); + assert.strictEqual(onchangeNum, 2, "one onchange happens when a line is added"); + assert.strictEqual(form.$('[name="foo"]').val(), "1", "onchange worked there is 1 line"); + + // Drag and drop second line before first one (with 1 draft and invalid line) + form.$('.o_field_x2many_list_row_add a').click(); + await testUtils.dragAndDrop( + form.$('.ui-sortable-handle').eq(0), + form.$('.o_data_row').last(), + {position: 'bottom'} + ); + assert.strictEqual(onchangeNum, 3, "one onchange happens when lines are resequenced") + assert.strictEqual(form.$('[name="foo"]').val(), "1", "onchange worked there is 1 line"); + + // Add a second line + form.$('.o_field_x2many_list_row_add a').click(); + form.$('.o_field_one2many input:first').focus(); + form.$('.o_field_one2many input:first').val('second line').trigger('input'); + form.$('input[name="foo"]').click(); + assert.strictEqual(onchangeNum, 4, "one onchange happens when a line is added"); + assert.strictEqual(form.$('[name="foo"]').val(), "2", "onchange worked there is 2 lines"); + + form.destroy(); + }); + QUnit.test('if the focus is on the discard button, hitting ESCAPE should discard', async function (assert) { assert.expect(1); diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 932ce53fece..dbce481710d 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -14,6 +14,7 @@ var widgetRegistry = require('web.widget_registry'); var Widget = require('web.Widget'); var _t = core._t; +var createActionManager = testUtils.createActionManager; var createView = testUtils.createView; @@ -937,6 +938,47 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('editable list view: check that controlpanel buttons are updating when groupby applied', async function (assert) { + assert.expect(4); + + this.data.foo.fields.foo = {string: "Foo", type: "char", required:true}; + + var actionManager = await createActionManager({ + actions: [{ + id: 11, + name: 'Partners Action 11', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[3, 'list']], + search_view_id: [9, 'search'], + }], + archs: { + 'foo,3,list': '<tree editable="top"><field name="display_name"/><field name="foo"/></tree>', + + 'foo,9,search': '<search>'+ + '<filter string="candle" name="itsName" context="{\'group_by\': \'foo\'}"/>' + + '</search>', + }, + data: this.data, + }); + + await actionManager.doAction(11); + await testUtils.dom.click(actionManager.$('.o_list_button_add')); + + assert.isNotVisible(actionManager.$('.o_list_button_add'), + "create button should be invisible"); + assert.isVisible(actionManager.$('.o_list_button_save'), "save button should be visible"); + + await testUtils.dom.click(actionManager.$('.o_dropdown_toggler_btn:contains("Group By")')); + await testUtils.dom.click(actionManager.$('.o_group_by_menu .o_menu_item a:contains("candle")')); + + assert.isVisible(actionManager.$('.o_list_button_add'), "create button should be invisible"); + assert.isNotVisible(actionManager.$('.o_list_button_save'), + "save button should be invisible after applying groupby"); + + actionManager.destroy(); + }); + QUnit.test('selection changes are triggered correctly', async function (assert) { assert.expect(8); |
