← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-client-web/proto61-cleanups-xmo into lp:~openerp-dev/openobject-client-web/trunk-proto61

 

Xavier (Open ERP) has proposed merging lp:~openerp-dev/openobject-client-web/proto61-cleanups-xmo into lp:~openerp-dev/openobject-client-web/trunk-proto61.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/proto61-cleanups-xmo/+merge/53378

* A pair of source fixes (replace `json` by `simplejson` everywhere as json is not available in 2.5 and simplejson is already a dependency and often faster (C accelerator)
* Fixed a bunch of typos and warnings (missing semicolons and trailing commas) in JS code
* Fixed a test and some return values in the Python code (used dict literals when possible)
* Reformatted and renamed boot.js as I was reading it

-- 
https://code.launchpad.net/~openerp-dev/openobject-client-web/proto61-cleanups-xmo/+merge/53378
Your team OpenERP R&D Team is requested to review the proposed merge of lp:~openerp-dev/openobject-client-web/proto61-cleanups-xmo into lp:~openerp-dev/openobject-client-web/trunk-proto61.
=== modified file 'addons/base/controllers/main.py'
--- addons/base/controllers/main.py	2011-03-11 13:26:22 +0000
+++ addons/base/controllers/main.py	2011-03-15 07:13:29 +0000
@@ -1,12 +1,11 @@
 # -*- coding: utf-8 -*-
-
-import glob,json,os
-
-#import simplejson as json
+import glob, os
+from xml.etree import ElementTree
+
+import simplejson
 
 import openerpweb
 
-from xml.etree import ElementTree
 
 class Xml2Json:
     # xml2json-direct
@@ -16,7 +15,7 @@
     # URL: http://code.google.com/p/xml2json-direct/
     @staticmethod
     def convert_to_json(s):
-        return json.dumps(Xml2Json.convert_to_structure(s), sort_keys=True, indent=4)
+        return simplejson.dumps(Xml2Json.convert_to_structure(s), sort_keys=True, indent=4)
 
     @staticmethod
     def convert_to_structure(s):
@@ -105,9 +104,7 @@
 
     @openerpweb.jsonrequest
     def modules(self, req):
-        res={}
-        res["modules"] = ["base","base_hello"]
-        return res
+        return {"modules": ["base", "base_hello"]}
 
     @openerpweb.jsonrequest
     def csslist(self, req, mods='base,base_hello'):
@@ -148,7 +145,7 @@
             i['children'] = []
         d = dict([(i["id"],i) for i in menu_items])
         for i in menu_items:
-            if i['parent_id'] == False:
+            if not i['parent_id']:
                 pid = False
             else:
                 pid = i['parent_id'][0]
@@ -157,9 +154,8 @@
         # sort by sequence a tree using parent_id
         for i in menu_items:
             i['children'].sort(key = lambda x:x["sequence"])
-        res={}
-        res['data']=menu_root
-        return res
+
+        return {'data': menu_root}
 
     @openerpweb.jsonrequest
     def action(self,req,menu_id):
@@ -180,10 +176,7 @@
         m = req.session.model(model)
         ids = m.search(domain)
         values = m.read(ids, fields)
-        res = {}
-        res['ids'] = ids
-        res['values'] = values
-        return res
+        return {'ids': ids, 'values': values}
 
 class FormView(openerpweb.Controller):
     _cp_path = "/base/formview"
@@ -217,8 +210,4 @@
 
     @openerpweb.jsonrequest
     def load(self,req,action_id):
-        #m = req.session.model('ir.ui.menu')
-        res={}
-        return res
-
-#
+        return {}

=== modified file 'addons/base/static/openerp/js/boot.js'
--- addons/base/static/openerp/js/boot.js	2011-03-10 12:54:15 +0000
+++ addons/base/static/openerp/js/boot.js	2011-03-15 07:13:29 +0000
@@ -62,46 +62,42 @@
 })();
 
 //---------------------------------------------------------
-// OpenERP initalisation and black magic about the pool
+// OpenERP initialisation and black magic about the pool
 //---------------------------------------------------------
 
