From a2c60d598c1faa09edaa0d53f362e21732fab6ab Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Sun, 10 Apr 2011 02:12:22 +0200 Subject: [PATCH] controller rework based on niv widget and xmo registry part1 bzr revid: al@openerp.com-20110410001222-pxar6n4szuy1zvzv --- addons/base/static/src/js/chrome.js | 190 +++++++++++++++++++++++++--- addons/base/static/src/js/views.js | 92 -------------- 2 files changed, 170 insertions(+), 112 deletions(-) diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 67d829c2e54..b26dccffb2e 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -484,30 +484,17 @@ openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.b } }); +// A controller takes an already existing element +// new() +// start() openerp.base.Controller = openerp.base.BasicController.extend( /** @lends openerp.base.Controller# */{ /** * Controller manifest used to declare standard controller attributes */ controller_manifest: { - register: [ "FormView.widget.char" ], + register: null, template: "", - elementpost: false, - }, - /** - * @constructs - * @extends openerp.base.BasicController - */ - init: function(parent_or_session, element_id) { - this._super(element_id); - // TODO migrate for backward compat - if(parent_or_session) { - if(parent_or_session.session) { - this.parent = parent_or_session; - } else { - this.session = parent_or_session; - } - - } + element_post_prefix: false, }, /** * Controller registry, @@ -517,8 +504,69 @@ openerp.base.Controller = openerp.base.BasicController.extend( /** @lends opener /** * Add a new child controller */ - controller_add: function(key,element_id) { - var obj = ""; + controller_get: function(key) { + return this.controller_registry[key]; + // OR should contrustct it ? setting parent correctly ? + // function construct(constructor, args) { + // function F() { + // return constructor.apply(this, args); + // } + // F.prototype = constructor.prototype; + // return new F(); + // } + // var obj = this.controller_registry[key]; + // if(obj) { + // return construct(obj, Array.prototype.slice.call(arguments, 1)); + // } + }, + controller_new: function(key) { + var self; + // OR should contrustct it ? setting parent correctly ? + function construct(constructor, args) { + function F() { + return constructor.apply(this, args); + } + F.prototype = constructor.prototype; + return new F(); + } + var obj = this.controller_registry[key]; + if(obj) { + // TODO Prepend parent + return construct(obj, Array.prototype.slice.call(arguments, 1)); + } + }, + /** + * @constructs + * @extends openerp.base.BasicController + */ + init: function(parent_or_session, element_id) { + this._super(element_id); + this.controller_parent = null; + this.controller_children = []; + if(parent_or_session) { + if(parent_or_session.session) { + this.parent = parent_or_session; + this.session = this.parent.session; + if(this.parent.children) { + this.parent.children.push(this); + } + } else { + // TODO remove Backward compatilbility + this.session = parent_or_session; + } + } + // Apply manifest options + if(this.controller_manifest) { + var register = this.controller_manifest.register; + // TODO accept a simple string + if(register) { + for(var i=0; i