return {'result': True}
return {'result': False}
- def normalize_attrs(self, elem, context):
- """ Normalize @attrs, @invisible, @required, @readonly and @states, so
- the client only has to deal with @attrs.
-
- See `the discoveries pad <http://pad.openerp.com/discoveries>`_ for
- the rationale.
-
- :param elem: the current view node (Python object)
- :type elem: xml.etree.ElementTree.Element
- :param dict context: evaluation context
- """
- # If @attrs is normalized in json by server, the eval should be replaced by simplejson.loads
- attrs = openerpweb.ast.literal_eval(elem.get('attrs', '{}'))
- if 'states' in elem.attrib:
- attrs.setdefault('invisible', [])\
- .append(('state', 'not in', elem.attrib.pop('states').split(',')))
- if attrs:
- elem.set('attrs', simplejson.dumps(attrs))
- for a in ['invisible', 'readonly', 'required']:
- if a in elem.attrib:
- # In the XML we trust
- avalue = bool(eval(elem.get(a, 'False'),
- {'context': context or {}}))
- if not avalue:
- del elem.attrib[a]
- else:
- elem.attrib[a] = '1'
- if a == 'invisible' and 'attrs' in elem.attrib:
- del elem.attrib['attrs']
-
def transform_view(self, view_string, session, context=None):
# transform nodes on the fly via iterparse, instead of
# doing it statically on the parsing result
if event == "start":
if root is None:
root = elem
- self.normalize_attrs(elem, context)
self.parse_domains_and_contexts(elem, session)
return root
on_form_changed: function() {
for (var w in this.widgets) {
w = this.widgets[w];
- w.process_attrs();
+ w.process_modifiers();
w.update_dom();
}
},
stack.push(!_(val).contains(field));
break;
default:
- this.log("Unsupported operator in attrs :", op);
+ this.log("Unsupported operator in modifiers :", op);
}
}
return _.all(stack);
init: function(view, node) {
this.view = view;
this.node = node;
- this.attrs = JSON.parse(this.node.attrs.attrs || '{}');
+ this.modifiers = JSON.parse(this.node.attrs.modifiers || '{}');
this.type = this.type || node.tag;
this.element_name = this.element_name || this.type;
this.element_id = [this.view.element_id, this.element_name, this.view.widgets_counter++].join("_");
this.string = this.string || node.attrs.string;
this.help = this.help || node.attrs.help;
- this.invisible = (node.attrs.invisible == '1');
+ this.invisible = this.modifiers['invisible'] === true;
},
start: function() {
this.$element = $('#' + this.element_id);
},
- process_attrs: function() {
+ process_modifiers: function() {
var compute_domain = openerp.base.form.compute_domain;
- for (var a in this.attrs) {
- this[a] = compute_domain(this.attrs[a], this.view.fields);
+ for (var a in this.modifiers) {
+ this[a] = compute_domain(this.modifiers[a], this.view.fields);
}
},
update_dom: function() {
this.field = view.fields_view.fields[node.attrs.name] || {};
this.string = node.attrs.string || this.field.string;
this.help = node.attrs.help || this.field.help;
- this.invisible = (this.invisible || this.field.invisible == '1');
- this.nolabel = (this.field.nolabel || node.attrs.nolabel) == '1';
- this.readonly = (this.field.readonly || node.attrs.readonly) == '1';
- this.required = (this.field.required || node.attrs.required) == '1';
+ this.nolabel = (this.field.nolabel || node.attrs.nolabel) === '1';
+ this.readonly = this.modifiers['readonly'] === true;
+ this.required = this.modifiers['required'] === true;
this.invalid = false;
this.touched = false;
},
openerp.base.list.form[key] = (form_widgets.get_object(key)).extend({
update_dom: function () {
this.$element.children().css('visibility', '');
- if (this.invisible && this.node.attrs.invisible !== '1') {
+ if (this.invisible) {
this.$element.children().css('visibility', 'hidden');
} else {
+ this.invisible = !!this.modifiers.tree_invisible;
this._super();
+ this.invisible = false;
}
}
});
var name = field.attrs.name;
var column = _.extend({id: name, tag: field.tag},
field.attrs, fields[name]);
- // attrs computer
- if (column.attrs) {
- var attrs = JSON.parse(column.attrs);
- column.attrs_for = function (fields) {
+ // modifiers computer
+ if (column.modifiers) {
+ var modifiers = JSON.parse(column.modifiers);
+ column.modifiers_for = function (fields) {
var result = {};
- for (var attr in attrs) {
- result[attr] = domain_computer(attrs[attr], fields);
+ for (var modifier in modifiers) {
+ result[modifier] = domain_computer(modifiers[modifier], fields);
}
return result;
};
} else {
- column.attrs_for = noop;
+ column.modifiers_for = noop;
}
return column;
};
if (grouped) {
this.columns.unshift({
id: '_group', tag: '', string: "Group", meta: true,
- attrs_for: function () { return {}; }
+ modifiers_for: function () { return {}; }
}, {
id: '_count', tag: '', string: '#', meta: true,
- attrs_for: function () { return {}; }
+ modifiers_for: function () { return {}; }
});
}
<td t-if="!column.meta and column.invisible !== '1'" t-att-title="column.help"
t-att-class="'oe-field-cell' + (align ? ' oe-number' : '')"
t-att-data-field="column.id">
- <t t-set="attrs" t-value="column.attrs_for(row.data)"/>
+ <t t-set="attrs" t-value="column.modifiers_for(row.data)"/>
<t t-if="!attrs.invisible">
<t t-set="is_button" t-value="column.tag === 'button'"/>
<!-- TODO: get correct widget from form -->