[ADD] Add support for @modifiers in kanban views

bzr revid: fme@openerp.com-20120607130231-i4lovbubmq9vevwb
This commit is contained in:
Fabien Meghazi 2012-06-07 15:02:31 +02:00
parent 2c616a90b2
commit c04b75fb53
1 changed files with 25 additions and 15 deletions

View File

@ -109,11 +109,23 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
}
},
transform_qweb_template: function(node) {
var qweb_prefix = QWeb.prefix;
var qweb_add_if = function(node, condition) {
if (node.attrs[QWeb.prefix + '-if']) {
condition = _.str.sprintf("(%s) and (%s)", node.attrs[QWeb.prefix + '-if'], condition);
}
node.attrs[QWeb.prefix + '-if'] = condition;
};
// Process modifiers
if (node.tag && node.attrs.modifiers) {
var modifiers = JSON.parse(node.attrs.modifiers || '{}');
if (modifiers.invisible) {
qweb_add_if(node, _.str.sprintf("!kanban_compute_domain(%s)", JSON.stringify(modifiers.invisible)));
}
}
switch (node.tag) {
case 'field':
node.tag = qweb_prefix;
node.attrs[qweb_prefix + '-esc'] = 'record.' + node.attrs['name'] + '.value';
node.tag = QWeb.prefix;
node.attrs[QWeb.prefix + '-esc'] = 'record.' + node.attrs['name'] + '.value';
this.extract_aggregates(node);
break;
case 'button':
@ -126,18 +138,6 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
delete(node.attrs[k]);
}
});
if (node.attrs['data-states']) {
var states = _.map(node.attrs['data-states'].split(','), function(state) {
return "record.state.raw_value == '" + _.str.trim(state) + "'";
});
node.attrs[qweb_prefix + '-if'] = states.join(' or ');
}
if (node.attrs['data-kanban_states']) {
var states = _.map(node.attrs['data-kanban_states'].split(','), function(state) {
return "record.kanban_state.raw_value == '" + _.str.trim(state) + "'";
});
node.attrs[qweb_prefix + '-if'] = states.join(' or ');
}
if (node.attrs['data-string']) {
node.attrs.title = node.attrs['data-string'];
}
@ -530,7 +530,14 @@ instance.web_kanban.KanbanRecord = instance.web.OldWidget.extend({
this.state = this.view.state.records[this.id];
},
set_record: function(record) {
var self = this;
this.id = record.id;
this.values = {};
_.each(record, function(v, k) {
self.values[k] = {
value: v
};
});
this.record = this.transform_record(record);
},
start: function() {
@ -751,6 +758,9 @@ instance.web_kanban.KanbanRecord = instance.web.OldWidget.extend({
} else {
return s.substr(0, size) + '...';
}
},
kanban_compute_domain: function(domain) {
return instance.web.form.compute_domain(domain, this.values);
}
});