[FIX] m2m fields display
* Add reload_content method to ListView so third parties can ask for a redisplay * Add a StaticDataGroup descendant class to DataGroup (actually to GrouplessDataGroup as it can not contain groups, only records via a static data set) * Fix DataSetStatic.read_ids when no limit provided * Fix Many2ManyListView usage and overriding of a few ListView methods (due to ListView API changing) bzr revid: xmo@openerp.com-20110527151000-lq5a6sfohprs9gvs
This commit is contained in:
parent
d7e17b06cf
commit
dd3c1645ec
|
@ -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
|
||||
* domain and context may be empty. It is then interacted with via
|
||||
* :js:func:`~openerp.base.DataGroup.list`, which is used to read the
|
||||
* content of the current grouping level, and
|
||||
* :js:func:`~openerp.base.DataGroup.get`, which is used to fetch an item
|
||||
* of the current grouping level.
|
||||
* content of the current grouping level.
|
||||
*
|
||||
* @constructs
|
||||
* @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# */{
|
||||
/**
|
||||
* DateaManagement interface between views and the collection of selected
|
||||
|
@ -334,7 +350,8 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({
|
|||
this.count = 0;
|
||||
},
|
||||
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:
|
||||
|
|
|
@ -1050,11 +1050,16 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
|
|||
},
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.dataset = new openerp.base.DataSetMany2Many(this.session, this.field.relation);
|
||||
//TODO: switch to non selectable once xmo has corrected the bug related to that
|
||||
this.list_view = new openerp.base.form.Many2ManyListView(null, this.view.session,
|
||||
this.list_id, this.dataset, false, {'selectable-': false,
|
||||
'addable': 'Add'});
|
||||
this.dataset = new openerp.base.DataSetStatic(
|
||||
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,
|
||||
'addable': 'Add'
|
||||
});
|
||||
this.list_view.groups.datagroup = (
|
||||
new openerp.base.StaticDataGroup(this.dataset));
|
||||
var self = this;
|
||||
this.list_view.m2m_field = this;
|
||||
this.list_view.start();
|
||||
|
@ -1080,7 +1085,7 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
|
|||
},
|
||||
check_load: function() {
|
||||
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) {
|
||||
this.dataset.ids = _.without.apply(null, [this.dataset.ids].concat(ids));
|
||||
this.dataset.count = this.dataset.ids.length;
|
||||
// there may be a faster way
|
||||
this.reload_view();
|
||||
this.reload_content();
|
||||
|
||||
this.m2m_field.on_ui_change();
|
||||
},
|
||||
reload_view: function () {
|
||||
/* Dear xmo, according to your comments, this method's implementation in list view seems
|
||||
* to be a little bit bullshit.
|
||||
* 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);
|
||||
do_add_record: function () {
|
||||
var pop = new openerp.base.form.Many2XSelectPopup(
|
||||
null, this.m2m_field.view.session);
|
||||
pop.select_element(this.model);
|
||||
var self = this;
|
||||
pop.on_select_element.add(function(element_id) {
|
||||
if(! _.detect(self.dataset.ids, function(x) {return x == element_id;})) {
|
||||
self.dataset.ids.push(element_id);
|
||||
self.dataset.count = self.dataset.ids.length;
|
||||
self.reload_view();
|
||||
self.reload_content();
|
||||
}
|
||||
pop.stop();
|
||||
});
|
||||
},
|
||||
select_record: function(index) {
|
||||
var id = this.rows[index].data.id.value;
|
||||
if(! id) {
|
||||
return;
|
||||
}
|
||||
var action_manager = this.m2m_field.view.session.action_manager;
|
||||
action_manager.do_action({
|
||||
do_activate_record: function(index, id) {
|
||||
this.m2m_field.view.session.action_manager.do_action({
|
||||
"res_model": this.dataset.model,
|
||||
"views":[[false,"form"]],
|
||||
"res_id": id,
|
||||
|
@ -1143,9 +1130,8 @@ openerp.base.form.Many2XSelectPopup = openerp.base.BaseWidget.extend({
|
|||
template: "Many2XSelectPopup",
|
||||
select_element: function(model, dataset) {
|
||||
this.model = model;
|
||||
this.dataset = dataset
|
||||
var html = this.render();
|
||||
jQuery(html).dialog({title: '',
|
||||
this.dataset = dataset;
|
||||
jQuery(this.render()).dialog({title: '',
|
||||
modal: true,
|
||||
minWidth: 800});
|
||||
this.start();
|
||||
|
|
|
@ -263,6 +263,14 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
|||
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.render(
|
||||
$.proxy(this, 'compute_aggregates')));
|
||||
},
|
||||
/**
|
||||
* Event handler for a search, asks for the computation/folding of domains
|
||||
* 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']) {
|
||||
results.group_by = null;
|
||||
}
|
||||
self.reload_view(!!results.group_by).then(function () {
|
||||
self.$element.find('table').append(
|
||||
self.groups.render(function () {
|
||||
self.compute_aggregates();}));});
|
||||
self.reload_view(!!results.group_by).then(
|
||||
$.proxy(self, 'reload_content'));
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue