summaryrefslogtreecommitdiff
path: root/addons/base/static
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2011-03-30 10:48:35 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2011-03-30 10:48:35 +0200
commitab56c9a9aee16fea4beae01e10bc401c2e105ecf (patch)
tree6af0cab78ba5ac0e8204bbac57d484a9791ca663 /addons/base/static
parent408b9e64bb0dac5d1392b3934ab36f708a90d724 (diff)
parentd438b37475b54e8fff822f6b73ebb72a82f4e185 (diff)
[MERGE] Little improvement to BaseWidget.
bzr revid: nicolas.vanhoren@openerp.com-20110330084835-arzwrgcucsxepi5z
Diffstat (limited to 'addons/base/static')
-rw-r--r--addons/base/static/openerp/js/base_views.js29
1 files changed, 19 insertions, 10 deletions
diff --git a/addons/base/static/openerp/js/base_views.js b/addons/base/static/openerp/js/base_views.js
index f28e4f8204d..99888b472b4 100644
--- a/addons/base/static/openerp/js/base_views.js
+++ b/addons/base/static/openerp/js/base_views.js
@@ -419,10 +419,8 @@ openerp.base.BaseWidget = openerp.base.Controller.extend({
*/
init: function (parent) {
this.children = [];
- this.parent = parent;
- if(parent != null) {
- parent.children.push(this);
- }
+ this.parent = null;
+ this.set_parent(parent);
this.make_id(this.identifier_prefix);
},
/**
@@ -443,7 +441,7 @@ openerp.base.BaseWidget = openerp.base.Controller.extend({
start: function () {
this._super();
var tmp = document.getElementById(this.element_id)
- this.$element = tmp != null ? $(tmp) : null;
+ this.$element = tmp ? $(tmp) : null;
},
/**
* "Stops" the widgets. Called when the view destroys itself, this
@@ -458,14 +456,25 @@ openerp.base.BaseWidget = openerp.base.Controller.extend({
if(this.$element != null) {
this.$element.remove();
}
- if(this.parent != null) {
- var _this = this;
- this.parent.children = _.reject(this.parent.children, function(x) { return x === _this;});
- this.parent = null;
- }
+ this.set_parent(null);
this._super();
},
/**
+ * Set the parent of this component, also unregister the previous parent if there
+ * was one.
+ *
+ * @param {openerp.base.BaseWidget} parent The new parent.
+ */
+ set_parent: function(parent) {
+ if(this.parent) {
+ this.parent.children = _.without(this.parent.children, this);
+ }
+ this.parent = parent;
+ if(this.parent) {
+ parent.children.push(this);
+ }
+ },
+ /**
* Render the widget. This.template must be defined.
* The content of the current object is passed as context to the template.
*