From c7964657ecbbad278cec73cf231d7eef55b44347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Hennecart?= Date: Fri, 19 Jun 2020 07:06:31 +0000 Subject: [IMP] web: add support of "sample" attribute in views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this commit, it is now possible to display sample (fake) data in empty views, in the hope of easing user onboarding. This can be enabled (in list and kanban views) with attribute sample="1" on the arch root element. In this case, if there is no data to display, sample data will be generated based on heuristics (depending on field types and names). This can be used in addition to the no content helper. Task 2232801 X-original-commit: 7c8e627ff5029cb539d702705e5ce53d658c76ed Co-authored-by: Aaron Bohy Co-authored-by: Mathieu Duckerts-Antoine Co-authored-by: Jérémy Hennecart Co-authored-by: Julien Mougenot --- addons/web/static/src/js/views/basic/basic_renderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic/basic_renderer.js') 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 fd285010054..8db6058f242 100644 --- a/addons/web/static/src/js/views/basic/basic_renderer.js +++ b/addons/web/static/src/js/views/basic/basic_renderer.js @@ -455,7 +455,7 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { * @returns {boolean} */ _hasContent: function () { - return this.state.count !== 0; + return this.state.count !== 0 && (!('isSample' in this.state) || !this.state.isSample); }, /** * Force the resequencing of the records after moving one of them to a given -- cgit v1.2.3 From 6998452065044650665c5020e6b730aede690ec0 Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Fri, 19 Jun 2020 07:06:32 +0000 Subject: [IMP] web: disable keyboard navigation with sample data Previous commit introduces the sample data feature in list and kanban views. When sample data is displayed, most parts of the renderers can't be clicked on, to prevent the user from interacting with sample records (e.g. to open a sample record in form view from the list). This commit disables keyboard navigation as well, as those sample records could still be accessed with the keyboard. To do so, several refactorings have been done in views: - _giveFocus function added on controllers (so that we can hook on the moment where we want to focus the renderer, and prevent it in sample mode), it kind of replaces giveFocus of ActionMixin which wasn't use from the outside - updateRendererState -> _updateRendererState as it is private - _setState function added on controllers, to have a hook when we set a new state (already existed, but only in kanban) - _renderView function moved from Basic to AbstractRenderer, so that we have a proper hook to deactivate clickable elements in sample mode Task 2232801 X-original-commit: 4482a03fe2f083f4f44fc6eb76d90ae22afbff91 --- .../static/src/js/views/basic/basic_renderer.js | 46 +++++++--------------- 1 file changed, 15 insertions(+), 31 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_renderer.js') 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 8db6058f242..f90e27d23d8 100644 --- a/addons/web/static/src/js/views/basic/basic_renderer.js +++ b/addons/web/static/src/js/views/basic/basic_renderer.js @@ -142,7 +142,7 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { */ confirmChange: function (state, id, fields, ev) { var self = this; - this.state = state; + this._setState(state); var record = this._getRecord(id); if (!record) { return this._render().then(_.constant([])); @@ -646,25 +646,25 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { return modifiersData.evaluatedModifiers[record.id]; }, /** - * Render the view - * * @override - * @returns {Promise} */ - _render: function () { - var oldAllFieldWidgets = this.allFieldWidgets; + async _render() { + const oldAllFieldWidgets = this.allFieldWidgets; this.allFieldWidgets = {}; // TODO maybe merging allFieldWidgets and allModifiersData into "nodesData" in some way could be great this.allModifiersData = []; - var oldWidgets = this.widgets; + const oldWidgets = this.widgets; this.widgets = []; - return this._renderView().then(function () { - _.each(oldAllFieldWidgets, function (recordWidgets) { - _.each(recordWidgets, function (widget) { - widget.destroy(); - }); - }); - _.invoke(oldWidgets, 'destroy'); - }); + + await this._super(...arguments); + + for (const id in oldAllFieldWidgets) { + for (const widget of oldAllFieldWidgets[id]) { + widget.destroy(); + } + } + for (const widget of oldWidgets) { + widget.destroy(); + } }, /** * Instantiates the appropriate AbstractField specialization for the given @@ -775,22 +775,6 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { .addClass('o_view_nocontent') .append($noContent); }, - /** - * Actual rendering. Supposed to be overridden by concrete renderers. - * The basic responsabilities of _renderView are: - * - use the xml arch of the view to render a jQuery representation - * - instantiate a widget from the registry for each field in the arch - * - * Note that the 'state' field should contains all necessary information - * for the rendering. The field widgets should be as synchronous as - * possible. - * - * @abstract - * @returns {Promise} - */ - _renderView: function () { - return Promise.resolve(); - }, /** * Instantiate custom widgets * -- cgit v1.2.3