[imp] cosmetic changes

bzr revid: nicolas.vanhoren@openerp.com-20120221155806-e6efydx5k7qtppdn
This commit is contained in:
niv-openerp 2012-02-21 16:58:06 +01:00
parent 7fcfcbaddb
commit 4ee34acbbe
2 changed files with 37 additions and 18 deletions

View File

@ -93,9 +93,28 @@ niv = (function() {
niv.ParentedMixin = {
__parented_mixin: true,
setParent: function(parent) {
if(this.getParent()) {
if (this.getParent().__parented_mixin) {
this.getParent().__parented_children = _.without(this.getParent().getChildren(), this);
}
this.__parented_parent = undefined;
}
this.__parented_parent = parent;
if(parent && parent.__parented_mixin) {
if (!parent.getChildren())
parent.__parented_children = [];
parent.getChildren().push(this);
}
},
getParent: function() {
return this.__parented_parent;
},
getChildren: function() {
return this.__parented_children || [];
},
isDestroyed: function() {
return this.__parented_stopped;
}
};
return niv;

View File

@ -1029,9 +1029,22 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
getChildren: function() {
return this.__parented_children || [];
},
isStopped: function() {
isDestroyed: function() {
return this.__parented_stopped;
},
/**
* Destroys the current widget, also destroys all its children before destroying itself.
*/
stop: function() {
_.each(_.clone(this.getChildren()), function(el) {
el.stop();
});
if(this.$element != null) {
this.$element.remove();
}
this.setParent(undefined);
this.__parented_stopped = true;
},
/**
* Renders the current widget and appends it to the given jQuery object or Widget.
*
@ -1122,19 +1135,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
start: function() {
return $.Deferred().done().promise();
},
/**
* Destroys the current widget, also destroys all its children before destroying itself.
*/
stop: function() {
_.each(_.clone(this.getChildren()), function(el) {
el.stop();
});
if(this.$element != null) {
this.$element.remove();
}
this.setParent(undefined);
this.__parented_stopped = true;
},
/**
* Informs the action manager to do an action. This supposes that
* the action manager can be found amongst the ancestors of the current widget.
@ -1163,10 +1163,10 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
var def = $.Deferred().then(success, error);
var self = this;
openerp.connection.rpc(url, data). then(function() {
if (!self.isStopped())
if (!self.isDestroyed())
def.resolve.apply(def, arguments);
}, function() {
if (!self.isStopped())
if (!self.isDestroyed())
def.reject.apply(def, arguments);
});
return def.promise();