Skip to content
Permalink
Browse files

[FIX] web: $el in kanban widget is not safe to use

The definition of the $el attribute of the kanban widget can be
delayed by a willStart, it occurs when opening Accounting with
studio where some js libs need to be downloaded.

The fix consist of creating a temporary empty <div> element that
is replaced by the actual element once the willStart deferred
resolves.

opw-1925079
opw-1925479

related to #30087
  • Loading branch information...
Julien00859 committed Feb 19, 2019
1 parent d12c993 commit 124b5c5a0047d765398079d647d87e5edb9f45c4
@@ -313,6 +313,7 @@ var KanbanRecord = Widget.extend({
var def = widget.replace($field);
if (def.state() === 'pending') {
this.defs.push(def);
widget.$el = $('<div>');
}
this._setFieldDisplay(widget.$el, field_name);
return widget;
@@ -327,6 +328,7 @@ var KanbanRecord = Widget.extend({
var def = widget._widgetRenderAndInsert(function () {});
if (def.state() === 'pending') {
self.defs.push(def);
widget.$el = $('<div>');
}
widget.$el.addClass('o_widget');
$field.replaceWith(widget.$el);
@@ -4310,6 +4310,45 @@ QUnit.module('Views', {
delete widgetRegistry.map.test;
});

QUnit.test('support for delayed deferred on a kanban widget', function (assert) {
assert.expect(2);

var def = $.Deferred();
var MyWidget = Widget.extend({
init: function (parent, dataPoint) {
this.data = dataPoint.data;
},
willStart: function () {
return def;
},
start: function () {
this.$el.text(JSON.stringify(this.data));
},
});
widgetRegistry.add('test', MyWidget);

var view = testUtils.createAsyncView({
View: KanbanView,
model: 'partner',
data: this.data,
arch: '<kanban class="o_kanban_test"><templates><t t-name="kanban-box">' +
'<div>' +
'<widget name="test"/>' +
'</div>' +
'</t></templates></kanban>',
debug: true,
}).then(function (kanban) {
assert.strictEqual(kanban.$('.o_kanban_record:eq(2)').text(), '{"id":3}',
"widget should have been instantiated");

kanban.destroy();
delete widgetRegistry.map.test;
});

assert.equal(view.state(), 'pending', 'The deferred blocks the rendering');
def.resolve();
});

QUnit.test('column progressbars properly work', function (assert) {
assert.expect(2);

0 comments on commit 124b5c5

Please sign in to comment.
You can’t perform that action at this time.