-(function(){
-
-if(this.openerp)
-    return;
-
-var openerp = this.openerp = function() {
-    // create a new pool instance
-    var o = {};
-
-    // links to the global openerp
-    o._openerp = openerp;
-
-    // Only base will be loaded, the rest will be by loaded by
-    // openerp.base.Connection on the first connection
-    o._modules_loaded = false
-
-    // this unique id will be replaced by hostname_databasename by
-    // openerp.base.Connection on the first connection
-    o._session_id = "session" + openerp.sessions.length;
-    openerp.sessions[o._session_id] = o;
-
-    o.screen = openerp.screen;
-    o.sessions = openerp.sessions;
-    o.base = {};
-    openerp.base(o);
-
-    return o;
-}
-
-// element_ids registry linked to all controllers on the page
-// TODO rename to elements, or keep gtk naming?
-this.openerp.screen = {};
-
-// Per session namespace
-// openerp.<module> will map to
-// openerp.sessions.servername_port_dbname_login.<module> using a closure
-this.openerp.sessions = {};
+(function() {
+    if (this.openerp)
+        return;
+
+    // openerp instance constructor
+    var openerp = this.openerp = function() {
+        var new_instance = {
+            // links to the global openerp
+            _openerp: openerp,
+            // Only base will be loaded, the rest will be by loaded by
+            // openerp.base.Connection on the first connection
+            _modules_loaded: false,
+            // this unique id will be replaced by hostname_databasename by
+            // openerp.base.Connection on the first connection
+            _session_id: "session" + openerp.sessions.length,
+            screen: openerp.screen,
+            sessions: openerp.sessions,
+            base: {}
+        };
+        openerp.sessions[new_instance._session_id] = new_instance;
+        openerp.base(new_instance);
+
+        return new_instance;
+    };
+
+    // element_ids registry linked to all controllers on the page
+    // TODO rename to elements, or keep gtk naming?
+    this.openerp.screen = {};
+
+    // Per session namespace
+    // openerp.<module> will map to
+    // openerp.sessions.servername_port_dbname_login.<module> using a closure
+    this.openerp.sessions = {};
 
 })();
 

=== modified file 'addons/base/static/openerp/js/controllers.js'
--- addons/base/static/openerp/js/controllers.js	2011-03-11 13:26:22 +0000
+++ addons/base/static/openerp/js/controllers.js	2011-03-15 07:13:29 +0000
@@ -16,9 +16,8 @@
     //     position: "first" or "last"
     //     unique: boolean
     // })
-    var args = Array.prototype.slice.call(arguments);
     var callback = function() {
-        var args2 = Array.prototype.slice.call(arguments);
+        var args = Array.prototype.slice.call(arguments);
         var r;
         for(var i = 0; i < callback.callback_chain.length; i++)  {
             var c = callback.callback_chain[i];
@@ -26,7 +25,7 @@
                 // al: obscure but shortening C-style hack, sorry
                 callback.callback_chain.pop(i--);
             }
-            r = c.callback.apply(c.self, c.args.concat(args2));
+            r = c.callback.apply(c.self, c.args.concat(args));
             // TODO special value to stop the chain
             // openerp.base.callback_stop
         }
@@ -34,13 +33,12 @@
     };
     callback.callback_chain = [];
     callback.add = function(f) {
-        var args2 = Array.prototype.slice.call(arguments);
         if(typeof(f) == 'function') {
-            f = { callback: f, args: args2.slice(1) };
+            f = { callback: f, args: Array.prototype.slice.call(arguments, 1) };
         }
         f.self = f.self || null;
         f.args = f.args || [];
-        f.unique = f.unique || false;
+        f.unique = !!f.unique;
         if(f.position == 'last') {
             callback.callback_chain.push(f);
         } else {
@@ -49,15 +47,22 @@
         return callback;
     };
     callback.add_first = function(f) {
-        callback.add.apply(null,arguments);
+        return callback.add.apply(null,arguments);
     };
     callback.add_last = function(f) {
-        var args2 = Array.prototype.slice.call(arguments);
-        callback.add({callback: f, args: args2.slice(1), position: "last"});
+        return callback.add({
+            callback: f,
+            args: Array.prototype.slice.call(arguments, 1),
+            position: "last"
+        });
     };
-    callback.add({ callback: method, self:obj, args:args.slice(2) });
-    return callback;
-}
+
+    return callback.add({
+        callback: method,
+        self:obj,
+        args:Array.prototype.slice.call(arguments, 2)
+    });
+};
 
 openerp.base.BasicController = Class.extend({
     // TODO: init and start semantics are not clearly defined yet
@@ -92,7 +97,7 @@
         console.log(arguments);
     },
     on_ready: function() {
-    },
+    }
 });
 
 openerp.base.Console =  openerp.base.BasicController.extend({
@@ -110,12 +115,12 @@
                 $('<pre></pre>').text(v.toString()).appendTo(self.$element);
             }
         });
