summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_renderer.js
diff options
context:
space:
mode:
authorOdoo's Mergebot <xmo+roboto@odoo.com>2020-06-22 16:46:29 +0200
committerGitHub <noreply@github.com>2020-06-22 16:46:29 +0200
commit5a99aacda5b97e53f7df65323560586f6739b779 (patch)
tree74095815cec90338d563e2be87f8736bf3dc4f20 /addons/web/static/src/js/views/basic/basic_renderer.js
parent669bba4694896e29c088d6ce69440d3bef8e9fe5 (diff)
parent9389f7ce2ea16121a74535557fa4cae0577bb011 (diff)
[FW][MERGE] *: display sample data in empty views
This PR allows 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. This PR also activates it in a bunch of list and kanban views. Task 2232801 closes odoo/odoo#53417 Forward-port-of: odoo/odoo#52867 Related: odoo/enterprise#11330 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: Jérémy Hennecart <jeh@odoo.com> Co-authored-by: Julien Mougenot <jum@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_renderer.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_renderer.js48
1 files changed, 16 insertions, 32 deletions
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..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([]));
@@ -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
@@ -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
@@ -776,22 +776,6 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, {
.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
*
* @private