From 43b8eca5b4feef99cdcfcd1d6dd0bf49d6a9d2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 7 Sep 2019 23:26:10 +0200 Subject: [PATCH] Show dynamic readonly widget in editable tree We must render such widget to be able to display them when they are no more readonly. And we must ensure they are loaded and the states is computed when displayed. issue8626 review280041002 --- src/view/tree.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/view/tree.js b/src/view/tree.js index 9d389a1158..713e9dfd96 100644 --- a/src/view/tree.js +++ b/src/view/tree.js @@ -1290,15 +1290,28 @@ Sao.View.Tree.RowEditable._super.redraw.call(this, selected, expanded); + var display_callback = function(widget) { + var record = this.record; + return function() { + var field = record.model.fields[widget.field_name]; + field.set_state(record); + widget.display(record, field); + }; + }.bind(this); // The autocompletion widget do not call display thus we have to // call it when redrawing the row for (i = 0; i < this.tree.columns.length; i++) { + var column = this.tree.columns[i]; td = this._get_column_td(i); tr = td.find('tr'); widget = jQuery(tr.children('.widget-editable')).data('widget'); if (widget) { - field = this.record.model.fields[widget.field_name]; - widget.display(this.record, field); + var callback = display_callback(widget); + if (!this.record.is_loaded(column.attributes.name)) { + this.record.load(column.attributes.name).done(callback); + } else { + callback(); + } } } }, @@ -1369,18 +1382,9 @@ if (!col.field) { continue; } - var state_attrs = col.field.get_state_attrs(this.record); - var readonly = col.attributes.readonly; - if (readonly === undefined) { - readonly = state_attrs.readonly; - if (readonly === undefined) { - readonly = false; - } - } - var EditableBuilder = Sao.View.EditableTree.WIDGETS[ col.attributes.widget]; - if (!readonly && EditableBuilder) { + if (!col.attributes.readonly && EditableBuilder) { var widget = new EditableBuilder( this.tree, col.attributes); widget.el.on('keydown', this.key_press.bind(this));