[IMP] More dataset refactoring
bzr revid: fme@openerp.com-20120110165451-pvchn668y0b1p645
This commit is contained in:
parent
652e845321
commit
e9ca86dd63
|
@ -293,16 +293,16 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet
|
|||
*
|
||||
* @param {Array} ids identifiers of the records to read
|
||||
* @param {Array} fields fields to read and return, by default all fields are returned
|
||||
* @param {Function} callback function called with read result
|
||||
* @returns {$.Deferred}
|
||||
*/
|
||||
read_ids: function (ids, fields, callback) {
|
||||
read_ids: function (ids, fields, options) {
|
||||
var options = options || {};
|
||||
return this.rpc('/web/dataset/get', {
|
||||
model: this.model,
|
||||
ids: ids,
|
||||
fields: fields,
|
||||
context: this.get_context()
|
||||
}, callback);
|
||||
context: this.get_context(options.context)
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Read a slice of the records represented by this DataSet, based on its
|
||||
|
@ -312,22 +312,20 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet
|
|||
* @params {Object} options
|
||||
* @param {Number} [options.offset=0] The index from which selected records should be returned
|
||||
* @param {Number} [options.limit=null] The maximum number of records to return
|
||||
* @param {Function} callback function called with read_slice result
|
||||
* @returns {$.Deferred}
|
||||
*/
|
||||
read_slice: function (fields, options, callback) {
|
||||
return null;
|
||||
read_slice: function (fields, options) {
|
||||
return null;
|
||||
},
|
||||
/**
|
||||
* Reads the current dataset record (from its index)
|
||||
*
|
||||
* @params {Array} [fields] fields to read and return, by default all fields are returned
|
||||
* @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context
|
||||
* @params {Function} callback function called with read_index result
|
||||
* @returns {$.Deferred}
|
||||
*/
|
||||
read_index: function (fields, options, callback) {
|
||||
var def = $.Deferred().then(callback);
|
||||
read_index: function (fields, options) {
|
||||
var def = $.Deferred();
|
||||
if (_.isEmpty(this.ids)) {
|
||||
def.reject();
|
||||
} else {
|
||||
|
@ -344,15 +342,16 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet
|
|||
* Reads default values for the current model
|
||||
*
|
||||
* @param {Array} [fields] fields to get default values for, by default all defaults are read
|
||||
* @param {Function} callback function called with default_get result
|
||||
* @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context
|
||||
* @returns {$.Deferred}
|
||||
*/
|
||||
default_get: function(fields, callback) {
|
||||
default_get: function(fields, options) {
|
||||
var options = options || {};
|
||||
return this.rpc('/web/dataset/default_get', {
|
||||
model: this.model,
|
||||
fields: fields,
|
||||
context: this.get_context()
|
||||
}, callback);
|
||||
context: this.get_context(options.context)
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Creates a new record in db
|
||||
|
@ -504,14 +503,14 @@ openerp.web.DataSetStatic = openerp.web.DataSet.extend({
|
|||
// all local records
|
||||
this.ids = ids || [];
|
||||
},
|
||||
read_slice: function (fields, options, callback) {
|
||||
read_slice: function (fields, options) {
|
||||
// TODO remove fields from options
|
||||
var self = this,
|
||||
offset = options.offset || 0,
|
||||
limit = options.limit || false,
|
||||
fields = fields || false;
|
||||
var end_pos = limit && limit !== -1 ? offset + limit : this.ids.length;
|
||||
return this.read_ids(this.ids.slice(offset, end_pos), fields, callback);
|
||||
return this.read_ids(this.ids.slice(offset, end_pos), fields);
|
||||
},
|
||||
set_ids: function (ids) {
|
||||
this.ids = ids;
|
||||
|
@ -558,10 +557,9 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D
|
|||
* @param {Array} [options.domain] domain data to add to the request payload, ANDed with the dataset's domain
|
||||
* @param {Number} [options.offset=0] The index from which selected records should be returned
|
||||
* @param {Number} [options.limit=null] The maximum number of records to return
|
||||
* @param {Function} callback function called with read_slice result
|
||||
* @returns {$.Deferred}
|
||||
*/
|
||||
read_slice: function (fields, options, callback) {
|
||||
read_slice: function (fields, options) {
|
||||
var self = this;
|
||||
var options = options || {};
|
||||
var offset = options.offset || 0;
|
||||
|
@ -577,7 +575,7 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D
|
|||
self.ids = result.ids;
|
||||
self.offset = offset;
|
||||
return result.records;
|
||||
}).then(callback);
|
||||
});
|
||||
},
|
||||
get_domain: function (other_domain) {
|
||||
if (other_domain) {
|
||||
|
@ -700,7 +698,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
|
|||
this.delete_all = false;
|
||||
},
|
||||
on_change: function() {},
|
||||
read_ids: function (ids, fields, callback) {
|
||||
read_ids: function (ids, fields) {
|
||||
var self = this;
|
||||
var to_get = [];
|
||||
_.each(ids, function(id) {
|
||||
|
@ -714,7 +712,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
|
|||
to_get.push(id);
|
||||
}
|
||||
});
|
||||
var completion = $.Deferred().then(callback);
|
||||
var completion = $.Deferred();
|
||||
var return_records = function() {
|
||||
var records = _.map(ids, function(id) {
|
||||
return _.extend({}, _.detect(self.cache, function(c) {return c.id === id;}).values, {"id": id});
|
||||
|
|
|
@ -74,7 +74,7 @@ openerp.web.DataExport = openerp.web.Dialog.extend({
|
|||
}
|
||||
return this.exports.read_slice(['name'], {
|
||||
domain: [['resource', '=', this.dataset.model]]
|
||||
}, function (export_list) {
|
||||
}).then(function (export_list) {
|
||||
if (!export_list.length) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ openerp.web.DataImport = openerp.web.Dialog.extend({
|
|||
'fields_get', [], function (fields) {
|
||||
self.graft_fields(fields);
|
||||
self.ready.push(new openerp.web.DataSet(self, self.model)
|
||||
.default_get(_.pluck(self.fields, 'id'), function (fields) {
|
||||
.default_get(_.pluck(self.fields, 'id')).then(function (fields) {
|
||||
_.each(fields, function(val, key) {
|
||||
if (val) {
|
||||
self.fields_with_defaults.push(key);
|
||||
|
|
|
@ -124,7 +124,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({
|
|||
}
|
||||
});
|
||||
if (field_name) {
|
||||
model_dataset.read_slice(['name','field_id'], {"domain": [['model','=',self.model]]}, function(records) {
|
||||
model_dataset.read_slice(['name','field_id'], {"domain": [['model','=',self.model]]}).then(function(records) {
|
||||
if (records) {view_string = records[0].name;}
|
||||
var arch = _.str.sprintf("<?xml version='1.0'?>\n<%s string='%s'>\n\t<field name='%s'/>\n</%s>", values.view_type, view_string, field_name, values.view_type);
|
||||
var vals = {'model': self.model, 'name': values.view_name, 'priority': values.priority, 'type': values.view_type, 'arch': arch};
|
||||
|
@ -232,7 +232,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({
|
|||
var arch_object = self.parse_xml(arch[0].arch, self.main_view_id);
|
||||
self.main_view_type = arch[0].type == 'tree'? 'list': arch[0].type;
|
||||
view_arch_list.push({"view_id": self.main_view_id, "arch": arch[0].arch});
|
||||
self.dataset.read_slice([], {domain: [['inherit_id','=', parseInt(self.main_view_id)]]}, function(result) {
|
||||
self.dataset.read_slice([], {domain: [['inherit_id','=', parseInt(self.main_view_id)]]}).then(function(result) {
|
||||
_.each(result, function(res) {
|
||||
view_arch_list.push({"view_id": res.id, "arch": res.arch});
|
||||
self.inherit_view(arch_object, res);
|
||||
|
@ -915,7 +915,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({
|
|||
table_selector.find("td[id^=]").attr("width","100px");
|
||||
self.add_node_dialog.$element.find('#new_field').click(function() {
|
||||
model_data = new openerp.web.DataSetSearch(self,'ir.model', null, null);
|
||||
model_data.read_slice([], {domain: [['model','=', self.model]]}, function(result) {
|
||||
model_data.read_slice([], {domain: [['model','=', self.model]]}).then(function(result) {
|
||||
self.render_new_field(result[0].id);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -625,7 +625,7 @@ openerp.web.form.SidebarAttachments = openerp.web.Widget.extend({
|
|||
['res_model', '=', this.view.dataset.model],
|
||||
['res_id', '=', this.view.datarecord.id],
|
||||
['type', 'in', ['binary', 'url']]
|
||||
])).read_slice(['name', 'url', 'type'], {}, this.on_attachments_loaded);
|
||||
])).read_slice(['name', 'url', 'type'], {}).then(this.on_attachments_loaded);
|
||||
}
|
||||
},
|
||||
on_attachments_loaded: function(attachments) {
|
||||
|
|
|
@ -1290,7 +1290,7 @@ openerp.web.ListView.Groups = openerp.web.Class.extend( /** @lends openerp.web.L
|
|||
var fields = _.pluck(_.select(this.columns, function(x) {return x.tag == "field"}), 'name');
|
||||
var options = { offset: page * limit, limit: limit };
|
||||
//TODO xmo: investigate why we need to put the setTimeout
|
||||
$.async_when().then(function() {dataset.read_slice(fields, options , function (records) {
|
||||
$.async_when().then(function() {dataset.read_slice(fields, options).then(function (records) {
|
||||
// FIXME: ignominious hacks, parents (aka form view) should not send two ListView#reload_content concurrently
|
||||
if (self.records.length) {
|
||||
self.records.reset(null, {silent: true});
|
||||
|
|
|
@ -86,7 +86,7 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView#
|
|||
'toolbar': has_toolbar
|
||||
}));
|
||||
|
||||
this.dataset.read_slice(this.fields_list(), {}, function (records) {
|
||||
this.dataset.read_slice(this.fields_list()).then(function(records) {
|
||||
if (!has_toolbar) {
|
||||
// WARNING: will do a second read on the same ids, but only on
|
||||
// first load so not very important
|
||||
|
|
|
@ -918,7 +918,7 @@ session.web.TranslateDialog = session.web.Dialog.extend({
|
|||
this.languages = null;
|
||||
this.languages_loaded = $.Deferred();
|
||||
(new session.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
|
||||
[['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }, this.on_languages_loaded);
|
||||
[['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }).then(this.on_languages_loaded);
|
||||
},
|
||||
start: function() {
|
||||
var self = this;
|
||||
|
|
|
@ -392,7 +392,7 @@ openerp.web_calendar.CalendarView = openerp.web.View.extend({
|
|||
offset: 0,
|
||||
domain: self.get_range_domain(),
|
||||
context: self.last_search[1]
|
||||
}, function(events) {
|
||||
}).then(function(events) {
|
||||
self.dataset_events = events;
|
||||
self.on_events_loaded(events);
|
||||
});
|
||||
|
|
|
@ -296,8 +296,10 @@ openerp.web_dashboard.ConfigOverview = openerp.web.View.extend({
|
|||
'|', ['groups_id', '=', false],
|
||||
['groups_id', 'in', record['groups_id']]];
|
||||
return $.when(
|
||||
self.dataset.read_slice(['state', 'action_id', 'category_id'],{
|
||||
domain: todos_filter }),
|
||||
self.dataset.read_slice(
|
||||
['state', 'action_id', 'category_id'],
|
||||
{ domain: todos_filter }
|
||||
),
|
||||
self.dataset.call('progress').pipe(
|
||||
function (arg) { return arg; }, null))
|
||||
}, null).then(this.on_records_loaded);
|
||||
|
@ -403,7 +405,7 @@ openerp.web_dashboard.ApplicationTiles = openerp.web.Widget.extend({
|
|||
openerp.webclient.menu.do_hide_secondary();
|
||||
var domain = [['application','=',true], ['state','=','installed'], ['name', '!=', 'base']];
|
||||
var ds = new openerp.web.DataSetSearch(this, 'ir.module.module',{},domain);
|
||||
ds.read_slice(['id'], {}, function(result) {
|
||||
ds.read_slice(['id']).then(function(result) {
|
||||
if(result.length) {
|
||||
self.on_installed_database();
|
||||
} else {
|
||||
|
@ -418,7 +420,7 @@ openerp.web_dashboard.ApplicationTiles = openerp.web.Widget.extend({
|
|||
on_installed_database: function() {
|
||||
var self = this;
|
||||
var ds = new openerp.web.DataSetSearch(this, 'ir.ui.menu', null, [['parent_id', '=', false]]);
|
||||
var r = ds.read_slice( ['name', 'web_icon_data', 'web_icon_hover_data', 'module'], {}, function (applications) {
|
||||
var r = ds.read_slice( ['name', 'web_icon_data', 'web_icon_hover_data', 'module']).then(function (applications) {
|
||||
//// Create a matrix of 3*x applications
|
||||
//var rows = [];
|
||||
//while (applications.length) {
|
||||
|
|
|
@ -422,7 +422,7 @@ openerp.web_graph.GraphView = openerp.web.View.extend({
|
|||
} else {
|
||||
self.abscissa = self.first_field;
|
||||
}
|
||||
return self.dataset.read_slice(self.list_fields(), {}, $.proxy(self, 'schedule_chart'));
|
||||
return self.dataset.read_slice(self.list_fields()).then($.proxy(self, 'schedule_chart'));
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
|||
group_aggregates[value] = group.aggregates[key];
|
||||
});
|
||||
var dataset = new openerp.web.DataSetSearch(self, self.dataset.model, group.context, group.domain);
|
||||
dataset.read_slice(self.fields_keys, {'domain': group.domain, 'context': group.context}, function(records) {
|
||||
dataset.read_slice(self.fields_keys, {'domain': group.domain, 'context': group.context}).then(function(records) {
|
||||
self.dataset.ids.push.apply(self.dataset.ids, dataset.ids);
|
||||
groups_array[index] = new openerp.web_kanban.KanbanGroup(self, records, group_value, group_name, group_aggregates);
|
||||
if (!remaining--) {
|
||||
|
@ -175,7 +175,7 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
|||
do_process_dataset: function(dataset) {
|
||||
var self = this;
|
||||
this.do_clear_groups();
|
||||
this.dataset.read_slice(this.fields_keys, {}, function(records) {
|
||||
this.dataset.read_slice(this.fields_keys).then(function(records) {
|
||||
var groups = [];
|
||||
while (records.length) {
|
||||
for (var i = 0; i < self.default_nr_columns; i++) {
|
||||
|
|
|
@ -27,7 +27,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
|||
}
|
||||
this.dataset = new openerp.web.DataSetSearch(this, model, null, null);
|
||||
var context = new openerp.web.CompoundContext(this.dataset.get_context());
|
||||
this.dataset.read_slice([],{}, function (result) {
|
||||
this.dataset.read_slice([]).then(function (result) {
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
if (result[i].id == id) {
|
||||
self.datarecord = result[i];
|
||||
|
@ -73,7 +73,7 @@ openerp.web_mobile.FormView = openerp.web.Widget.extend({
|
|||
var list_ids = [];
|
||||
var datasearch = new openerp.web.DataSetSearch(self, rel_field.relation, rel_field.context);
|
||||
datasearch.domain=[['id', 'in', rel_ids]];
|
||||
datasearch.read_slice(['name'], {context:rel_field.context, domain: datasearch.domain, limit:80}, function(listrec){
|
||||
datasearch.read_slice(['name'], {context:rel_field.context, domain: datasearch.domain, limit:80}).then(function(listrec){
|
||||
_.each(listrec, function(i) {
|
||||
list_ids.push(i.id);
|
||||
});
|
||||
|
|
|
@ -33,7 +33,7 @@ openerp.web_mobile.ListView = openerp.web.Widget.extend({
|
|||
var list_ids = [];
|
||||
var datasearch = new openerp.web.DataSetSearch(self, self.action.res_model,self.action.context);
|
||||
datasearch.domain = self.action.domain;
|
||||
datasearch.read_slice(['name'], {context:datasearch.context, domain: datasearch.domain, limit:80}, function(listresult){
|
||||
datasearch.read_slice(['name'], {context:datasearch.context, domain: datasearch.domain, limit:80}).then(function(listresult){
|
||||
_.each(listresult, function(i) {
|
||||
list_ids.push(i.id);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue