[FIX] listview display when action button deletes the corresponding record
if a record has disappeared between activating a button and refreshing the record, remove it from the list view lp bug: https://launchpad.net/bugs/1042718 fixed bzr revid: xmo@openerp.com-20121113104407-n924vinluqfdtesf
This commit is contained in:
parent
7d745f7195
commit
22edf6193d
|
@ -503,12 +503,17 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
|
||||||
return this.reload_content();
|
return this.reload_content();
|
||||||
},
|
},
|
||||||
reload_record: function (record) {
|
reload_record: function (record) {
|
||||||
|
var self = this;
|
||||||
return this.dataset.read_ids(
|
return this.dataset.read_ids(
|
||||||
[record.get('id')],
|
[record.get('id')],
|
||||||
_.pluck(_(this.columns).filter(function (r) {
|
_.pluck(_(this.columns).filter(function (r) {
|
||||||
return r.tag === 'field';
|
return r.tag === 'field';
|
||||||
}), 'name')
|
}), 'name')
|
||||||
).done(function (records) {
|
).done(function (records) {
|
||||||
|
if (!records[0]) {
|
||||||
|
self.records.remove(record);
|
||||||
|
return;
|
||||||
|
}
|
||||||
_(records[0]).each(function (value, key) {
|
_(records[0]).each(function (value, key) {
|
||||||
record.set(key, value, {silent: true});
|
record.set(key, value, {silent: true});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
$(document).ready(function () {
|
||||||
|
var instance;
|
||||||
|
var $fix = $('#qunit-fixture');
|
||||||
|
|
||||||
|
module('list.buttons', {
|
||||||
|
setup: function () {
|
||||||
|
instance = openerp.testing.instanceFor('list');
|
||||||
|
|
||||||
|
openerp.testing.loadTemplate(instance);
|
||||||
|
|
||||||
|
openerp.testing.mockifyRPC(instance);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
asyncTest('record-deletion', 2, function () {
|
||||||
|
instance.session.responses['/web/view/load'] = function () {
|
||||||
|
return {result: {
|
||||||
|
type: 'tree',
|
||||||
|
fields: {
|
||||||
|
a: {type: 'char', string: "A"}
|
||||||
|
},
|
||||||
|
arch: {
|
||||||
|
tag: 'tree',
|
||||||
|
attrs: { },
|
||||||
|
children: [
|
||||||
|
{tag: 'field', attrs: {name: 'a'}},
|
||||||
|
{tag: 'button', attrs: {type: 'object', name: 'foo'}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
};
|
||||||
|
instance.session.responses['/web/dataset/call_kw:read'] = function (req) {
|
||||||
|
var args = req.params.args[0];
|
||||||
|
if (_.isEqual(args, [1, 2, 3])) {
|
||||||
|
return {result: [
|
||||||
|
{id: 1, a: 'foo'}, {id: 2, a: 'bar'}, {id: 3, a: 'baz'}
|
||||||
|
]};
|
||||||
|
} else if (_.isEqual(args, [2])) {
|
||||||
|
// button action virtually removed record
|
||||||
|
return {result: []};
|
||||||
|
}
|
||||||
|
throw new Error(JSON.stringify(req.params));
|
||||||
|
};
|
||||||
|
instance.session.responses['/web/dataset/call_button'] = function () {
|
||||||
|
return {result: false};
|
||||||
|
};
|
||||||
|
var ds = new instance.web.DataSetStatic(null, 'demo', null, [1, 2, 3]);
|
||||||
|
var l = new instance.web.ListView({}, ds, false, {editable: 'top'});
|
||||||
|
l.appendTo($fix)
|
||||||
|
.then(l.proxy('reload_content'))
|
||||||
|
.then(function () {
|
||||||
|
var d = $.Deferred();
|
||||||
|
l.records.bind('remove', function () {
|
||||||
|
d.resolve();
|
||||||
|
});
|
||||||
|
$fix.find('table tbody tr:eq(1) button').click();
|
||||||
|
return d.promise();
|
||||||
|
})
|
||||||
|
.always(function () { start(); })
|
||||||
|
.then(function () {
|
||||||
|
strictEqual(l.records.length, 2,
|
||||||
|
"should have 2 records left");
|
||||||
|
strictEqual($fix.find('table tbody tr[data-id]').length, 2,
|
||||||
|
"should have 2 rows left");
|
||||||
|
}, function (e) {
|
||||||
|
ok(false, e && e.message || e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -58,5 +58,6 @@
|
||||||
<script type="text/javascript" src="/web/static/test/evals.js"></script>
|
<script type="text/javascript" src="/web/static/test/evals.js"></script>
|
||||||
<script type="text/javascript" src="/web/static/test/search.js"></script>
|
<script type="text/javascript" src="/web/static/test/search.js"></script>
|
||||||
<script type="text/javascript" src="/web/static/test/Widget.js"></script>
|
<script type="text/javascript" src="/web/static/test/Widget.js"></script>
|
||||||
|
<script type="text/javascript" src="/web/static/test/list.js"></script>
|
||||||
<script type="text/javascript" src="/web/static/test/list-editable.js"></script>
|
<script type="text/javascript" src="/web/static/test/list-editable.js"></script>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue