diff options
| author | Yogesh (OpenERP) <ysa@tinyerp.com> | 2011-07-22 19:03:49 +0530 |
|---|---|---|
| committer | Yogesh (OpenERP) <ysa@tinyerp.com> | 2011-07-22 19:03:49 +0530 |
| commit | ebcb50bc9d7da1a9089900a0eb91614649e9f0fe (patch) | |
| tree | b8f3f32fa1c89e4d429f695a2c0f2f51ec9d4c1a /addons/base/static/src/js/controller.js | |
| parent | 7ff6fafdaf7e665fd29ba6ba55bb76c3088e45ea (diff) | |
| parent | 50180134f12e77e048acc20cae034eacd0b2e6e0 (diff) | |
[MERGE] Merge With Trunk
bzr revid: ysa@tinyerp.com-20110722133349-izodauajpwgoxhgd
Diffstat (limited to 'addons/base/static/src/js/controller.js')
| -rw-r--r-- | addons/base/static/src/js/controller.js | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/addons/base/static/src/js/controller.js b/addons/base/static/src/js/controller.js index a5c7bca4b53..1a100b6cc75 100644 --- a/addons/base/static/src/js/controller.js +++ b/addons/base/static/src/js/controller.js @@ -66,7 +66,7 @@ openerp.base.controller = function(instance) { return Class; }; -})(instance.base); +})(); // todo change john resig class to keep window clean instance.base.Class = window.Class @@ -121,14 +121,39 @@ instance.base.callback = function(obj, method) { }; /** + * Generates an inherited class that replaces all the methods by null methods (methods + * that does nothing and always return undefined). + * + * @param {Class} claz + * @param {dict} add Additional functions to override. + * @return {Class} + */ +instance.base.generate_null_object_class = function(claz, add) { + var newer = {}; + var copy_proto = function(prototype) { + for (var name in prototype) { + if(typeof prototype[name] == "function") { + newer[name] = function() {}; + } + } + if (prototype.prototype) + copy_proto(prototype.prototype); + }; + copy_proto(claz.prototype); + newer.init = instance.base.Controller.prototype.init; + var tmpclass = claz.extend(newer); + return tmpclass.extend(add || {}); +}; + +/** * OpenERP Controller + * TODO merge BaseWidget with Controller */ -instance.base.BasicController = instance.base.Class.extend( /** @lends instance.base.BasicController# */{ +instance.base.Controller = instance.base.Class.extend( /** @lends instance.base.Controller# */{ /** + * @constructs * rpc operations, event binding and callback calling should be done in - * start() instead of init so that event can be hooked in between. - * - * @constructs + * start() instead of init so that events can be hooked in between. */ init: function(parent, element_id) { this.element_id = element_id; @@ -137,12 +162,14 @@ instance.base.BasicController = instance.base.Class.extend( /** @lends instance. instance.screen[element_id] = this; } // save the parent children relationship - this.controller_parent = null; + this.controller_parent = parent; this.controller_children = []; - this.parent = parent; - if(this.parent && this.parent.children) { - this.parent.children.push(this); + if(parent && parent.controller_children) { + parent.controller_children.push(this); } + // backward compatibility + this.parent = this.controller_parent; + this.children = this.controller_children; // Transform on_* method into openerp.base.callbacks for (var name in this) { @@ -156,9 +183,8 @@ instance.base.BasicController = instance.base.Class.extend( /** @lends instance. } }, /** - * Controller start - * event binding, rpc and callback calling required to initialize the - * object can happen here + * Event binding, rpc and callback calling required to initialize the + * object should happen here * * Returns a promise object letting callers (subclasses and direct callers) * know when this component is done starting |
