[ADD] get_active_id, use API functions more instead of internals in DataSet
bzr revid: xmo@openerp.com-20110323075429-ek9bvxs6vzoxcqlc
This commit is contained in:
@@ -183,7 +183,7 @@ openerp.base.DataSet = openerp.base.Controller.extend({
|
||||
*/
|
||||
active_ids: function () {
|
||||
this.rpc('/base/dataset/get', {
|
||||
ids: this._active_ids
|
||||
ids: this.get_active_ids()
|
||||
}, _.bind(function (records) {
|
||||
this.on_active_ids(_.map(
|
||||
records, function (record) {
|
||||
@@ -209,6 +209,15 @@ openerp.base.DataSet = openerp.base.Controller.extend({
|
||||
* @returns itself
|
||||
*/
|
||||
active_id: function () {
|
||||
this.rpc('/base/dataset/get', {
|
||||
ids: [this.get_active_id()]
|
||||
}, _.bind(function (records) {
|
||||
var record = records[0];
|
||||
this.on_active_id(
|
||||
record && new openerp.base.DataRecord(
|
||||
this.session, this._model,
|
||||
this._fields, record));
|
||||
}, this));
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -299,23 +299,28 @@ $(document).ready(function () {
|
||||
equal(dataset.get_active_id(), 3);
|
||||
});
|
||||
|
||||
module('active_ids', {
|
||||
setup: function () {
|
||||
openerp = window.openerp.init();
|
||||
}
|
||||
});
|
||||
asyncTest('Get pre-set active_ids', 6, function () {
|
||||
var dataset = new openerp.base.DataSet({
|
||||
var ResponseAssertSession = function (response_ids) {
|
||||
return {
|
||||
rpc: function (url, params, on_success) {
|
||||
equal(url, '/base/dataset/get');
|
||||
deepEqual(params.ids, [1, 2, 3]);
|
||||
deepEqual(params.ids, response_ids);
|
||||
_.delay(on_success, 0, _.map(
|
||||
params.ids, function (id) {
|
||||
return {id: id, sequence: id, name: 'foo'+id};
|
||||
}
|
||||
));
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module('active_ids', {
|
||||
setup: function () {
|
||||
openerp = window.openerp.init();
|
||||
}
|
||||
});
|
||||
asyncTest('Get pre-set active_ids', 6, function () {
|
||||
var dataset = new openerp.base.DataSet(
|
||||
new ResponseAssertSession([1, 2, 3]));
|
||||
dataset.select([1, 2, 3]);
|
||||
dataset.on_active_ids.add(function (data_records) {
|
||||
equal(data_records.length, 3);
|
||||
@@ -326,4 +331,21 @@ $(document).ready(function () {
|
||||
});
|
||||
dataset.active_ids();
|
||||
});
|
||||
|
||||
module('active_id', {
|
||||
setup: function () {
|
||||
openerp = window.openerp.init();
|
||||
}
|
||||
});
|
||||
test('Get pre-set active_id', 3, function () {
|
||||
var dataset = new openerp.base.DataSet(
|
||||
new ResponseAssertSession([42]));
|
||||
stop(500);
|
||||
dataset.select([1, 2, 3, 42]).activate(42);
|
||||
dataset.on_active_id.add(function (data_record) {
|
||||
equal(data_record.values.id, 42);
|
||||
start();
|
||||
});
|
||||
dataset.active_id();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user