[IMP] in form view, try all widget possibilities in sequence, so that the form falls back on the default widget if it does not find a more precise spec

bzr revid: xmo@openerp.com-20110627141438-r0gq292w7jp4s79n
This commit is contained in:
Xavier Morel 2011-06-27 16:14:38 +02:00
parent 611e78218e
commit fe1a9ee4ec
2 changed files with 25 additions and 2 deletions

View File

@ -137,6 +137,29 @@ openerp.base.Registry = Class.extend( /** @lends openerp.base.Registry# */ {
}
return object_match;
},
/**
* Tries a number of keys, and returns the first object matching one of
* the keys.
*
* @param {Array} keys a sequence of keys to fetch the object for
* @returns {Class} the first class found matching an object
*
* @throws {openerp.base.KeyNotFound} if none of the keys was in the mapping
* @trows {openerp.base.ObjectNotFound} if a found object path was invalid
*/
get_any: function (keys) {
for (var i=0; i<keys.length; ++i) {
try {
return this.get_object(keys[i]);
} catch (e) {
if (e instanceof openerp.base.KeyNotFound) {
continue;
}
throw e;
}
}
throw new openerp.base.KeyNotFound(keys.join(','));
},
/**
* Adds a new key and value to the registry.
*

View File

@ -568,8 +568,8 @@ openerp.base.form.WidgetFrame = openerp.base.form.Widget.extend({
},
handle_node: function(node) {
var type = this.view.fields_view.fields[node.attrs.name] || {};
var widget_type = node.attrs.widget || type.type || node.tag;
var widget = new (this.view.registry.get_object(widget_type)) (this.view, node);
var widget = new (this.view.registry.get_any(
[node.attrs.widget, type.type, node.tag])) (this.view, node);
if (node.tag == 'field') {
if (!this.view.default_focus_field || node.attrs.default_focus == '1') {
this.view.default_focus_field = widget;