[FIX] M2M form widget so it matches new listview API, add missing (needed) method in ListView API

* Add reload_content method on ListView to re-fetch list content when requested
* Add StaticDataGroup to handle providing static lists to a ListView
  - and fix behavior of DataSet.read_slice in case of a not-provided limit
* Cleanup implementation of M2M widget (and fix its interactions with ListView) to account for improvements in ListView API

bzr revid: xmo@openerp.com-20110530070656-f5sgodses4xqglr2
This commit is contained in:
Xavier Morel 2011-05-30 09:06:56 +02:00
commit ee143db695
3 changed files with 52 additions and 54 deletions

View File

@ -10,9 +10,7 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas
* (a session, a model, a domain, a context and a group_by sequence), the * (a session, a model, a domain, a context and a group_by sequence), the
* domain and context may be empty. It is then interacted with via * domain and context may be empty. It is then interacted with via
* :js:func:`~openerp.base.DataGroup.list`, which is used to read the * :js:func:`~openerp.base.DataGroup.list`, which is used to read the
* content of the current grouping level, and * content of the current grouping level.
* :js:func:`~openerp.base.DataGroup.get`, which is used to fetch an item
* of the current grouping level.
* *
* @constructs * @constructs
* @extends openerp.base.Controller * @extends openerp.base.Controller
@ -204,6 +202,24 @@ openerp.base.GrouplessDataGroup = openerp.base.DataGroup.extend(
} }
}); });
openerp.base.StaticDataGroup = openerp.base.GrouplessDataGroup.extend(
/** @lends openerp.base.StaticDataGroup# */ {
/**
* A specialization of groupless data groups, relying on a single static
* dataset as its records provider.
*
* @constructs
* @extends openerp.base.GrouplessDataGroup
* @param {openep.base.DataSetStatic} dataset a static dataset backing the groups
*/
init: function (dataset) {
this.dataset = dataset;
},
list: function (ifGroups, ifRecords) {
ifRecords(this.dataset);
}
});
openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.DataSet# */{ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.DataSet# */{
/** /**
* DateaManagement interface between views and the collection of selected * DateaManagement interface between views and the collection of selected
@ -334,7 +350,8 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({
this.count = 0; this.count = 0;
}, },
read_slice: function (fields, offset, limit, callback) { read_slice: function (fields, offset, limit, callback) {
this.read_ids(this.ids.slice(offset, offset + limit)); var end_pos = limit && limit !== -1 ? offset + limit : undefined;
this.read_ids(this.ids.slice(offset, end_pos), fields, callback);
} }
}); });
@ -408,18 +425,6 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({
} }
}); });
openerp.base.DataSetRelational = openerp.base.DataSet.extend( /** @lends openerp.base.DataSet# */{
});
openerp.base.DataSetMany2Many = openerp.base.DataSetStatic.extend({
/* should extend DataSetStatic instead, but list view still does not support it
*/
unlink: function(ids) {
// just do nothing
}
});
}; };
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:

View File

