[imp] added replace() method in Widget to ease insertion at a precise place in the dom

bzr revid: nicolas.vanhoren@openerp.com-20111122062431-zh762kivblfhwewk
This commit is contained in:
niv-openerp
2011-11-22 11:54:31 +05:30
parent 8301ca9e47
commit 452eca8952
+17 -7
View File
@@ -809,7 +809,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
*/
tag_name: 'div',
/**
* Construct the widget and set its parent if a parent is given.
* Constructs the widget and sets its parent if a parent is given.
*
* @constructs openerp.web.Widget
* @extends openerp.web.CallbackEnabled
@@ -841,7 +841,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
this.widget_is_stopped = false;
},
/**
* Render the current widget and appends it to the given jQuery object or Widget.
* Renders the current widget and appends it to the given jQuery object or Widget.
*
* @param target A jQuery object or a Widget instance.
*/
@@ -852,7 +852,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
}, target);
},
/**
* Render the current widget and prepends it to the given jQuery object or Widget.
* Renders the current widget and prepends it to the given jQuery object or Widget.
*
* @param target A jQuery object or a Widget instance.
*/
@@ -863,7 +863,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
}, target);
},
/**
* Render the current widget and inserts it after to the given jQuery object or Widget.
* Renders the current widget and inserts it after to the given jQuery object or Widget.
*
* @param target A jQuery object or a Widget instance.
*/
@@ -874,7 +874,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
}, target);
},
/**
* Render the current widget and inserts it before to the given jQuery object or Widget.
* Renders the current widget and inserts it before to the given jQuery object or Widget.
*
* @param target A jQuery object or a Widget instance.
*/
@@ -884,6 +884,16 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
self.$element.insertBefore(t);
}, target);
},
/**
* Renders the current widget and replaces the given jQuery object.
*
* @param target A jQuery object or a Widget instance.
*/
replace: function(target) {
return this._render_and_insert(_.bind(function(t) {
this.$element.replaceAll(t);
}, this), target);
},
_render_and_insert: function(insertion, target) {
this.render_element();
if (target instanceof openerp.web.Widget)
@@ -929,7 +939,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
return $.Deferred().done().promise();
},
/**
* Destroys the current widget, also destroy all its children before destroying itself.
* Destroys the current widget, also destroys all its children before destroying itself.
*/
stop: function() {
_.each(_.clone(this.widget_children), function(el) {
@@ -945,7 +955,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
this.widget_is_stopped = true;
},
/**
* Inform the action manager to do an action. Of course, this suppose that
* Informs the action manager to do an action. This supposes that
* the action manager can be found amongst the ancestors of the current widget.
* If that's not the case this method will simply return `false`.
*/