diff options
| author | Xavier Morel <xmo@openerp.com> | 2012-07-26 16:48:17 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2012-07-26 16:48:17 +0200 |
| commit | 5c0324f3214d95c3a2d34db7d6d145700501c762 (patch) | |
| tree | c5168a8e72964971bdac936888f2ce2478ab34ce /addons/web/static/src/js/corelib.js | |
| parent | a9ccdfae0305afa988284e59dc1a81694e0a26e3 (diff) | |
[IMP] Widget#setElement from init to reinstate $element always being there
That makes precious little sense, but a bunch of widgets actually
expect $element to exist before start() has been called.
Also extract creating a node from the widget's node description into a
private method, use that where possible.
bzr revid: xmo@openerp.com-20120726144817-20caa8jkvg39ycho
Diffstat (limited to 'addons/web/static/src/js/corelib.js')
| -rw-r--r-- | addons/web/static/src/js/corelib.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index b80543a34d8..3fafcab26fb 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -514,6 +514,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { */ init: function(parent) { instance.web.CallbackEnabledMixin.init.call(this); + this.setElement(this._make_descriptive()); this.setParent(parent); }, /** @@ -701,10 +702,7 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, { $el = $(_.str.trim(instance.web.qweb.render( this.template, {widget: this}))); } else { - var attrs = _.extend({}, this.attributes || {}); - if (this.id) { attrs.id = this.id; } - if (this.className) { attrs['class'] = this.className; } - $el = $(this.make(this.tagName, attrs)); + $el = this._make_descriptive(); } this.replaceElement($el); }, @@ -737,6 +735,8 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, { * @return {*} this */ setElement: function (element) { + // NB: completely useless, as WidgetMixin#init creates a $element + // always if (this.$element) { this.undelegateEvents(); } @@ -766,6 +766,19 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, { } return el; }, + /** + * Makes a potential root element from the declarative builder of the + * widget + * + * @return {jQuery} + * @private + */ + _make_descriptive: function () { + var attrs = _.extend({}, this.attributes || {}); + if (this.id) { attrs.id = this.id; } + if (this.className) { attrs['class'] = this.className; } + return $(this.make(this.tagName, attrs)); + }, delegateEvents: function () { var events = this.events; if (_.isEmpty(events)) { return; } |