@ -1050,11 +1050,16 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
}, },
start: function() { start: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.dataset = new openerp.base.DataSetMany2Many(this.session, this.field.relation); this.dataset = new openerp.base.DataSetStatic(
//TODO: switch to non selectable once xmo has corrected the bug related to that this.session, this.field.relation);
this.list_view = new openerp.base.form.Many2ManyListView(null, this.view.session,
this.list_id, this.dataset, false, {'selectable-': false, this.list_view = new openerp.base.form.Many2ManyListView(
'addable': 'Add'}); null, this.view.session, this.list_id, this.dataset, false, {
'selectable': false,
'addable': 'Add'
});
this.list_view.groups.datagroup = (
new openerp.base.StaticDataGroup(this.dataset));
var self = this; var self = this;
this.list_view.m2m_field = this; this.list_view.m2m_field = this;
this.list_view.start(); this.list_view.start();
@ -1080,7 +1085,7 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
}, },
check_load: function() { check_load: function() {
if(this.is_started && this.is_setted) { if(this.is_started && this.is_setted) {
this.list_view.reload_view(); this.list_view.reload_content();
} }
} }
}); });
@ -1089,44 +1094,26 @@ openerp.base.form.Many2ManyListView = openerp.base.ListView.extend({
do_delete: function (ids) { do_delete: function (ids) {
this.dataset.ids = _.without.apply(null, [this.dataset.ids].concat(ids)); this.dataset.ids = _.without.apply(null, [this.dataset.ids].concat(ids));
this.dataset.count = this.dataset.ids.length; this.dataset.count = this.dataset.ids.length;
// there may be a faster way this.reload_content();
this.reload_view();
this.m2m_field.on_ui_change(); this.m2m_field.on_ui_change();
}, },
reload_view: function () { do_add_record: function () {
/* Dear xmo, according to your comments, this method's implementation in list view seems var pop = new openerp.base.form.Many2XSelectPopup(
* to be a little bit bullshit. null, this.m2m_field.view.session);
* I assume the list view will be changed later, so I hope it will support static datasets.
*/
return this.rpc('/base/listview/fill', {
'model': this.dataset.model,
'id': this.view_id,
'domain': [["id", "in", this.dataset.ids]],
'context': this.dataset.context
}, this.do_fill_table);
},
do_add_record: function (e) {
e.stopImmediatePropagation();
var pop = new openerp.base.form.Many2XSelectPopup(null, this.m2m_field.view.session);
pop.select_element(this.model); pop.select_element(this.model);
var self = this; var self = this;
pop.on_select_element.add(function(element_id) { pop.on_select_element.add(function(element_id) {
if(! _.detect(self.dataset.ids, function(x) {return x == element_id;})) { if(! _.detect(self.dataset.ids, function(x) {return x == element_id;})) {
self.dataset.ids.push(element_id); self.dataset.ids.push(element_id);
self.dataset.count = self.dataset.ids.length; self.dataset.count = self.dataset.ids.length;
self.reload_view(); self.reload_content();
} }
pop.stop(); pop.stop();
}); });
}, },
select_record: function(index) { do_activate_record: function(index, id) {
var id = this.rows[index].data.id.value; this.m2m_field.view.session.action_manager.do_action({
if(! id) {
return;
}
var action_manager = this.m2m_field.view.session.action_manager;
action_manager.do_action({
"res_model": this.dataset.model, "res_model": this.dataset.model,
"views":[[false,"form"]], "views":[[false,"form"]],
"res_id": id, "res_id": id,
@ -1143,9 +1130,8 @@ openerp.base.form.Many2XSelectPopup = openerp.base.BaseWidget.extend({
template: "Many2XSelectPopup", template: "Many2XSelectPopup",
select_element: function(model, dataset) { select_element: function(model, dataset) {
this.model = model; this.model = model;
this.dataset = dataset this.dataset = dataset;
var html = this.render(); jQuery(this.render()).dialog({title: '',
jQuery(html).dialog({title: '',
modal: true, modal: true,
minWidth: 800}); minWidth: 800});
this.start(); this.start();

View File

@ -263,6 +263,14 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
self.on_loaded(field_view_get, grouped); self.on_loaded(field_view_get, grouped);
}); });
}, },
/**
* re-renders the content of the list view
*/
reload_content: function () {
this.$element.find('table').append(
this.groups.apoptosis().render(
$.proxy(this, 'compute_aggregates')));
},
/** /**
* Event handler for a search, asks for the computation/folding of domains * Event handler for a search, asks for the computation/folding of domains
* and contexts (and group-by), then reloads the view's content. * and contexts (and group-by), then reloads the view's content.
@ -289,10 +297,8 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) { if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) {
results.group_by = null; results.group_by = null;
} }
self.reload_view(!!results.group_by).then(function () { self.reload_view(!!results.group_by).then(
self.$element.find('table').append( $.proxy(self, 'reload_content'));
self.groups.render(function () {
self.compute_aggregates();}));});
}); });
}, },
/** /**
@ -875,3 +881,4 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
}; };
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: