[IMP] read_slice fields outside option [] are probably bugs

bzr revid: al@openerp.com-20110818225721-tn1vl2450tbe11d6
This commit is contained in:
Antony Lesuisse 2011-08-19 00:57:21 +02:00
parent e9d031cb0b
commit 47e709eb73
11 changed files with 50 additions and 31 deletions

View File

@ -286,14 +286,16 @@ openerp.base.DataSet = openerp.base.Widget.extend( /** @lends openerp.base.Data
* Read a slice of the records represented by this DataSet, based on its
* domain and context.
*
* @param {Array} [fields] fields to read and return, by default all fields are returned
* @params {Object} options
* @param {Array} [options.fields] fields to read and return, by default all fields are returned
* @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 (options, callback) { return null; },
read_slice: function (fields, options, callback) {
return null;
},
/**
* Reads the current dataset record (from its index)
*
@ -478,11 +480,12 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({
// all local records
this.ids = ids || [];
},
read_slice: function (options, callback) {
read_slice: function (fields, options, callback) {
// TODO remove fields from options
var self = this,
offset = options.offset || 0,
limit = options.limit || false,
fields = options.fields || false;
fields = fields || false;
var end_pos = limit && limit !== -1 ? offset + limit : undefined;
return this.read_ids(this.ids.slice(offset, end_pos), fields, callback);
},
@ -532,12 +535,12 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({
* @param {Function} callback function called with read_slice result
* @returns {$.Deferred}
*/
read_slice: function (options, callback) {
read_slice: function (fields, options, callback) {
var self = this;
var offset = options.offset || 0;
return this.rpc('/base/dataset/search_read', {
model: this.model,
fields: options.fields || false,
fields: fields || false,
domain: this.get_domain(options.domain),
context: this.get_context(options.context),
sort: this.sort(),

View File

@ -458,9 +458,7 @@ openerp.base.form.SidebarAttachments = openerp.base.Widget.extend({
['res_model', '=', this.view.dataset.model],
['res_id', '=', this.view.datarecord.id],
['type', 'in', ['binary', 'url']]
])).read_slice(
{fields: ['name', 'url', 'type']},
this.on_attachments_loaded);
])).read_slice(['name', 'url', 'type'], this.on_attachments_loaded);
}
},
on_attachments_loaded: function(attachments) {

View File

@ -476,7 +476,8 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
*/
do_activate_record: function (index, id, dataset) {
var self = this;
this.dataset.read_slice({
// TODO is it needed ?
this.dataset.read_slice([],{
context: dataset.get_context(),
domain: dataset.get_domain()
}, function () {
@ -1034,11 +1035,9 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
d = new $.Deferred(),
page = this.datagroup.openable ? this.page : view.page;
dataset.read_slice({
fields: _.pluck(_.select(this.columns, function(x) {return x.tag == "field"}), 'name'),
offset: page * limit,
limit: limit
}, function (records) {
var fields = _.pluck(_.select(this.columns, function(x) {return x.tag == "field"}), 'name');
var options = { offset: page * limit, limit: limit };
dataset.read_slice(fields, options , function (records) {
if (!self.datagroup.openable) {
view.configure_pager(dataset);
} else {

View File

@ -72,7 +72,7 @@ openerp.base.TreeView = openerp.base.View.extend({
'toolbar': has_toolbar
}));
this.dataset.read_slice({fields: this.fields_list()}, function (records) {
this.dataset.read_slice(this.fields_list(), {}, function (records) {
if (!has_toolbar) {
// WARNING: will do a second read on the same ids, but only on
// first load so not very important

View File

@ -17,6 +17,7 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.dialog = null;
this.dialog_viewmanager = null;
this.client_widget = null;
this.url = {}
},
render: function() {
return "<div id='"+this.element_id+"'></div>";
@ -35,6 +36,28 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.inner_viewmanager = null;
}
},
url_update: function(action) {
// this.url = {
// "model": action.model,
// "domain": action.domain,
// };
// action.res_model
// action.domain
// action.context
// after
// action.views
// action.res_id
// mode
// menu
},
url_stringify: function(action) {
},
url_parse: function(action) {
},
on_url_update: function(url) {
},
do_url_action: function(url) {
},
do_action: function(action, on_close) {
var type = action.type.replace(/\./g,'_');
var popup = action.target === 'new';
@ -69,6 +92,7 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.inner_stop();
this.inner_viewmanager = new openerp.base.ViewManagerAction(this, action);
this.inner_viewmanager.appendTo(this.$element);
this.url_update(action);
}
/* new window code
this.rpc("/base/session/save_session_action", { the_action : action}, function(key) {

View File

@ -302,8 +302,7 @@ openerp.base_calendar.CalendarView = openerp.base.View.extend({
// TODO: handle non-empty results.group_by with read_group
self.dataset.context = self.context = results.context;
self.dataset.domain = self.domain = results.domain;
self.dataset.read_slice({
fields: _.keys(self.fields),
self.dataset.read_slice(_.keys(self.fields), {
offset:0,
limit: self.limit
}, function(events) {

View File

@ -290,7 +290,7 @@ openerp.base_dashboard.ConfigOverview = openerp.base.View.extend({
this.dataset.domain = [['type', '=', 'manual']];
},
start: function () {
$.when(this.dataset.read_slice({fields: ['state', 'action_id', 'category_id']}),
$.when(this.dataset.read_slice(['state', 'action_id', 'category_id']),
this.dataset.call('progress'))
.then(this.on_records_loaded);
},
@ -352,9 +352,7 @@ openerp.base_dashboard.ApplicationTiles = openerp.base.View.extend({
},
start: function () {
var self = this;
this.dataset.read_slice(
{fields: ['name', 'web_icon_data', 'web_icon_hover_data']},
function (applications) {
this.dataset.read_slice( ['name', 'web_icon_data', 'web_icon_hover_data'], {}, function (applications) {
// Create a matrix of 3*x applications
var rows = [];
while (applications.length) {
@ -384,9 +382,7 @@ openerp.base_dashboard.Widgets = openerp.base.View.extend({
this.widgets = new openerp.base.DataSetSearch(this, 'res.widget');
},
start: function () {
this.user_widgets.read_slice(
{fields: ['widget_id', 'user_id']},
this.on_widgets_list_loaded);
this.user_widgets.read_slice(['widget_id', 'user_id'], {}, this.on_widgets_list_loaded);
},
on_widgets_list_loaded: function (user_widgets) {
var self = this;

View File

@ -86,7 +86,7 @@ openerp.base_default_home = function (openerp) {
$.blockUI({
message: '<img src="/base_default_home/static/src/img/throbber.gif">'
});
Modules.read_slice({fields: ['id']}, function (records) {
Modules.read_slice(['id'], function (records) {
if (!(records.length === 1)) { return; }
Modules.call('state_update',
[_.pluck(records, 'id'), 'to install', ['uninstalled']],

View File

@ -79,7 +79,7 @@ init: function(parent, element_id, dataset, view_id) {
get_events: function() {
var self = this;
this.dataset.read_slice({}, function(result) {
this.dataset.read_slice([],{}, function(result) {
self.load_event(result);
});
@ -498,7 +498,7 @@ init: function(parent, element_id, dataset, view_id) {
reload_gantt: function() {
var self = this;
this.dataset.read_slice({}, function(response) {
this.dataset.read_slice([],{}, function(response) {
ganttChartControl.clearAll();
jQuery("#GanttDiv").children().remove();
self.load_event(response);

View File

@ -89,7 +89,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({
}
this.dataset.domain = domain;
this.dataset.context = this.view_manager.dataset.context;
this.dataset.read_slice({fields: _(this.fields).keys()}, function(res) {
this.dataset.read_slice(_(this.fields).keys(),{}, function(res) {
self.schedule_chart(res);
});
}
@ -468,7 +468,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({
}
self.dataset.context = results.context;
self.dataset.domain = results.domain;
self.dataset.read_slice({}, $.proxy(self, 'load_chart'));
self.dataset.read_slice([],{}, $.proxy(self, 'load_chart'));
});
}
});

View File

@ -12,7 +12,7 @@ openerp.web_mobile.FormView = openerp.base.Widget.extend({
view_id = this.action.views[1][0];
this.dataset = new openerp.base.DataSetSearch(this.session, this.action.res_model, null, null);
this.dataset.read_slice({}, function (result) {
this.dataset.read_slice([],{}, function (result) {
for (var i = 0; i < result.length; i++) {
if (result[i].id == id) {