[CHG] rename this. to this.

because why make things simple when you can make them fucked up

bzr revid: xmo@openerp.com-20120726075359-b0uvuuagrfsf7nhb
This commit is contained in:
Xavier Morel 2012-07-26 09:53:59 +02:00
parent 0924a29e7a
commit d304f9fbb7
3 changed files with 39 additions and 39 deletions

View File

@ -523,8 +523,8 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
_.each(this.getChildren(), function(el) { _.each(this.getChildren(), function(el) {
el.destroy(); el.destroy();
}); });
if(this.$el) { if(this.$element) {
this.$el.remove(); this.$element.remove();
} }
instance.web.PropertiesMixin.destroy.call(this); instance.web.PropertiesMixin.destroy.call(this);
}, },
@ -536,7 +536,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
appendTo: function(target) { appendTo: function(target) {
var self = this; var self = this;
return this.__widgetRenderAndInsert(function(t) { return this.__widgetRenderAndInsert(function(t) {
self.$el.appendTo(t); self.$element.appendTo(t);
}, target); }, target);
}, },
/** /**
@ -547,7 +547,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
prependTo: function(target) { prependTo: function(target) {
var self = this; var self = this;
return this.__widgetRenderAndInsert(function(t) { return this.__widgetRenderAndInsert(function(t) {
self.$el.prependTo(t); self.$element.prependTo(t);
}, target); }, target);
}, },
/** /**
@ -558,7 +558,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
insertAfter: function(target) { insertAfter: function(target) {
var self = this; var self = this;
return this.__widgetRenderAndInsert(function(t) { return this.__widgetRenderAndInsert(function(t) {
self.$el.insertAfter(t); self.$element.insertAfter(t);
}, target); }, target);
}, },
/** /**
@ -569,7 +569,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
insertBefore: function(target) { insertBefore: function(target) {
var self = this; var self = this;
return this.__widgetRenderAndInsert(function(t) { return this.__widgetRenderAndInsert(function(t) {
self.$el.insertBefore(t); self.$element.insertBefore(t);
}, target); }, target);
}, },
/** /**
@ -579,7 +579,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
*/ */
replace: function(target) { replace: function(target) {
return this.__widgetRenderAndInsert(_.bind(function(t) { return this.__widgetRenderAndInsert(_.bind(function(t) {
this.$el.replaceAll(t); this.$element.replaceAll(t);
}, this), target); }, this), target);
}, },
__widgetRenderAndInsert: function(insertion, target) { __widgetRenderAndInsert: function(insertion, target) {
@ -717,10 +717,10 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, {
* @returns {*} this * @returns {*} this
*/ */
replaceElement: function ($el) { replaceElement: function ($el) {
var $oldel = this.$el; var $oldel = this.$element;
this.setElement($el); this.setElement($el);
if ($oldel && !$oldel.is(this.$el)) { if ($oldel && !$oldel.is(this.$element)) {
$oldel.replaceWith(this.$el); $oldel.replaceWith(this.$element);
} }
return this; return this;
}, },
@ -737,12 +737,12 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, {
* @return {*} this * @return {*} this
*/ */
setElement: function (element) { setElement: function (element) {
if (this.$el) { if (this.$element) {
this.undelegateEvents(); this.undelegateEvents();
} }
this.$element = this.$el = (element instanceof $) ? element : $(element); this.$element = (element instanceof $) ? element : $(element);
this.el = this.$el[0]; this.el = this.$element[0];
this.delegateEvents(); this.delegateEvents();
@ -781,23 +781,23 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, {
event += '.widget_events'; event += '.widget_events';
if (!selector) { if (!selector) {
this.$el.on(event, method); this.$element.on(event, method);
} else { } else {
this.$el.on(event, selector, method); this.$element.on(event, selector, method);
} }
} }
}, },
undelegateEvents: function () { undelegateEvents: function () {
this.$el.off('.widget_events'); this.$element.off('.widget_events');
}, },
/** /**
* Shortcut for ``this.$el.find(selector)`` * Shortcut for ``this.$element.find(selector)``
* *
* @param {String} selector CSS selector, rooted in $el * @param {String} selector CSS selector, rooted in $el
* @returns {jQuery} selector match * @returns {jQuery} selector match
*/ */
$: function(selector) { $: function(selector) {
return this.$el.find(selector); return this.$element.find(selector);
}, },
/** /**
* Informs the action manager to do an action. This supposes that * Informs the action manager to do an action. This supposes that

View File

@ -86,15 +86,15 @@ $(document).ready(function () {
test('no template, default', function () { test('no template, default', function () {
var w = new (instance.web.Widget.extend({ })); var w = new (instance.web.Widget.extend({ }));
ok(!w.$el, "should not initially have a root element"); ok(!w.$element, "should not initially have a root element");
w.renderElement(); w.renderElement();
ok(w.$el, "should have generated a root element"); ok(w.$element, "should have generated a root element");
strictEqual(w.$element, w.$el, "should provide $element alias"); strictEqual(w.$element, w.$element, "should provide $element alias");
ok(w.$el.is(w.el), "should provide raw DOM alias"); ok(w.$element.is(w.el), "should provide raw DOM alias");
equal(w.el.nodeName, 'DIV', "should have generated the default element"); equal(w.el.nodeName, 'DIV', "should have generated the default element");
equal(w.el.attributes.length, 0, "should not have generated any attribute"); equal(w.el.attributes.length, 0, "should not have generated any attribute");
ok(_.isEmpty(w.$el.html(), "should not have generated any content")); ok(_.isEmpty(w.$element.html(), "should not have generated any content"));
}); });
test('no template, custom tag', function () { test('no template, custom tag', function () {
var w = new (instance.web.Widget.extend({ var w = new (instance.web.Widget.extend({
@ -111,7 +111,7 @@ $(document).ready(function () {
w.renderElement(); w.renderElement();
equal(w.el.attributes.length, 1, "should have one attribute"); equal(w.el.attributes.length, 1, "should have one attribute");
equal(w.$el.attr('id'), 'foo', "should have generated the id attribute"); equal(w.$element.attr('id'), 'foo', "should have generated the id attribute");
equal(w.el.id, 'foo', "should also be available via property"); equal(w.el.id, 'foo', "should also be available via property");
}); });
test('no template, @className', function () { test('no template, @className', function () {
@ -121,7 +121,7 @@ $(document).ready(function () {
w.renderElement(); w.renderElement();
equal(w.el.className, 'oe_some_class', "should have the right property"); equal(w.el.className, 'oe_some_class', "should have the right property");
equal(w.$el.attr('class'), 'oe_some_class', "should have the right attribute"); equal(w.$element.attr('class'), 'oe_some_class', "should have the right attribute");
}); });
test('no template, bunch of attributes', function () { test('no template, bunch of attributes', function () {
var w = new (instance.web.Widget.extend({ var w = new (instance.web.Widget.extend({
@ -138,16 +138,16 @@ $(document).ready(function () {
equal(w.el.attributes.length, 5, "should have all the specified attributes"); equal(w.el.attributes.length, 5, "should have all the specified attributes");
equal(w.el.id, 'some_id'); equal(w.el.id, 'some_id');
equal(w.$el.attr('id'), 'some_id'); equal(w.$element.attr('id'), 'some_id');
equal(w.el.className, 'some_class'); equal(w.el.className, 'some_class');
equal(w.$el.attr('class'), 'some_class'); equal(w.$element.attr('class'), 'some_class');
equal(w.$el.attr('data-foo'), 'data attribute'); equal(w.$element.attr('data-foo'), 'data attribute');
equal(w.$el.data('foo'), 'data attribute'); equal(w.$element.data('foo'), 'data attribute');
equal(w.$el.attr('clark'), 'gable'); equal(w.$element.attr('clark'), 'gable');
equal(w.$el.attr('spoiler'), 'snape kills dumbledore'); equal(w.$element.attr('spoiler'), 'snape kills dumbledore');
}); });
test('template', function () { test('template', function () {
@ -157,7 +157,7 @@ $(document).ready(function () {
w.renderElement(); w.renderElement();
equal(w.el.nodeName, 'OL'); equal(w.el.nodeName, 'OL');
equal(w.$el.children().length, 5); equal(w.$element.children().length, 5);
equal(w.el.textContent, '01234'); equal(w.el.textContent, '01234');
}); });
@ -168,7 +168,7 @@ $(document).ready(function () {
})); }));
w.renderElement(); w.renderElement();
ok(w.$('li:eq(3)').is(w.$el.find('li:eq(3)')), ok(w.$('li:eq(3)').is(w.$element.find('li:eq(3)')),
"should do the same thing as calling find on the widget root"); "should do the same thing as calling find on the widget root");
}); });
@ -189,7 +189,7 @@ $(document).ready(function () {
})); }));
w.renderElement(); w.renderElement();
w.$el.click(); w.$element.click();
w.$('li:eq(3)').click(); w.$('li:eq(3)').click();
w.$('input:last').val('foo').change(); w.$('input:last').val('foo').change();
@ -204,7 +204,7 @@ $(document).ready(function () {
events: { 'click li': function () { clicked = true; } } events: { 'click li': function () { clicked = true; } }
})); }));
w.renderElement(); w.renderElement();
w.$el.on('click', 'li', function () { newclicked = true }); w.$element.on('click', 'li', function () { newclicked = true });
w.$('li').click(); w.$('li').click();
ok(clicked, "should trigger bound events"); ok(clicked, "should trigger bound events");
@ -227,11 +227,11 @@ $(document).ready(function () {
.always(start) .always(start)
.done(function () { .done(function () {
equal($fix.find('p').text(), '42', "DOM fixture should contain initial value"); equal($fix.find('p').text(), '42', "DOM fixture should contain initial value");
equal(w.$el.text(), '42', "should set initial value"); equal(w.$element.text(), '42', "should set initial value");
w.value = 36; w.value = 36;
w.renderElement(); w.renderElement();
equal($fix.find('p').text(), '36', "DOM fixture should use new value"); equal($fix.find('p').text(), '36', "DOM fixture should use new value");
equal(w.$el.text(), '36', "should set new value"); equal(w.$element.text(), '36', "should set new value");
}); });
}); });
}); });

View File

@ -39,14 +39,14 @@ DOM Root
A :js:class:`~openerp.web.Widget` is responsible for a section of the A :js:class:`~openerp.web.Widget` is responsible for a section of the
page materialized by the DOM root of the widget. The DOM root is page materialized by the DOM root of the widget. The DOM root is
available via the :js:attr:`~openerp.web.Widget.el` and available via the :js:attr:`~openerp.web.Widget.el` and
:js:attr:`~openerp.web.Widget.$el` attributes, which are respectively :js:attr:`~openerp.web.Widget.$element` attributes, which are respectively
the raw DOM Element and the jQuery wrapper around the DOM element. the raw DOM Element and the jQuery wrapper around the DOM element.
.. note:: .. note::
both attributes are compatible with Backbone's equivalent, there both attributes are compatible with Backbone's equivalent, there
is also the :js:attr:`~openerp.web.Widget.$element` attribute is also the :js:attr:`~openerp.web.Widget.$element` attribute
which aliases to :js:attr:`~openerp.web.Widget.$el` and remains which aliases to :js:attr:`~openerp.web.Widget.$element` and remains
for backwards compatiblity reasons. for backwards compatiblity reasons.
There are two main ways to define and generate this DOM root: There are two main ways to define and generate this DOM root: