[???] try to hook some stuff into reset event

bzr revid: xmo@openerp.com-20110819101208-nqoroidipedo73rs
This commit is contained in:
Xavier Morel 2011-08-19 12:12:08 +02:00
parent 941d1d0968
commit d69cd3cb15
1 changed files with 14 additions and 15 deletions

View File

@ -338,9 +338,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
this.sidebar.$element.show(); this.sidebar.$element.show();
} }
if (this.hidden) { if (this.hidden) {
this.$element.find('.oe-listview-content').append( this.reload_content();
this.groups.apoptosis().render());
this.hidden = false;
} }
}, },
do_hide: function () { do_hide: function () {
@ -378,7 +376,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
reload_content: function () { reload_content: function () {
this.records.reset(); this.records.reset();
this.$element.find('.oe-listview-content').append( this.$element.find('.oe-listview-content').append(
this.groups.apoptosis().render( this.groups.render(
$.proxy(this, 'compute_aggregates'))); $.proxy(this, 'compute_aggregates')));
}, },
/** /**
@ -626,6 +624,8 @@ openerp.base.ListView.List = openerp.base.Class.extend( /** @lends openerp.base.
this.dataset = opts.dataset; this.dataset = opts.dataset;
this.records = opts.records; this.records = opts.records;
this.records.bind('reset', $.proxy(this, 'on_records_reset'));
this.$_element = $('<tbody class="ui-widget-content">') this.$_element = $('<tbody class="ui-widget-content">')
.appendTo(document.body) .appendTo(document.body)
.delegate('th.oe-record-selector', 'click', function (e) { .delegate('th.oe-record-selector', 'click', function (e) {
@ -710,9 +710,9 @@ openerp.base.ListView.List = openerp.base.Class.extend( /** @lends openerp.base.
return this.records.at(this.row_position(row)).get('id'); return this.records.at(this.row_position(row)).get('id');
}, },
/** /**
* Death signal, cleans up list * Death signal, cleans up list display
*/ */
apoptosis: function () { on_records_reset: function (ev, records) {
if (!this.$current) { return; } if (!this.$current) { return; }
this.$current.remove(); this.$current.remove();
this.$current = null; this.$current = null;
@ -811,6 +811,8 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
this.children = {}; this.children = {};
this.page = 0; this.page = 0;
this.records.bind('reset', $.proxy(this, 'on_records_reset'));
}, },
make_fragment: function () { make_fragment: function () {
return document.createDocumentFragment(); return document.createDocumentFragment();
@ -871,7 +873,7 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
}, },
close: function () { close: function () {
this.$row.children().last().empty(); this.$row.children().last().empty();
this.apoptosis(); this.records.reset();
}, },
/** /**
* Prefixes ``$node`` with floated spaces in order to indent it relative * Prefixes ``$node`` with floated spaces in order to indent it relative
@ -892,7 +894,7 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
var placeholder = this.make_fragment(); var placeholder = this.make_fragment();
_(datagroups).each(function (group) { _(datagroups).each(function (group) {
if (self.children[group.value]) { if (self.children[group.value]) {
self.children[group.value].apoptosis(); self.records.proxy(group.value).reset();
delete self.children[group.value]; delete self.children[group.value];
} }
var child = self.children[group.value] = new openerp.base.ListView.Groups(self.view, { var child = self.children[group.value] = new openerp.base.ListView.Groups(self.view, {
@ -1025,7 +1027,7 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
.attr('disabled', page === pages - 1); .attr('disabled', page === pages - 1);
} }
self.records.reset(records); self.records.add(records);
list.render(); list.render();
d.resolve(list); d.resolve(list);
}); });
@ -1113,14 +1115,9 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
return {ids: ids, records: records}; return {ids: ids, records: records};
}, },
apoptosis: function () { on_records_reset: function () {
_(this.children).each(function (child) {
child.apoptosis();
});
this.children = {}; this.children = {};
$(this.elements).remove(); $(this.elements).remove();
this.records.reset();
return this;
}, },
get_records: function () { get_records: function () {
if (_(this.children).isEmpty()) { if (_(this.children).isEmpty()) {
@ -1368,6 +1365,8 @@ var Collection = openerp.base.Class.extend(/** @lends Collection# */{
}, },
_onRecordEvent: function (event, record, options) { _onRecordEvent: function (event, record, options) {
// don't propagate reset events
if (event === 'reset') { return; }
this.trigger.apply(this, arguments); this.trigger.apply(this, arguments);
}, },