From 1d488be821bc603bc796525480d9393fdf0d9dd7 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 17 Apr 2012 13:52:47 +0200 Subject: [PATCH] [imp] refactored corelib.js bzr revid: nicolas.vanhoren@openerp.com-20120417115247-an5dj09s7k1a2su0 --- addons/web/static/src/js/corelib.js | 126 ++++++++++++++-------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 2da804c3d2c..5475f4ad53c 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -23,7 +23,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -openerp.web.corelib = function(openerp) { +openerp.web.corelib = function(instance) { /** * Improved John Resig's inheritance, based on: @@ -39,7 +39,7 @@ openerp.web.corelib = function(openerp) { * * Example: * - * var Person = openerp.web.Class.extend({ + * var Person = instance.web.Class.extend({ * init: function(isDancing){ * this.dancing = isDancing; * }, @@ -75,14 +75,14 @@ openerp.web.corelib = function(openerp) { var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The web Class implementation (does nothing) - openerp.web.Class = function(){}; + instance.web.Class = function(){}; /** * Subclass an existing class * * @param {Object} prop class-level properties (class attributes and instance methods) to set on the new class */ - openerp.web.Class.extend = function() { + instance.web.Class.extend = function() { var _super = this.prototype; // Support mixins arguments var args = _.toArray(arguments); @@ -180,7 +180,7 @@ openerp.web.corelib = function(openerp) { * When an object is destroyed, all its children are destroyed too releasing * any resource they could have reserved before. */ -openerp.web.ParentedMixin = { +instance.web.ParentedMixin = { __parentedMixin : true, init: function() { this.__parentedDestroyed = false; @@ -253,7 +253,7 @@ openerp.web.ParentedMixin = { * events is done in EventDispatcherMixin. * */ -openerp.web.Events = openerp.web.Class.extend({ +instance.web.Events = instance.web.Class.extend({ on : function(events, callback, context) { var ev; @@ -324,11 +324,11 @@ openerp.web.Events = openerp.web.Class.extend({ } }); -openerp.web.EventDispatcherMixin = _.extend({}, openerp.web.ParentedMixin, { +instance.web.EventDispatcherMixin = _.extend({}, instance.web.ParentedMixin, { __eventDispatcherMixin: true, init: function() { - openerp.web.ParentedMixin.init.call(this); - this.__edispatcherEvents = new openerp.web.Events(); + instance.web.ParentedMixin.init.call(this); + this.__edispatcherEvents = new instance.web.Events(); this.__edispatcherRegisteredEvents = []; }, on: function(events, dest, func) { @@ -369,13 +369,13 @@ openerp.web.EventDispatcherMixin = _.extend({}, openerp.web.ParentedMixin, { debugger; } this.__edispatcherEvents.off(); - openerp.web.ParentedMixin.destroy.call(this); + instance.web.ParentedMixin.destroy.call(this); } }); -openerp.web.GetterSetterMixin = _.extend({}, openerp.web.EventDispatcherMixin, { +instance.web.GetterSetterMixin = _.extend({}, instance.web.EventDispatcherMixin, { init: function() { - openerp.web.EventDispatcherMixin.init.call(this); + instance.web.EventDispatcherMixin.init.call(this); this.__getterSetterInternalMap = {}; }, set: function(map) { @@ -400,9 +400,9 @@ openerp.web.GetterSetterMixin = _.extend({}, openerp.web.EventDispatcherMixin, { } }); -openerp.web.CallbackEnabledMixin = _.extend({}, openerp.web.GetterSetterMixin, { +instance.web.CallbackEnabledMixin = _.extend({}, instance.web.GetterSetterMixin, { init: function() { - openerp.web.GetterSetterMixin.init.call(this); + instance.web.GetterSetterMixin.init.call(this); var self = this; var callback_maker = function(obj, name, method) { var callback = function() { @@ -421,7 +421,7 @@ openerp.web.CallbackEnabledMixin = _.extend({}, openerp.web.GetterSetterMixin, { r = result; } // TODO special value to stop the chain - // openerp.web.callback_stop + // instance.web.callback_stop } return r; }; @@ -500,7 +500,7 @@ openerp.web.CallbackEnabledMixin = _.extend({}, openerp.web.GetterSetterMixin, { } }); -openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, { +instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { /** * Tag name when creating a default $element. * @type string @@ -509,10 +509,10 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, { /** * Constructs the widget and sets its parent if a parent is given. * - * @constructs openerp.web.Widget - * @extends openerp.web.CallbackEnabled + * @constructs instance.web.Widget + * @extends instance.web.CallbackEnabled * - * @param {openerp.web.Widget} parent Binds the current instance to the given Widget instance. + * @param {instance.web.Widget} parent Binds the current instance to the given Widget instance. * When that widget is destroyed by calling destroy(), the current instance will be * destroyed too. Can be null. * @param {String} element_id Deprecated. Sets the element_id. Only useful when you want @@ -521,7 +521,7 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, { * for new components this argument should not be provided any more. */ init: function(parent) { - openerp.web.CallbackEnabledMixin.init.call(this); + instance.web.CallbackEnabledMixin.init.call(this); this.$element = $(document.createElement(this.tagName)); this.setParent(parent); }, @@ -535,7 +535,7 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, { if(this.$element != null) { this.$element.remove(); } - openerp.web.GetterSetterMixin.destroy.call(this); + instance.web.GetterSetterMixin.destroy.call(this); }, /** * Renders the current widget and appends it to the given jQuery object or Widget. @@ -616,9 +616,9 @@ openerp.web.WidgetMixin = _.extend({},openerp.web.CallbackEnabledMixin, { // Classes -openerp.web.CallbackEnabled = openerp.web.Class.extend(openerp.web.CallbackEnabledMixin, { +instance.web.CallbackEnabled = instance.web.Class.extend(instance.web.CallbackEnabledMixin, { init: function() { - openerp.web.CallbackEnabledMixin.init.call(this); + instance.web.CallbackEnabledMixin.init.call(this); } }); @@ -637,7 +637,7 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(openerp.web.CallbackEnabl * * Here is a sample child class: * - * MyWidget = openerp.base.Widget.extend({ + * MyWidget = instance.base.Widget.extend({ * // the name of the QWeb template to use for rendering * template: "MyQWebTemplate", * @@ -670,7 +670,7 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(openerp.web.CallbackEnabl * * That will kill the widget in a clean way and erase its content from the dom. */ -openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, { +instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, { /** * The name of the QWeb template that will be used for rendering. Must be * redefined in subclasses or the default render() method can not be used. @@ -681,10 +681,10 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, { /** * Constructs the widget and sets its parent if a parent is given. * - * @constructs openerp.web.Widget - * @extends openerp.web.CallbackEnabled + * @constructs instance.web.Widget + * @extends instance.web.CallbackEnabled * - * @param {openerp.web.Widget} parent Binds the current instance to the given Widget instance. + * @param {instance.web.Widget} parent Binds the current instance to the given Widget instance. * When that widget is destroyed by calling destroy(), the current instance will be * destroyed too. Can be null. * @param {String} element_id Deprecated. Sets the element_id. Only useful when you want @@ -693,8 +693,8 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, { * for new components this argument should not be provided any more. */ init: function(parent) { - openerp.web.WidgetMixin.init.call(this,parent); - this.session = openerp.connection; + instance.web.WidgetMixin.init.call(this,parent); + this.session = instance.connection; }, /** * Renders the element. The default implementation renders the widget using QWeb, @@ -704,7 +704,7 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, { renderElement: function() { var rendered = null; if (this.template) - rendered = openerp.web.qweb.render(this.template, {widget: this}); + rendered = instance.web.qweb.render(this.template, {widget: this}); if (_.str.trim(rendered)) { var elem = $(rendered); this.$element.replaceWith(elem); @@ -737,7 +737,7 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, { rpc: function(url, data, success, error) { var def = $.Deferred().then(success, error); var self = this; - openerp.connection.rpc(url, data). then(function() { + instance.connection.rpc(url, data). then(function() { if (!self.isDestroyed()) def.resolve.apply(def, arguments); }, function() { @@ -748,7 +748,7 @@ openerp.web.Widget = openerp.web.Class.extend(openerp.web.WidgetMixin, { } }); -openerp.web.Registry = openerp.web.Class.extend({ +instance.web.Registry = instance.web.Class.extend({ /** * Stores a mapping of arbitrary key (strings) to object paths (as strings * as well). @@ -757,11 +757,11 @@ openerp.web.Registry = openerp.web.Class.extend({ * object, even if those objects have been overloaded/replaced after the * registry was created. * - * An object path is simply a dotted name from the openerp root to the - * object pointed to (e.g. ``"openerp.web.Connection"`` for an OpenERP + * An object path is simply a dotted name from the instance root to the + * object pointed to (e.g. ``"instance.web.Connection"`` for an OpenERP * connection object). * - * @constructs openerp.web.Registry + * @constructs instance.web.Registry * @param {Object} mapping a mapping of keys to object-paths */ init: function (mapping) { @@ -785,7 +785,7 @@ openerp.web.Registry = openerp.web.Class.extend({ return null; } - var object_match = openerp; + var object_match = instance; var path = path_string.split('.'); // ignore first section for(var i=1; i