changeset 432806fd379d in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=432806fd379d
description:
        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
diffstat:

 src/view/tree.js |  28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diffs (54 lines):

diff -r a8c23e9023e7 -r 432806fd379d src/view/tree.js
--- a/src/view/tree.js  Sat Sep 07 23:24:07 2019 +0200
+++ b/src/view/tree.js  Sat Sep 07 23:26:10 2019 +0200
@@ -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));

Reply via email to