From 9cf7baee6bd7aa5e0fc0b58bc2cf04da8fb46d28 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 10 Mar 2011 16:53:45 +0100 Subject: [PATCH 01/17] [FIX] use simplejson as json is not available on Python 2.5 (also simplejson has better perfs) bzr revid: xmo@openerp.com-20110310155345-8nxu3i92hno4j2yc --- addons/base/controllers/main.py | 9 ++++----- openerpweb/openerpweb.py | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index df21adb8db0..472af88baa9 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- +import glob, os +from xml.etree import ElementTree -import glob,json,os - -#import simplejson as json +import simplejson import openerpweb -from xml.etree import ElementTree class Xml2Json: # xml2json-direct @@ -16,7 +15,7 @@ class Xml2Json: # 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): diff --git a/openerpweb/openerpweb.py b/openerpweb/openerpweb.py index edd1a907486..d427c8bac89 100644 --- a/openerpweb/openerpweb.py +++ b/openerpweb/openerpweb.py @@ -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 @@ class JsonRequest(object): 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 @@ class JsonRequest(object): print #import pprint #pprint.pprint(r) - return json.dumps(r) + return simplejson.dumps(r) def jsonrequest(f): # check cleaner wrapping: From 59a5c4c2a5f178f6154b0cf59587a49ca1159f71 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 14 Mar 2011 10:38:25 +0100 Subject: [PATCH 02/17] [IMP] result dict creations bzr revid: xmo@openerp.com-20110314093825-1gcwso6w27tt6stz --- addons/base/controllers/main.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 472af88baa9..fbaf138e56f 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -104,9 +104,7 @@ class Session(openerpweb.Controller): @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'): @@ -147,7 +145,7 @@ class Menu(openerpweb.Controller): 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] @@ -156,9 +154,8 @@ class Menu(openerpweb.Controller): # 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): @@ -179,10 +176,7 @@ class DataSet(openerpweb.Controller): 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" @@ -216,8 +210,4 @@ class Action(openerpweb.Controller): @openerpweb.jsonrequest def load(self,req,action_id): - #m = req.session.model('ir.ui.menu') - res={} - return res - -# + return {} From ba287ba240e8ec646af66347f06c4937a532fcfd Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 14 Mar 2011 10:44:57 +0100 Subject: [PATCH 03/17] [FIX] JS warnings (typos, un-terminated statements, duplicate vars, trailing commas, unused locals bzr revid: xmo@openerp.com-20110314094457-lci9toigkpue3guh --- addons/base/static/openerp/js/boot.js | 6 +- addons/base/static/openerp/js/controllers.js | 115 +++++++++---------- 2 files changed, 57 insertions(+), 64 deletions(-) diff --git a/addons/base/static/openerp/js/boot.js b/addons/base/static/openerp/js/boot.js index 9c5661d27d6..92353469165 100644 --- a/addons/base/static/openerp/js/boot.js +++ b/addons/base/static/openerp/js/boot.js @@ -62,7 +62,7 @@ })(); //--------------------------------------------------------- -// OpenERP initalisation and black magic about the pool +// OpenERP initialisation and black magic about the pool //--------------------------------------------------------- (function(){ @@ -79,7 +79,7 @@ var openerp = this.openerp = function() { // Only base will be loaded, the rest will be by loaded by // openerp.base.Connection on the first connection - o._modules_loaded = false + o._modules_loaded = false; // this unique id will be replaced by hostname_databasename by // openerp.base.Connection on the first connection @@ -92,7 +92,7 @@ var openerp = this.openerp = function() { openerp.base(o); return o; -} +}; // element_ids registry linked to all controllers on the page // TODO rename to elements, or keep gtk naming? diff --git a/addons/base/static/openerp/js/controllers.js b/addons/base/static/openerp/js/controllers.js index b5312856408..99fd4be61cd 100644 --- a/addons/base/static/openerp/js/controllers.js +++ b/addons/base/static/openerp/js/controllers.js @@ -57,7 +57,7 @@ openerp.base.callback = function(obj, method) { }; callback.add({ callback: method, self:obj, args:args.slice(2) }); return callback; -} +}; openerp.base.BasicController = Class.extend({ // TODO: init and start semantics are not clearly defined yet @@ -92,7 +92,7 @@ openerp.base.BasicController = Class.extend({ console.log(arguments); }, on_ready: function() { - }, + } }); openerp.base.Console = openerp.base.BasicController.extend({ @@ -110,12 +110,12 @@ openerp.base.Console = openerp.base.BasicController.extend({ $('
').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 +133,13 @@ openerp.base.Session = openerp.base.BasicController.extend({
         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 +188,7 @@ openerp.base.Session = openerp.base.BasicController.extend({
     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) {
@@ -203,7 +201,7 @@ openerp.base.Session = openerp.base.BasicController.extend({
         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;
@@ -234,8 +232,8 @@ openerp.base.Session = openerp.base.BasicController.extend({
                         document.getElementsByTagName("head")[0].appendChild(s);
                         // at this point the js should be loaded or not ?
                     }
-                    for(var i=0; i
Date: Mon, 14 Mar 2011 11:00:55 +0100
Subject: [PATCH 04/17] Rename and reindent elements in boot.js to makes scope
 and flows clearer. Also use object literal when available

bzr revid: xmo@openerp.com-20110314100055-gwpyoz2nk4ve1rhd
---
 addons/base/static/openerp/js/boot.js | 62 +++++++++++++--------------
 1 file changed, 29 insertions(+), 33 deletions(-)

diff --git a/addons/base/static/openerp/js/boot.js b/addons/base/static/openerp/js/boot.js
index 92353469165..9c25f856af8 100644
--- a/addons/base/static/openerp/js/boot.js
+++ b/addons/base/static/openerp/js/boot.js
@@ -65,43 +65,39 @@
 // OpenERP initialisation and black magic about the pool
 //---------------------------------------------------------
 
-(function(){
+(function() {
+    if (this.openerp)
+        return;
 
-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);
 
-var openerp = this.openerp = function() {
-    // create a new pool instance
-    var o = {};
+        return new_instance;
+    };
 
-    // links to the global openerp
-    o._openerp = openerp;
+    // element_ids registry linked to all controllers on the page
+    // TODO rename to elements, or keep gtk naming?
+    this.openerp.screen = {};
 
-    // 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. will map to
-// openerp.sessions.servername_port_dbname_login. using a closure
-this.openerp.sessions = {};
+    // Per session namespace
+    // openerp. will map to
+    // openerp.sessions.servername_port_dbname_login. using a closure
+    this.openerp.sessions = {};
 
 })();
 

From 970dc4e2adf6894e12d7a05204d51e62566a965f Mon Sep 17 00:00:00 2001
From: Xavier Morel 
Date: Mon, 14 Mar 2011 12:58:28 +0100
Subject: [PATCH 05/17] Reformat openerp.base.callback

bzr revid: xmo@openerp.com-20110314115828-5w00q4qsx06pxb8p
---
 addons/base/static/openerp/js/controllers.js | 27 ++++++++++++--------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/addons/base/static/openerp/js/controllers.js b/addons/base/static/openerp/js/controllers.js
index 99fd4be61cd..d0c2f158508 100644
--- a/addons/base/static/openerp/js/controllers.js
+++ b/addons/base/static/openerp/js/controllers.js
@@ -16,9 +16,8 @@ openerp.base.callback = function(obj, method) {
     //     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 @@ openerp.base.callback = function(obj, method) {
                 // 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 @@ openerp.base.callback = function(obj, method) {
     };
     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,14 +47,21 @@ openerp.base.callback = function(obj, method) {
         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({

From 69b595ca8a664099c8e25274480e451fd0a411ee Mon Sep 17 00:00:00 2001
From: Xavier Morel 
Date: Tue, 15 Mar 2011 08:04:09 +0100
Subject: [PATCH 06/17] [FIX] typo

bzr revid: xmo@openerp.com-20110315070409-ovef64u9m2qpt5r7
---
 addons/base/static/openerp/js/controllers.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/addons/base/static/openerp/js/controllers.js b/addons/base/static/openerp/js/controllers.js
index d0c2f158508..41333244b9d 100644
--- a/addons/base/static/openerp/js/controllers.js
+++ b/addons/base/static/openerp/js/controllers.js
@@ -201,7 +201,7 @@ openerp.base.Session = openerp.base.BasicController.extend({
     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;
@@ -211,8 +211,8 @@ openerp.base.Session = openerp.base.BasicController.extend({
             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() {

From 2a69a9e23fd89257d4f5cf3577c153936fc63ffa Mon Sep 17 00:00:00 2001
From: Mustufa Rangwala 
Date: Wed, 16 Mar 2011 15:18:46 +0530
Subject: [PATCH 07/17] [FIX] Account: cannot install Any Chart of Account

lp bug: https://launchpad.net/bugs/735965 fixed

bzr revid: mra@mra-laptop-20110316094846-h0o0srendhztgvve
---
 addons/account/installer.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/addons/account/installer.py b/addons/account/installer.py
index 264557ad82c..e4229f0124c 100644
--- a/addons/account/installer.py
+++ b/addons/account/installer.py
@@ -213,7 +213,7 @@ class account_installer(osv.osv_memory):
                                     }, context=context)
 
             if 'date_start' in res and 'date_stop' in res:
-                f_ids = fy_obj.search(cr, uid, [('date_start', '<=', res['date_start']), ('date_stop', '>=', res['date_stop']), ('company_id', '=', res['company_id'])], context=context)
+                f_ids = fy_obj.search(cr, uid, [('date_start', '<=', res['date_start']), ('date_stop', '>=', res['date_stop']), ('company_id', '=', res['company_id'][0])], context=context)
                 if not f_ids:
                     name = code = res['date_start'][:4]
                     if int(name) != int(res['date_stop'][:4]):
@@ -224,7 +224,7 @@ class account_installer(osv.osv_memory):
                         'code': code,
                         'date_start': res['date_start'],
                         'date_stop': res['date_stop'],
-                        'company_id': res['company_id']
+                        'company_id': res['company_id'][0]
                     }
                     fiscal_id = fy_obj.create(cr, uid, vals, context=context)
                     if res['period'] == 'month':

From 170107c05134680e4154f2fc1da2791b48d23ff1 Mon Sep 17 00:00:00 2001
From: "Quentin (OpenERP)" 
Date: Wed, 16 Mar 2011 11:04:13 +0100
Subject: [PATCH 08/17] [FIX] account_followup: wrong domain syntax

bzr revid: qdp-launchpad@openerp.com-20110316100413-yq1z1i3a48lm2ay0
---
 addons/account_followup/wizard/account_followup_print.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/addons/account_followup/wizard/account_followup_print.py b/addons/account_followup/wizard/account_followup_print.py
index 3a062202bfa..47c9e1a59cb 100644
--- a/addons/account_followup/wizard/account_followup_print.py
+++ b/addons/account_followup/wizard/account_followup_print.py
@@ -115,7 +115,7 @@ class account_followup_print_all(osv.osv_memory):
     _name = 'account.followup.print.all'
     _description = 'Print Followup & Send Mail to Customers'
     _columns = {
-        'partner_ids': fields.many2many('account_followup.stat.by.partner', 'partner_stat_rel', 'osv_memory_id', 'partner_id', 'Partners', required=True, domain="[('account_id.type', '=', 'receivable'), ('account_id.reconcile', '=', True), ('reconcile_id','=', False), ('state', '!=', 'draft'), ('account_id.active', '=' True), ('debit', '>', 0)]"),
+        'partner_ids': fields.many2many('account_followup.stat.by.partner', 'partner_stat_rel', 'osv_memory_id', 'partner_id', 'Partners', required=True, domain="[('account_id.type', '=', 'receivable'), ('account_id.reconcile', '=', True), ('reconcile_id','=', False), ('state', '!=', 'draft'), ('account_id.active', '=', True), ('debit', '>', 0)]"),
         'email_conf': fields.boolean('Send email confirmation'),
         'email_subject': fields.char('Email Subject', size=64),
         'partner_lang': fields.boolean('Send Email in Partner Language', help='Do not change message text, if you want to send email in partner language, or configure from company'),

From fea50595d644ed864577bef4a30a8fd8d712301d Mon Sep 17 00:00:00 2001
From: Fabien Meghazi 
Date: Wed, 16 Mar 2011 14:31:10 +0100
Subject: [PATCH 09/17] [ADD] QWeb: changed behaviour of t-att

bzr revid: fme@openerp.com-20110316133110-s0wwdb4yrysxb6q7
---
 addons/base/static/qweb/qweb.js | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/addons/base/static/qweb/qweb.js b/addons/base/static/qweb/qweb.js
index 7ce95c5c13f..3bed1f10267 100644
--- a/addons/base/static/qweb/qweb.js
+++ b/addons/base/static/qweb/qweb.js
@@ -51,6 +51,7 @@ var QWeb = {
         // TODO: Currently this will also replace and, or, ... in strings. Try
         // 'hi boys and girls' != '' and 1 == 1  -- will be replaced to : 'hi boys && girls' != '' && 1 == 1
         // try to find a solution without tokenizing
+        e = '(' + e + ')';
         e = e.replace(/\band\b/g, " && ");
         e = e.replace(/\bor\b/g, " || ");
         e = e.replace(/\bgt\b/g, " > ");
@@ -169,10 +170,22 @@ var QWeb = {
     },
     render_att_att:function(e, t_att, g_att, v, ext, av) {
         if (ext) {
-            g_att[ext.substring(1)] = this.eval_str(av, v);
+            var attv = this.eval_object(av, v);
+            if (attv != null) {
+                g_att[ext.substring(1)] = attv.toString();
+            }
         } else {
             var o = this.eval_object(av, v);
-            g_att[o[0]] = o[1];
+            if (o != null) {
+                // TODO: http://bonsaiden.github.com/JavaScript-Garden/#types.typeof
+                if (o.constructor == Array && o.length > 1 && o[1] != null) {
+                    g_att[o[0]] = new String(o[1]);
+                } else if (o.constructor == Object) {
+                    for (var i in o) {
+                        g_att[i] = new String(o[i]);
+                    }
+                }
+            }
         }
     },
     render_att_attf:function(e, t_att, g_att, v, ext, av) {

From ac35ee9ec460c1eac08558bd3c2bba92bdd217af Mon Sep 17 00:00:00 2001
From: Fabien Meghazi 
Date: Wed, 16 Mar 2011 15:00:45 +0100
Subject: [PATCH 10/17] [ADD] Formview

bzr revid: fme@openerp.com-20110316140045-6tzlnbhakhfpu20n
---
 addons/base/static/openerp/base.css          |  10 +
 addons/base/static/openerp/base.xml          |  95 +++++++-
 addons/base/static/openerp/js/controllers.js | 236 ++++++++++++++++++-
 3 files changed, 338 insertions(+), 3 deletions(-)

diff --git a/addons/base/static/openerp/base.css b/addons/base/static/openerp/base.css
index b6278fdf718..a62d37011a0 100644
--- a/addons/base/static/openerp/base.css
+++ b/addons/base/static/openerp/base.css
@@ -290,3 +290,13 @@ body {
     border-radius: 3px;
     background: white;
 }
+
+/* Widgets */
+.openerp .separator {
+    border: 0 solid #666;
+}
+.openerp .separator.horizontal {
+   font-weight: bold;
+    border-bottom-width: 1px;
+    margin: 6px 4px 6px 1px;
+}
diff --git a/addons/base/static/openerp/base.xml b/addons/base/static/openerp/base.xml
index 01084a4da96..434759f49dc 100644
--- a/addons/base/static/openerp/base.xml
+++ b/addons/base/static/openerp/base.xml
@@ -93,7 +93,7 @@
     
     
- +

@@ -133,6 +133,99 @@ + +

+
+ + + 0 / 0 + + +
+ +
+ +
+
+ + Unhandled widget + + + + + + + + + +
+ +
+
+ + +
+ + +
+
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ One2Many widget +
+
+ + + + + + + + +

diff --git a/addons/base/static/openerp/js/controllers.js b/addons/base/static/openerp/js/controllers.js index 41333244b9d..8a4cf10baba 100644 --- a/addons/base/static/openerp/js/controllers.js +++ b/addons/base/static/openerp/js/controllers.js @@ -447,21 +447,253 @@ openerp.base.XmlInput = openerp.base.Controller.extend({ // to replace view editor }); +openerp.base.Widget = openerp.base.Controller.extend({ + init: function(session, element_id, view, node) { + var type = view.fields_view.fields[node.attrs.name] || {}; + this.type = node.attrs.widget || type.type || node.tag; + this.name = node.attrs.name; + var type = view.fields_view.fields[node.attrs.name] || {}; + this.type = node.attrs.widget || type.type || node.tag; + this.element_id = (node.tag == this.type ? node.tag : node.tag + '_' + this.type) + '_'; + this.element_id += (this.name ? this.name + (this.is_field_label ? '_label' : '') + '_' : ''); + this.element_id += Math.round(Math.random() * (new Date()).getTime()); + this._super(session, this.element_id); + this.view = view; + this.view.widgets[this.element_id] = this; + this.node = node; + this.children = node.children; + this.colspan = parseInt(node.attrs.colspan || 1); + if (node.tag == 'field') { + this.view.fields[node.attrs.name] = this; + if (node.attrs.nolabel != '1' && this.colspan > 1) { + this.colspan--; + } + } + this.field = view.fields_view.fields[node.attrs.name]; + this.template = "FormView.widget"; + + this.invisible = (node.attrs.invisible == '1'); + this.string = node.attrs.string || (this.field ? this.field.string : undefined); + this.help = node.attrs.help || (this.field ? this.field.help : undefined); + this.nolabel = (node.attrs.nolabel == '1'); + }, + register: function() { + this.$element = $('#' + this.element_id); + return this; + }, + render: function() { + var template = this.template; + return QWeb.render(template, { "widget": this }); + } +}); +openerp.base.WidgetFrame = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.frame"; + this.columns = node.attrs.col || 4; + this.x = 0; + this.y = 0; + this.table = []; + this.add_row(); + for (var i = 0; i < node.children.length; i++) { + var n = node.children[i]; + if (n.tag == "newline") { + this.add_row(); + } else { + this.handle_node(n); + } + } + this.set_row_cells_with(this.table[this.table.length - 1]); + }, + add_row: function(){ + if (this.table.length) { + this.set_row_cells_with(this.table[this.table.length - 1]); + } + var row = []; + this.table.push(row); + this.x = 0; + this.y += 1; + return row; + }, + set_row_cells_with: function(row) { + for (var i = 0; i < row.length; i++) { + var w = row[i]; + if (w.is_field_label) { + w.width = "1%"; + if (row[i + 1]) { + row[i + 1].width = Math.round((100 / this.columns) * (w.colspan + 1) - 1) + '%'; + } + } else if (w.width === undefined) { + w.width = Math.round((100 / this.columns) * w.colspan) + '%'; + } + } + }, + handle_node: function(n) { + var type = this.view.fields_view.fields[n.attrs.name] || {}; + var widget_type = n.attrs.widget || type.type || n.tag; + if (openerp.base.widgets[widget_type]) { + if (n.tag == 'field' && n.attrs.nolabel != '1') { + var label = new openerp.base.widgets['label'](this.session, null, this.view, n); + this.add_widget(label); + } + var widget = new openerp.base.widgets[widget_type](this.session, null, this.view, n); + this.add_widget(widget); + } else { + console.log("Unhandled widget type : " + widget_type, n); + } + }, + add_widget: function(w) { + if (!w.invisible) { + var current_row = this.table[this.table.length - 1]; + if (current_row.length && (this.x + w.colspan) > this.columns) { + current_row = this.add_row(); + } + current_row.push(w); + this.x += w.colspan; + } + return w; + } +}); +openerp.base.WidgetNotebook = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.notebook"; + this.pages = []; + for (var i = 0; i < node.children.length; i++) { + var n = node.children[i]; + if (n.tag == "page") { + var page = new openerp.base.WidgetFrame(this.session, null, this.view, n); + this.pages.push(page); + } + } + } +}); +openerp.base.WidgetSeparator = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.separator"; + } +}); +openerp.base.WidgetLabel = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this.is_field_label = true; + this._super(session, element_id, view, node); + this.template = "FormView.label"; + this.colspan = 1; + } +}); +openerp.base.WidgetFieldChar = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.char"; + } +}); +openerp.base.WidgetFieldEmail = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.char"; + } +}); +openerp.base.WidgetFieldFloat = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.char"; + } +}); +openerp.base.WidgetFieldBoolean = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.boolean"; + } +}); +openerp.base.WidgetFieldDate = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.date"; + } +}); +openerp.base.WidgetFieldDatetime = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.datetime"; + } +}); +openerp.base.WidgetFieldText = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.text"; + } +}); +openerp.base.WidgetFieldSelection = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.selection"; + } +}); +openerp.base.WidgetFieldMany2One = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.many2one"; + } +}); +openerp.base.WidgetFieldOne2Many = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.one2many"; + } +}); +openerp.base.WidgetFieldReference = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.field.reference"; + } +}); +openerp.base.WidgetButton = openerp.base.Widget.extend({ + init: function(session, element_id, view, node) { + this._super(session, element_id, view, node); + this.template = "FormView.button"; + } +}); +openerp.base.widgets = { + 'group' : openerp.base.WidgetFrame, + 'notebook' : openerp.base.WidgetNotebook, + 'separator' : openerp.base.WidgetSeparator, + 'label' : openerp.base.WidgetLabel, + 'char' : openerp.base.WidgetFieldChar, + 'email' : openerp.base.WidgetFieldEmail, + 'date' : openerp.base.WidgetFieldDate, + 'datetime' : openerp.base.WidgetFieldDatetime, + 'text' : openerp.base.WidgetFieldText, + 'selection' : openerp.base.WidgetFieldSelection, + 'many2one' : openerp.base.WidgetFieldMany2One, + 'one2many' : openerp.base.WidgetFieldOne2Many, + 'reference' : openerp.base.WidgetFieldReference, + 'boolean' : openerp.base.WidgetFieldBoolean, + 'float' : openerp.base.WidgetFieldFloat, + 'button' : openerp.base.WidgetButton +} + openerp.base.FormView = openerp.base.Controller.extend({ init: function(session, element_id, dataset, view_id) { this._super(session, element_id); this.dataset = dataset; this.model = dataset.model; this.view_id = view_id; + this.widgets = {}; + this.fields = {}; }, start: function() { //this.log('Starting FormView '+this.model+this.view_id) - this.rpc("/base/formview/load", {"model": this.model, "view_id":this.view_id}, this.on_loaded); + this.rpc("/base/formview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); }, on_loaded: function(data) { this.fields_view = data.fields_view; //this.log(this.fields_view); - this.$element.html(QWeb.render("FormView", {"fields_view": this.fields_view})); + var frame = new openerp.base.WidgetFrame(this.session, null, this, this.fields_view.arch); + this.$element.html(QWeb.render("FormView", { "frame": frame, "view": this })); + for (var i in this.widgets) { + this.widgets[i].register(); + } }, on_button: function() { }, From 195d5aef8b8aab8f7fa5fe629ee60f488f1ca710 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 16 Mar 2011 15:37:53 +0100 Subject: [PATCH 11/17] [FIX] label for attribute bzr revid: fme@openerp.com-20110316143753-vlrvls0qmtz27iaw --- addons/base/static/openerp/base.xml | 2 +- addons/base/static/openerp/js/controllers.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/base/static/openerp/base.xml b/addons/base/static/openerp/base.xml index 434759f49dc..1b295cf4cab 100644 --- a/addons/base/static/openerp/base.xml +++ b/addons/base/static/openerp/base.xml @@ -179,7 +179,7 @@ -