From ed5097650b236bbd7bb4b96690258a9dbfb9d2c9 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Thu, 18 Aug 2011 21:53:49 +0200 Subject: [IMP] more production mode move Session above session aware, jquery ui css is not absolute bzr revid: al@openerp.com-20110818195349-zebyew12sefo93ml --- addons/base/static/src/js/core.js | 800 +++++++++++++++++++------------------- 1 file changed, 399 insertions(+), 401 deletions(-) (limited to 'addons/base/static/src/js/core.js') diff --git a/addons/base/static/src/js/core.js b/addons/base/static/src/js/core.js index 96c6cb1372a..58d19de9008 100644 --- a/addons/base/static/src/js/core.js +++ b/addons/base/static/src/js/core.js @@ -320,299 +320,6 @@ openerp.base.CallbackEnabled = openerp.base.Class.extend({ } }); -/** - * Utility class that any class is allowed to extend to easy common manipulations. - * - * It provides rpc calls, callback on all methods preceded by "on_" or "do_" and a - * logging facility. - */ -openerp.base.SessionAware = openerp.base.CallbackEnabled.extend({ - init: function(session) { - this._super(); - this.session = session; - }, - /** - * Performs a JSON-RPC call - * - * @param {String} url endpoint url - * @param {Object} data RPC parameters - * @param {Function} success RPC call success callback - * @param {Function} error RPC call error callback - * @returns {jQuery.Deferred} deferred object for the RPC call - */ - rpc: function(url, data, success, error) { - return this.session.rpc(url, data, success, error); - }, - log: function() { - var args = Array.prototype.slice.call(arguments); - var caller = arguments.callee.caller; - // TODO add support for line number using - // https://github.com/emwendelin/javascript-stacktrace/blob/master/stacktrace.js - // args.unshift("" + caller.debug_name); - this.on_log.apply(this,args); - }, - on_log: function() { - if(window.openerp.debug || (window.location.search.indexOf('?debug') !== -1)) { - var notify = false; - var body = false; - if(window.console) { - console.log(arguments); - } else { - 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.Widget = openerp.base.SessionAware.extend({
-    /**
-     * 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.
-     *
-     * @type string
-     */
-    template: null,
-    /**
-     * The prefix used to generate an id automatically. Should be redefined in
-     * subclasses. If it is not defined, a generic identifier will be used.
-     *
-     * @type string
-     */
-    identifier_prefix: 'generic-identifier-',
-    /**
-     * Construct the widget and set its parent if a parent is given.
-     *
-     * @constructs
-     * @param {openerp.base.Widget} parent Binds the current instance to the given Widget instance.
-     * When that widget is destroyed by calling stop(), the current instance will be
-     * destroyed too. Can be null.
-     * @param {String} element_id Deprecated. Sets the element_id. Only useful when you want
-     * to bind the current Widget to an already existing part of the DOM, which is not compatible
-     * with the DOM insertion methods provided by the current implementation of Widget. So
-     * for new components this argument should not be provided any more.
-     */
-    init: function(parent, /** @deprecated */ element_id) {
-        this._super((parent || {}).session);
-        // if given an element_id, try to get the associated DOM element and save
-        // a reference in this.$element. Else just generate a unique identifier.
-        this.element_id = element_id;
-        this.element_id = this.element_id || _.uniqueId(this.identifier_prefix);
-        var tmp = document.getElementById(this.element_id);
-        this.$element = tmp ? $(tmp) : undefined;
-
-        this.widget_parent = parent;
-        this.widget_children = [];
-        if(parent && parent.widget_children) {
-            parent.widget_children.push(this);
-        }
-        // useful to know if the widget was destroyed and should not be used anymore
-        this.widget_is_stopped = false;
-    },
-    /**
-     * Render the current widget and appends it to the given jQuery object or Widget.
-     *
-     * @param target A jQuery object or a Widget instance.
-     */
-    appendTo: function(target) {
-        var self = this;
-        return this._render_and_insert(function(t) {
-            self.$element.appendTo(t);
-        }, target);
-    },
-    /**
-     * Render the current widget and prepends it to the given jQuery object or Widget.
-     *
-     * @param target A jQuery object or a Widget instance.
-     */
-    prependTo: function(target) {
-        var self = this;
-        return this._render_and_insert(function(t) {
-            self.$element.prependTo(t);
-        }, target);
-    },
-    /**
-     * Render the current widget and inserts it after to the given jQuery object or Widget.
-     *
-     * @param target A jQuery object or a Widget instance.
-     */
-    insertAfter: function(target) {
-        var self = this;
-        return this._render_and_insert(function(t) {
-            self.$element.insertAfter(t);
-        }, target);
-    },
-    /**
-     * Render the current widget and inserts it before to the given jQuery object or Widget.
-     *
-     * @param target A jQuery object or a Widget instance.
-     */
-    insertBefore: function(target) {
-        var self = this;
-        return this._render_and_insert(function(t) {
-            self.$element.insertBefore(t);
-        }, target);
-    },
-    _render_and_insert: function(insertion, target) {
-        var rendered = this.render();
-        this.$element = $(rendered);
-        if (target instanceof openerp.base.Widget)
-            target = target.$element;
-        insertion(target);
-        return this.start();
-    },
-    /**
-     * Renders the widget using QWeb, `this.template` must be defined.
-     * The context given to QWeb contains the "widget" key that references `this`.
-     *
-     * @param {Object} additional Additional context arguments to pass to the template.
-     */
-    render: function (additional) {
-        return QWeb.render(this.template, _.extend({widget: this}, additional || {}));
-    },
-    /**
-     * Method called after rendering. Mostly used to bind actions, perform asynchronous
-     * calls, etc...
-     *
-     * By convention, the method should return a promise to inform the caller when
-     * this widget has been initialized.
-     *
-     * @returns {jQuery.Deferred}
-     */
-    start: function() {
-        if (!this.$element) {
-            var tmp = document.getElementById(this.element_id);
-            this.$element = tmp ? $(tmp) : undefined;
-        }
-        return $.Deferred().done().promise();
-    },
-    /**
-     * Destroys the current widget, also destory all its children before destroying itself.
-     */
-    stop: function() {
-        _.each(_.clone(this.widget_children), function(el) {
-            el.stop();
-        });
-        if(this.$element != null) {
-            this.$element.remove();
-        }
-        if (this.widget_parent && this.widget_parent.widget_children) {
-            this.widget_parent.widget_children = _.without(this.widget_parent.widget_children, this);
-        }
-        this.widget_parent = null;
-        this.widget_is_stopped = true;
-    },
-    /**
-     * Inform the action manager to do an action. Of course, this suppose that
-     * the action manager can be found amongst the ancestors of the current widget.
-     * If that's not the case this method will simply return `false`.
-     */
-    do_action: function(action, on_finished) {
-        if (this.widget_parent) {
-            return this.widget_parent.do_action(action, on_finished);
-        }
-        return false;
-    },
-    do_notify: function() {
-        if (this.widget_parent) {
-            return this.widget_parent.do_notify.apply(this,arguments);
-        }
-        return false;
-    },
-    do_warn: function() {
-        if (this.widget_parent) {
-            return this.widget_parent.do_warn.apply(this,arguments);
-        }
-        return false;
-    },
-    rpc: function(url, data, success, error) {
-        var def = $.Deferred().then(success, error);
-        var self = this;
-        this._super(url, data). then(function() {
-            if (!self.widget_is_stopped)
-                def.resolve.apply(def, arguments);
-        }, function() {
-            if (!self.widget_is_stopped)
-                def.reject.apply(def, arguments);
-        });
-        return def.promise();
-    }
-});
-
-/**
- * @deprecated
- * For retro compatibility only, the only difference with is that render() uses
- * directly `this` instead of context with a "widget" key.
- */
-openerp.base.OldWidget = openerp.base.Widget.extend({
-    render: function (additional) {
-        return QWeb.render(this.template, _.extend(_.extend({}, this), additional || {}));
-    }
-});
-
-openerp.base.TranslationDataBase = openerp.base.Class.extend({
-    init: function() {
-        this.db = {};
-        this.parameters = {"direction": 'ltr',
-                        "date_format": '%m/%d/%Y',
-                        "time_format": '%H:%M:%S',
-                        "grouping": "[]",
-                        "decimal_point": ".",
-                        "thousands_sep": ","};
-    },
-    set_bundle: function(translation_bundle) {
-        var self = this;
-        this.db = {};
-        var modules = _.keys(translation_bundle.modules).sort();
-        if (_.include(modules, "base")) {
-            modules = ["base"].concat(_.without(modules, "base"));
-        }
-        _.each(modules, function(name) {
-            self.add_module_translation(translation_bundle.modules[name]);
-        });
-        if (translation_bundle.lang_parameters) {
-            this.parameters = translation_bundle.lang_parameters;
-        }
-    },
-    add_module_translation: function(mod) {
-        var self = this;
-        _.each(mod.messages, function(message) {
-            if (self.db[message.id] === undefined) {
-                self.db[message.id] = message.string;
-            }
-        });
-    },
-    build_translation_function: function() {
-        var self = this;
-        var fcnt = function(str) {
-            var tmp = self.get(str);
-            return tmp === undefined ? str : tmp;
-        }
-        fcnt.database = this;
-        return fcnt;
-    },
-    get: function(key) {
-        if (this.db[key])
-            return this.db[key];
-        return undefined;
-    }
-});
-
-openerp.base._t = new openerp.base.TranslationDataBase().build_translation_function();
-
 openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.base.Session# */{
     /**
      * @constructs
@@ -625,7 +332,7 @@ openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.b
         this.server = (server == undefined) ? location.hostname : server;
         this.port = (port == undefined) ? location.port : port;
         this.rpc_mode = (server == location.hostname) ? "ajax" : "jsonp";
-        this.debug = true;
+        this.debug = (window.location.search.indexOf('?debug') !== -1);
         this.db = "";
         this.login = "";
         this.password = "";
@@ -765,143 +472,434 @@ openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.b
                 success_callback();
         });
     },
-    session_logout: function() {
-        this.uid = false;
+    session_logout: function() {
+        this.uid = false;
+    },
+    /**
+     * Reloads uid and session_id from local storage, if they exist
+     */
+    session_restore: function () {
+        this.uid = this.get_cookie('uid');
+        this.session_id = this.get_cookie('session_id');
+        this.db = this.get_cookie('db');
+        this.login = this.get_cookie('login');
+        this.user_context = this.get_cookie("user_context");
+        // we should do an rpc to confirm that this session_id is valid and if it is retrieve the information about db and login
+        // then call on_session_valid
+        this.on_session_valid();
+    },
+    /**
+     * Saves the session id and uid locally
+     */
+    session_save: function () {
+        this.set_cookie('uid', this.uid);
+        this.set_cookie('session_id', this.session_id);
+        this.set_cookie('db', this.db);
+        this.set_cookie('login', this.login);
+        this.set_cookie('user_context', this.user_context);
+    },
+    logout: function() {
+        delete this.uid;
+        delete this.session_id;
+        delete this.db;
+        delete this.login;
+        this.set_cookie('uid', '');
+        this.set_cookie('session_id', '');
+        this.set_cookie('db', '');
+        this.set_cookie('login', '');
+        this.on_session_invalid(function() {});
+    },
+    /**
+     * Fetches a cookie stored by an openerp session
+     *
+     * @private
+     * @param name the cookie's name
+     */
+    get_cookie: function (name) {
+        var nameEQ = this.element_id + '|' + name + '=';
+        var cookies = document.cookie.split(';');
+        for(var i=0; i').text(v).appendTo($('body'));
+                }
+                if(notify && this.notification) {
+                    this.notification.notify("Logging:",v);
+                }
+            }
+        }
+    }
+});
+
+openerp.base.Widget = openerp.base.SessionAware.extend({
+    /**
+     * 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.
+     *
+     * @type string
+     */
+    template: null,
+    /**
+     * The prefix used to generate an id automatically. Should be redefined in
+     * subclasses. If it is not defined, a generic identifier will be used.
+     *
+     * @type string
+     */
+    identifier_prefix: 'generic-identifier-',
+    /**
+     * Construct the widget and set its parent if a parent is given.
+     *
+     * @constructs
+     * @param {openerp.base.Widget} parent Binds the current instance to the given Widget instance.
+     * When that widget is destroyed by calling stop(), the current instance will be
+     * destroyed too. Can be null.
+     * @param {String} element_id Deprecated. Sets the element_id. Only useful when you want
+     * to bind the current Widget to an already existing part of the DOM, which is not compatible
+     * with the DOM insertion methods provided by the current implementation of Widget. So
+     * for new components this argument should not be provided any more.
+     */
+    init: function(parent, /** @deprecated */ element_id) {
+        this._super((parent || {}).session);
+        // if given an element_id, try to get the associated DOM element and save
+        // a reference in this.$element. Else just generate a unique identifier.
+        this.element_id = element_id;
+        this.element_id = this.element_id || _.uniqueId(this.identifier_prefix);
+        var tmp = document.getElementById(this.element_id);
+        this.$element = tmp ? $(tmp) : undefined;
+
+        this.widget_parent = parent;
+        this.widget_children = [];
+        if(parent && parent.widget_children) {
+            parent.widget_children.push(this);
+        }
+        // useful to know if the widget was destroyed and should not be used anymore
+        this.widget_is_stopped = false;
+    },
+    /**
+     * Render the current widget and appends it to the given jQuery object or Widget.
+     *
+     * @param target A jQuery object or a Widget instance.
+     */
+    appendTo: function(target) {
+        var self = this;
+        return this._render_and_insert(function(t) {
+            self.$element.appendTo(t);
+        }, target);
+    },
+    /**
+     * Render the current widget and prepends it to the given jQuery object or Widget.
+     *
+     * @param target A jQuery object or a Widget instance.
+     */
+    prependTo: function(target) {
+        var self = this;
+        return this._render_and_insert(function(t) {
+            self.$element.prependTo(t);
+        }, target);
     },
     /**
-     * Reloads uid and session_id from local storage, if they exist
+     * Render the current widget and inserts it after to the given jQuery object or Widget.
+     *
+     * @param target A jQuery object or a Widget instance.
      */
-    session_restore: function () {
-        this.uid = this.get_cookie('uid');
-        this.session_id = this.get_cookie('session_id');
-        this.db = this.get_cookie('db');
-        this.login = this.get_cookie('login');
-        this.user_context = this.get_cookie("user_context");
-        // we should do an rpc to confirm that this session_id is valid and if it is retrieve the information about db and login
-        // then call on_session_valid
-        this.on_session_valid();
+    insertAfter: function(target) {
+        var self = this;
+        return this._render_and_insert(function(t) {
+            self.$element.insertAfter(t);
+        }, target);
     },
     /**
-     * Saves the session id and uid locally
+     * Render the current widget and inserts it before to the given jQuery object or Widget.
+     *
+     * @param target A jQuery object or a Widget instance.
      */
-    session_save: function () {
-        this.set_cookie('uid', this.uid);
-        this.set_cookie('session_id', this.session_id);
-        this.set_cookie('db', this.db);
-        this.set_cookie('login', this.login);
-        this.set_cookie('user_context', this.user_context);
+    insertBefore: function(target) {
+        var self = this;
+        return this._render_and_insert(function(t) {
+            self.$element.insertBefore(t);
+        }, target);
     },
-    logout: function() {
-        delete this.uid;
-        delete this.session_id;
-        delete this.db;
-        delete this.login;
-        this.set_cookie('uid', '');
-        this.set_cookie('session_id', '');
-        this.set_cookie('db', '');
-        this.set_cookie('login', '');
-        this.on_session_invalid(function() {});
+    _render_and_insert: function(insertion, target) {
+        var rendered = this.render();
+        this.$element = $(rendered);
+        if (target instanceof openerp.base.Widget)
+            target = target.$element;
+        insertion(target);
+        return this.start();
     },
     /**
-     * Fetches a cookie stored by an openerp session
+     * Renders the widget using QWeb, `this.template` must be defined.
+     * The context given to QWeb contains the "widget" key that references `this`.
      *
-     * @private
-     * @param name the cookie's name
+     * @param {Object} additional Additional context arguments to pass to the template.
      */
-    get_cookie: function (name) {
-        var nameEQ = this.element_id + '|' + name + '=';
-        var cookies = document.cookie.split(';');
-        for(var i=0; i
Date: Fri, 19 Aug 2011 01:38:11 +0200
Subject: [IMP] web_rpc example

bzr revid: al@openerp.com-20110818233811-yiee3czhbtc6p3ob
---
 addons/base/static/src/js/core.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'addons/base/static/src/js/core.js')

diff --git a/addons/base/static/src/js/core.js b/addons/base/static/src/js/core.js
index 58d19de9008..e0ec45c3e6f 100644
--- a/addons/base/static/src/js/core.js
+++ b/addons/base/static/src/js/core.js
@@ -323,7 +323,6 @@ openerp.base.CallbackEnabled = openerp.base.Class.extend({
 openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.base.Session# */{
     /**
      * @constructs
-     * @param element_id to use for exception reporting
      * @param server
      * @param port
      */
@@ -344,6 +343,7 @@ openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.b
         this.context = {};
         this.shortcuts = [];
         this.active_id = null;
+        this.session = this;
     },
     start: function() {
         this.session_restore();
-- 
cgit v1.2.3