-    },
+    }
 });
 
 openerp.base.Database = openerp.base.BasicController.extend({
 // Non Session Controller to manage databases
-})
+});
 
 openerp.base.Session = openerp.base.BasicController.extend({
     init: function(element_id, server, port) {
@@ -133,15 +138,13 @@
         this.context = {};
     },
     rpc: function(url, params, success_callback, error_callback) {
-        var self = this;
-
-        // Construct a JSON-RPC2 request, method is currently unsed
+        // Construct a JSON-RPC2 request, method is currently unused
         params.session_id = this.session_id;
         params.context = typeof(params.context) != "undefined" ? params.context  : this.context;
         var request = { jsonrpc: "2.0", method: "call", params: params, "id":null };
 
         // This is a violation of the JSON-RPC2 over HTTP protocol
-        // specification but i dont know how to parse the raw POST content from
+        // specification but i don't know how to parse the raw POST content from
         // cherrypy so i use a POST form with one variable named request
         var post = { request: JSON.stringify(request) };
 
@@ -190,7 +193,7 @@
     on_rpc_response: function() {
     },
     on_rpc_error: function(error) {
-        // TODO this should use the $element with focus and buttonsi displaying OPW etc...
+        // TODO this should use the $element with focus and button is displaying OPW etc...
         this.on_log(error, error.message, error.data.type, error.data.debug);
     },
     on_session_invalid: function(contination) {
@@ -198,18 +201,18 @@
     session_valid: function() {
         return this.uid;
     },
-    session_login: function(db, login, password, sucess_callback) {
+    session_login: function(db, login, password, success_callback) {
         var self = this;
         this.db = db;
         this.login = login;
         this.password = password;
-        var params = { db: this.db, login: this.login, password: this.password }
+        var params = { db: this.db, login: this.login, password: this.password };
         this.rpc("/base/session/login", params, function(result) {
             self.session_id = result.session_id;
             self.uid = result.uid;
             self.session_check_modules();
-            if (sucess_callback)
-                sucess_callback();
+            if (success_callback)
+                success_callback();
         });
     },
     session_check_modules: function() {
@@ -234,8 +237,8 @@
                         document.getElementsByTagName("head")[0].appendChild(s);
                         // at this point the js should be loaded or not ?
                     }
-                    for(var i=0; i<this.module_list.length; i++) {
-                        var mod = this.module_list[i];
+                    for(var j=0; j<this.module_list.length; j++) {
+                        var mod = this.module_list[j];
                         if(mod == "base")
                             continue;
                         self.log(mod);
@@ -255,13 +258,13 @@
     },
     session_logout: function() {
         this.uid = false;
-    },
-})
+    }
+});
 
 openerp.base.Controller = openerp.base.BasicController.extend({
     init: function(session, element_id) {
         this._super(element_id);
-        this.session = session
+        this.session = session;
     },
     on_log: function() {
         if(this.session)
@@ -270,8 +273,8 @@
     rpc: function(url, data, success, error) {
         // TODO: support additional arguments ?
         this.session.rpc(url, data, success, error);
-    },
-})
+    }
+});
 
 openerp.base.Loading =  openerp.base.Controller.extend({
     init: function(session, element_id) {
@@ -279,7 +282,6 @@
         this.count = 0;
     },
     start: function() {
-        var self =this;
         this.session.on_rpc_request.add_first(this.on_rpc_event, 1);
         this.session.on_rpc_response.add_last(this.on_rpc_event, -1);
     },
@@ -301,7 +303,7 @@
     },
     start: function() {
         this.$element.html(QWeb.render("Header", {}));
-    },
+    }
 });
 
 openerp.base.Login =  openerp.base.Controller.extend({
@@ -331,7 +333,7 @@
         var login = $e.find("form input[name=login]").val();
         var password = $e.find("form input[name=password]").val();
         //$e.hide();
-        // Should hide then call calllback
+        // Should hide then call callback
         this.session.session_login("", login, password, function() {
             if(self.session.session_valid()) {
                 self.on_login_valid();
@@ -342,7 +344,6 @@
         return false;
     },
     do_ask_login: function(continuation) {
-        var self = this;
         this.on_login_invalid();
         this.on_submit.add({
             position: "last",
@@ -351,7 +352,7 @@
                 if(continuation) continuation();
                 return false;
             }});
-    },
+    }
 });
 
 openerp.base.Menu =  openerp.base.Controller.extend({
@@ -367,13 +368,12 @@
         var $e = this.$element;
         $e.html(QWeb.render("Menu.root", this.data));
         $("ul.sf-menu").superfish({
-            speed: 'fast',
+            speed: 'fast'
         });
         $e.find("a").click(this.on_menu_click);
         this.on_ready();
     },
     on_menu_click: function(ev) {
-        var self = this;
         var menu_id = Number(ev.target.id.split("_").pop());
         this.rpc("/base/menu/action", {"menu_id":menu_id}, this.on_menu_action_loaded);
         return false;
@@ -386,7 +386,7 @@
         }
     },
     on_action: function(action) {
-    },
+    }
 });
 
 openerp.base.DataSet =  openerp.base.Controller.extend({
@@ -399,7 +399,7 @@
         this.domain = [];
         this.context = {};
         this.order = "";
-        this.count;
+        this.count = null;
         this.ids = [];
         this.values = {};
 /*
@@ -420,11 +420,11 @@
         this.rpc("/base/dataset/load", {model: this.model, fields: this.fields }, this.on_loaded);
     },
     on_loaded: function(data) {
-        this.ids = data.ids
-        this.values = data.values
+        this.ids = data.ids;
+        this.values = data.values;
     },
     on_reloaded: function(ids) {
-    },
+    }
 });
 
 openerp.base.DataRecord =  openerp.base.Controller.extend({
@@ -440,12 +440,12 @@
     on_change: function() {
     },
     on_reload: function() {
-    },
+    }
 });
 
 openerp.base.XmlInput = openerp.base.Controller.extend({
 // to replace view editor
-})
+});
 
 openerp.base.FormView =  openerp.base.Controller.extend({
     init: function(session, element_id, dataset, view_id) {
@@ -466,7 +466,7 @@
     on_button: function() {
     },
     on_write: function() {
-    },
+    }
 });
 
 openerp.base.ListView = openerp.base.Controller.extend({
@@ -490,7 +490,6 @@
         this.rpc("/base/listview/load", {"model": this.model, "view_id":this.view_id}, this.on_loaded);
     },
     on_loaded: function(data) {
-        var self = this;
         this.fields_view = data.fields_view;
         //this.log(this.fields_view);
         this.name = "" + this.fields_view.arch.attrs.string;
@@ -542,29 +541,29 @@
             caption: this.name
         }).setGridWidth(this.$element.width());
         $(window).bind('resize', function() { self.$table.setGridWidth(self.$element.width()); }).trigger('resize');
-    },
+    }
 });
 
 openerp.base.TreeView = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.CalendarView = openerp.base.Controller.extend({
 // Dhtmlx scheduler ?
-})
+});
 
 openerp.base.GanttView = openerp.base.Controller.extend({
 // Dhtmlx gantt ?
-})
+});
 
 openerp.base.DiagramView = openerp.base.Controller.extend({
 // 
-})
+});
 
 openerp.base.GraphView = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.SearchViewInput = openerp.base.Controller.extend({
-// TODO not sure should we create a controler for every input ?
+// TODO not sure should we create a controller for every input ?
 
 // of we just keep a simple dict for each input in
 // openerp.base.SearchView#input_ids
@@ -598,7 +597,7 @@
         this.$element.html(QWeb.render("SearchView", {"fields_view": this.fields_view}));
         this.$element.find("#search").bind('click',this.on_search);
         // TODO bind click event on all button
-        // TODO we dont do many2one yet, but in the future bind a many2one controller on them
+        // TODO we don't do many2one yet, but in the future bind a many2one controller on them
         this.log(this.$element.find("#search"));
     },
     register_input: function(node) {
@@ -608,15 +607,14 @@
         // generate id
         var id = this.element_id + "_" + this.input_index++;
         // TODO construct a nice object
-        var input = {
+        // save it in our registry
+        this.input_ids[id] = {
             node: node,
             type: "filter",
             domain: "",
             context: "",
-            disabled: false,
+            disabled: false
         };
-        // save it in our registry
-        this.input_ids[id] = input;
 
         return id;
     },
@@ -632,17 +630,17 @@
         // save the result in this.domain
     },
     on_clear: function() {
-    },
+    }
 });
 
 openerp.base.ProcessView = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.HelpView = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.View = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.Action =  openerp.base.Controller.extend({
     init: function(session, element_id) {
@@ -673,7 +671,7 @@
         $("#oe_action_list").hide();
     },
     do_action: function(action) {
-        // instanciate the right controllers by understanding the action
+        // instantiate the right controllers by understanding the action
         this.action = action;
         this.log(action);
 //        debugger;
@@ -700,9 +698,9 @@
 
         // Locate first form view
         this.listview_id = false;
-        for(var i = 0; i < action.views.length; i++)  {
-            if(action.views[i][1] == "form") {
-                this.formview_id = action.views[i][0];
+        for(var j = 0; j < action.views.length; j++)  {
+            if(action.views[j][1] == "form") {
+                this.formview_id = action.views[j][0];
                 break;
             }
         }
@@ -720,17 +718,17 @@
         // Connect the the dataset load event with the search button of search view
         // THIS IS COOL
         this.searchview.on_search.add_last(this.dataset.do_load);
-    },
+    }
 });
 
 openerp.base.Preferences = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.ImportExport = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.Homepage = openerp.base.Controller.extend({
-})
+});
 
 openerp.base.WebClient = openerp.base.Controller.extend({
     init: function(element_id) {
@@ -752,8 +750,8 @@
             self.$element.find(".on_logged").show();
         });
 
-        // TODO MOVE ALL OF THAT IN on_loggued
-        // after pooler udpate of modules
+        // TODO MOVE ALL OF THAT IN on_logged
+        // after pooler update of modules
         // Cool no ?
         this.session.on_session_invalid.add(this.login.do_ask_login);
 
@@ -777,7 +775,7 @@
         this.action.do_action(action);
     },
     do_about: function() {
-    },
+    }
 });
 
 openerp.base.webclient = function(element_id) {
@@ -785,7 +783,7 @@
     var client = new openerp.base.WebClient(element_id);
     client.start();
     return client;
-}
+};
 
 };
 

=== modified file 'openerpweb/openerpweb.py'
--- openerpweb/openerpweb.py	2011-03-08 14:57:54 +0000
+++ openerpweb/openerpweb.py	2011-03-15 07:13:29 +0000
@@ -1,10 +1,9 @@
 #!/usr/bin/python
 
-import os,re,sys,traceback,xmlrpclib
+import os, re, sys, traceback, xmlrpclib
 
 import cherrypy.lib.static
-
-import simplejson as json
+import simplejson
 
 import xmlrpctimeout
 
@@ -91,7 +90,7 @@
     def parse(self, request):
         self.cherrypy_request = None
         self.cherrypy_session = None
-        d=json.loads(request)
+        d = simplejson.loads(request)
         self.params = d.get("params",{})
         self.session_id = self.params.pop("session_id", None) or "random.random"
         self.session = session_store.setdefault(self.session_id, OpenERPSession())
@@ -126,7 +125,7 @@
         print
         #import pprint
         #pprint.pprint(r)
-        return json.dumps(r)
+        return simplejson.dumps(r)
 
 def jsonrequest(f):
     # check cleaner wrapping:


Follow ups