diff --git a/addons/base/static/src/js/base.js b/addons/base/static/src/js/base.js index 8f9921ceeae..675476879cf 100644 --- a/addons/base/static/src/js/base.js +++ b/addons/base/static/src/js/base.js @@ -76,6 +76,10 @@ /** @lends openerp */ var openerp = this.openerp = { + /** + * Debug flag turns on logging + */ + debug: true, // element_ids registry linked to all controllers on the page // TODO rename to elements, or keep gtk naming? screen: {}, diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index cdfa1f4d192..920973e640a 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -193,8 +193,6 @@ openerp.base.BasicController = Class.extend( /** @lends openerp.base.BasicContro // try to call deferred methods on this return value. return $.Deferred().done().promise(); }, - on_ready: function() { - }, stop: function() { }, log: function() { @@ -206,20 +204,55 @@ openerp.base.BasicController = Class.extend( /** @lends openerp.base.BasicContro this.on_log.apply(this,args); }, on_log: function() { - if(true || window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) { + if(window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) { + var notify = false; + var body = false; if(window.console) { console.log(arguments); } else { - $.each(arguments, function(i,v) { - v = v==null ? "null" : v; - $('
').text(v.toString()).appendTo($('body'));
-                });
+                body = true;
+            }
+            var a = Array.prototype.slice.call(arguments, 0);
+            for(var i = 0; i < a.length; i++) {
+                var v = a[i]==null ? "null" : a[i].toString();
+                if(i==0) {
+                    notify = v.match(/^not/);
+                    body = v.match(/^bod/);
+                }
+                if(body) {
+                    $('
').text(v).appendTo($('body'));
+                }
+                if(notify && this.notification) {
+                    this.notification.notify("Logging:",v);
+                }
             }
         }
 
     }
 });
 
+openerp.base.Notification =  openerp.base.BasicController.extend({
+    init: function(element_id) {
+        this._super(element_id);
+        this.$element.notify({
+            speed: 500,
+            expires: 1500
+        });
+    },
+    notify: function(title, text) {
+        this.$element.notify('create', {
+            title: title,
+            text: text
+        });
+    },
+    warn: function(title, text) {
+        this.$element.notify('create', 'oe_notification_alert', {
+            title: title,
+            text: text
+        });
+    }
+});
+
 openerp.base.Session = openerp.base.BasicController.extend( /** @lends openerp.base.Session# */{
     /**
      * @constructs
@@ -446,18 +479,89 @@ 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: null,
+        template: "",
+        element_post_prefix: false,
+    },
+    /**
+     * Controller registry, 
+     */
+    controller_registry: {
+    },
+    /**
+     * Add a new child controller
+     */
+    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(session, element_id) {
+    init: function(parent_or_session, element_id) {
         this._super(element_id);
-        this.session = session;
-    },
-    on_log: function() {
-        if(this.session)
-            this.session.log.apply(this.session,arguments);
+        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