diff options
Diffstat (limited to 'addons/base/static/src/js/controller.js')
| -rw-r--r-- | addons/base/static/src/js/controller.js | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/addons/base/static/src/js/controller.js b/addons/base/static/src/js/controller.js index a5c7bca4b53..c9ca3193e70 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 @@ -174,6 +200,12 @@ instance.base.BasicController = instance.base.Class.extend( /** @lends instance. return $.Deferred().done().promise(); }, stop: function() { + if (this.parent && this.parent.children) { + this.parent.children = _.without(this.parent.children, this); + this.parent.controller_children = this.parent.children; + } + this.parent = null; + this.controller_parent = null; }, log: function() { var args = Array.prototype.slice.call(arguments); |
