[IMP] use Class.include() in editable listview, also in WebClient static home extension

but not as good: this._super references break when used in async contexts as the this._super reference has already been broken by the time the callback executes

bzr revid: xmo@openerp.com-20110808103424-043a0ro0o7r390s7
This commit is contained in:
Xavier Morel 2011-08-08 12:34:24 +02:00
parent f130d1c374
commit dad68b79a7
2 changed files with 15 additions and 17 deletions

View File

@ -8,15 +8,11 @@ openerp.base.list.editable = function (openerp) {
// editability status of list rows
openerp.base.ListView.prototype.defaults.editable = null;
var old_init = openerp.base.ListView.prototype.init,
old_actual_search = openerp.base.ListView.prototype.do_actual_search,
old_add_record = openerp.base.ListView.prototype.do_add_record,
old_on_loaded = openerp.base.ListView.prototype.on_loaded;
// TODO: not sure second @lends on existing item is correct, to check
_.extend(openerp.base.ListView.prototype, /** @lends openerp.base.ListView# */{
openerp.base.ListView.include(/** @lends openerp.base.ListView# */{
init: function () {
var self = this;
old_init.apply(this, arguments);
this._super.apply(this, arguments);
$(this.groups).bind({
'edit': function (e, id, dataset) {
self.do_edit(dataset.index, id, dataset);
@ -63,7 +59,7 @@ openerp.base.list.editable = function (openerp) {
*/
do_actual_search: function (results) {
this.set_editable(results.context['set_editable']);
old_actual_search.call(this, results);
this._super(results);
},
/**
* Replace do_add_record to handle editability (and adding new record
@ -73,17 +69,17 @@ openerp.base.list.editable = function (openerp) {
if (this.options.editable) {
this.groups.new_record();
} else {
old_add_record.call(this);
this._super();
}
},
on_loaded: function (data, grouped) {
// tree/@editable takes priority on everything else if present.
this.options.editable = data.fields_view.arch.attrs.editable || this.options.editable;
return old_on_loaded.call(this, data, grouped);
return this._super(data, grouped);
}
});
_.extend(openerp.base.ListView.Groups.prototype, /** @lends openerp.base.ListView.Groups# */{
openerp.base.ListView.Groups.include(/** @lends openerp.base.ListView.Groups# */{
passtrough_events: openerp.base.ListView.Groups.prototype.passtrough_events + " edit saved",
new_record: function () {
// TODO: handle multiple children
@ -91,11 +87,10 @@ openerp.base.list.editable = function (openerp) {
}
});
var old_list_row_clicked = openerp.base.ListView.List.prototype.row_clicked;
_.extend(openerp.base.ListView.List.prototype, /** @lends openerp.base.ListView.List */{
openerp.base.ListView.List.include(/** @lends openerp.base.ListView.List */{
row_clicked: function (event) {
if (!this.options.editable) {
return old_list_row_clicked.call(this, event);
return this._super(event);
}
this.edit_record();
},

View File

@ -1,8 +1,6 @@
openerp.base_default_home = function (openerp) {
QWeb.add_template('/base_default_home/static/src/xml/base_default_home.xml');
var old_home = openerp.base.WebClient.prototype.default_home;
openerp.base_default_home = {
applications: [
[
@ -51,9 +49,14 @@ openerp.base_default_home = function (openerp) {
]
};
_.extend(openerp.base.WebClient.prototype, {
openerp.base.WebClient.include({
default_home: function () {
var self = this;
var self = this,
// resig class can't handle _super in async contexts, by the
// time async callback comes back, _super has already been
// reset to a baseline value of this.prototype (or something
// like that)
old_home = this._super;
var Installer = new openerp.base.DataSet(
this, 'base.setup.installer');
Installer.call('already_installed', [], function (installed_modules) {