From 4ee34acbbec49b6de11b1ef0843b4e6605d60227 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 21 Feb 2012 16:58:06 +0100 Subject: [PATCH] [imp] cosmetic changes bzr revid: nicolas.vanhoren@openerp.com-20120221155806-e6efydx5k7qtppdn --- addons/web/static/lib/nivjs/src/niv.js | 23 ++++++++++++++++-- addons/web/static/src/js/core.js | 32 +++++++++++++------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/addons/web/static/lib/nivjs/src/niv.js b/addons/web/static/lib/nivjs/src/niv.js index daa49397754..bd6ff897895 100644 --- a/addons/web/static/lib/nivjs/src/niv.js +++ b/addons/web/static/lib/nivjs/src/niv.js @@ -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; diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 9e9e01428ba..992c7fef83c 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -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();