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

View File

@ -458,9 +458,7 @@ openerp.base.form.SidebarAttachments = openerp.base.Widget.extend({
['res_model', '=', this.view.dataset.model], ['res_model', '=', this.view.dataset.model],
['res_id', '=', this.view.datarecord.id], ['res_id', '=', this.view.datarecord.id],
['type', 'in', ['binary', 'url']] ['type', 'in', ['binary', 'url']]
])).read_slice( ])).read_slice(['name', 'url', 'type'], this.on_attachments_loaded);
{fields: ['name', 'url', 'type']},
this.on_attachments_loaded);
} }
}, },
on_attachments_loaded: function(attachments) { 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) { do_activate_record: function (index, id, dataset) {
var self = this; var self = this;
this.dataset.read_slice({ // TODO is it needed ?
this.dataset.read_slice([],{
context: dataset.get_context(), context: dataset.get_context(),
domain: dataset.get_domain() domain: dataset.get_domain()
}, function () { }, function () {
@ -1034,11 +1035,9 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
d = new $.Deferred(), d = new $.Deferred(),
page = this.datagroup.openable ? this.page : view.page; page = this.datagroup.openable ? this.page : view.page;
dataset.read_slice({ var fields = _.pluck(_.select(this.columns, function(x) {return x.tag == "field"}), 'name');
fields: _.pluck(_.select(this.columns, function(x) {return x.tag == "field"}), 'name'), var options = { offset: page * limit, limit: limit };
offset: page * limit, dataset.read_slice(fields, options , function (records) {
limit: limit
}, function (records) {
if (!self.datagroup.openable) { if (!self.datagroup.openable) {
view.configure_pager(dataset); view.configure_pager(dataset);
} else { } else {

View File

@ -72,7 +72,7 @@ openerp.base.TreeView = openerp.base.View.extend({
'toolbar': has_toolbar '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) { if (!has_toolbar) {
// WARNING: will do a second read on the same ids, but only on // WARNING: will do a second read on the same ids, but only on
// first load so not very important // first load so not very important

View File

@ -17,6 +17,7 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.dialog = null; this.dialog = null;
this.dialog_viewmanager = null; this.dialog_viewmanager = null;
this.client_widget = null; this.client_widget = null;
this.url = {}
}, },
render: function() { render: function() {
return "<div id='"+this.element_id+"'></div>"; return "<div id='"+this.element_id+"'></div>";
@ -35,6 +36,28 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.inner_viewmanager = null; 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) { do_action: function(action, on_close) {
var type = action.type.replace(/\./g,'_'); var type = action.type.replace(/\./g,'_');
var popup = action.target === 'new'; var popup = action.target === 'new';
@ -69,6 +92,7 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
this.inner_stop(); this.inner_stop();
this.inner_viewmanager = new openerp.base.ViewManagerAction(this, action); this.inner_viewmanager = new openerp.base.ViewManagerAction(this, action);
this.inner_viewmanager.appendTo(this.$element); this.inner_viewmanager.appendTo(this.$element);
this.url_update(action);
} }
/* new window code /* new window code
this.rpc("/base/session/save_session_action", { the_action : action}, function(key) { 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 // TODO: handle non-empty results.group_by with read_group
self.dataset.context = self.context = results.context; self.dataset.context = self.context = results.context;
self.dataset.domain = self.domain = results.domain; self.dataset.domain = self.domain = results.domain;
self.dataset.read_slice({ self.dataset.read_slice(_.keys(self.fields), {
fields: _.keys(self.fields),
offset:0, offset:0,
limit: self.limit limit: self.limit
}, function(events) { }, function(events) {

View File

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

View File

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

View File

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

View File

@ -89,7 +89,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({
} }
this.dataset.domain = domain; this.dataset.domain = domain;
this.dataset.context = this.view_manager.dataset.context; 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); self.schedule_chart(res);
}); });
} }
@ -468,7 +468,7 @@ openerp.base_graph.GraphView = openerp.base.View.extend({
} }
self.dataset.context = results.context; self.dataset.context = results.context;
self.dataset.domain = results.domain; 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]; view_id = this.action.views[1][0];
this.dataset = new openerp.base.DataSetSearch(this.session, this.action.res_model, null, null); 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++) { for (var i = 0; i < result.length; i++) {
if (result[i].id == id) { if (result[i].id == id) {