[IMP]kanban : div widget many2many_tags => field

bzr revid: chm@openerp.com-20120918153035-xutvjflw057s8t18
This commit is contained in:
Christophe Matthieu 2012-09-18 17:30:35 +02:00
parent 5d25e1c109
commit 3fd98b0f80
1 changed files with 27 additions and 13 deletions

View File

@ -71,6 +71,9 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
this.fields_keys = _.keys(this.fields_view.fields);
this.add_qweb_template();
this.has_been_loaded.resolve();
this._super.apply(this, arguments);
return $.when();
},
_is_quick_create_enabled: function() {
@ -85,6 +88,9 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
return false;
return this._super(action);
},
/* add_qweb_template
* select the nodes into the xml and send to extract_aggregates the nodes with TagName="field"
*/
add_qweb_template: function() {
for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
var child = this.fields_view.arch.children[i];
@ -97,6 +103,9 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
}
}
},
/* extract_aggregates
* extract the agggregates from the nodes (TagName="field")
*/
extract_aggregates: function(node) {
for (var j = 0, jj = this.group_operators.length; j < jj; j++) {
if (node.attrs[this.group_operators[j]]) {
@ -121,9 +130,15 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
}
switch (node.tag) {
case 'field':
node.tag = QWeb.prefix;
node.attrs[QWeb.prefix + '-esc'] = 'record.' + node.attrs['name'] + '.value';
this.extract_aggregates(node);
if(this.fields_view.fields[ node.attrs['name'] ].type == 'many2many'){
node.tag = 'div';
node.attrs['class'] = 'oe_kanban_many2many_tags';
node.attrs['model'] = this.fields_view.fields[node.attrs['name']].relation;
node.attrs['t-att-data'] = 'record.' + node.attrs['name'] + '.raw_value';
}else {
node.tag = QWeb.prefix;
node.attrs[QWeb.prefix + '-esc'] = 'record.' + node.attrs['name'] + '.value';
}
break;
case 'button':
case 'a':
@ -163,17 +178,16 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
}
}
},
/* widget for list of tags/categories...
* make : <div widget="many2many_tags" t-att-data="record.your_field_ids.raw_value" model="note.tag"/>
/* widget for list of tags/categories...
*/
transform_widget_many2many: function(){
var self=this,
arg={};
// select all widget
self.$el.find("[widget='many2many_tags']").each(function(){
var model = $(this).attr("model"),
data = $(this).attr("data"),
list = data.split(",");
self.$el.find(".oe_kanban_many2many_tags").each(function(){
var model = $(this).attr("model");
var data = $(this).attr("data");
var list = data.split(",");
//select all id (per model)
if(!arg[model]) arg[model]=[];
for(var t=0;t<list.length;t++) if(list[t]!="") arg[model].push( list[t] );
@ -186,13 +200,10 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
dataset.name_get(_.uniq( arg[model] )).then(
function(result) {
for(var t=0;t<result.length;t++){
self.$el.find("[widget='many2many_tags'][model='" + model + "']")
self.$el.find(".oe_kanban_many2many_tags[model='" + model + "']")
.filter(function(){ return this.getAttribute("data").match(new RegExp('(^|,)'+result[t][0]+'(,|$)')); })
.append('<span class="oe_tag" data-list_id="' + result[t][0] +'"">'+result[t][1]+'</span>');
}
},
function(r){
console.log('Error',r);
}
);
}
@ -717,6 +728,9 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
transform_record: function(record) {
var self = this,
new_record = {};
console.log(this, record);
_.each(record, function(value, name) {
var r = _.clone(self.view.fields_view.fields[name] || {});
if ((r.type === 'date' || r.type === 'datetime') && value) {