[IMP] kanban: transform_list_many2many : only one request by model

bzr revid: chm@openerp.com-20120911101805-basl7y3zdeg0cb5u
This commit is contained in:
Christophe Matthieu 2012-09-11 12:18:05 +02:00
parent ae0c3cf8a1
commit e0cedfcb0b
1 changed files with 16 additions and 11 deletions

View File

@ -166,6 +166,8 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
transform_list_many2many: function(){ transform_list_many2many: function(){
var self = this; var self = this;
var arg={};
/* Set the lists of tag/categories */ /* Set the lists of tag/categories */
var blocks = self.$el.find('.oe_kanban_list_many2many'); var blocks = self.$el.find('.oe_kanban_list_many2many');
for(var i=0;i<blocks.length;i++){ for(var i=0;i<blocks.length;i++){
@ -174,22 +176,26 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
//select the model //select the model
var model = block.data('model'); var model = block.data('model');
if(!model||model.length<1) console.log("Error : no data-model on a field : .oe_kanban_list_many2many"); if(model&&model.length>1){
// select all ids if(!arg[model]) arg[model]=[];
var list_ids = [];
block.find('[data-list_id]').each(function() {
list_ids.push( $(this).data('list_id') );
});
// select all ids
block.find('[data-list_id]').each(function() {
arg[model].push( $(this).data('list_id') );
});
}
if(list_ids.length>0){ }
// request
// only one request by model
for(var model in arg){
if(arg[model].length>0){
var dataset = new instance.web.DataSetSearch(self, model, self.session.context); var dataset = new instance.web.DataSetSearch(self, model, self.session.context);
dataset.name_get(_.uniq(list_ids)).then( dataset.name_get(_.uniq( arg[model] )).then(
function(result) { function(result) {
for(var t=0;t<result.length;t++){ for(var t=0;t<result.length;t++){
self.$el.find(".oe_kanban_list_many2many [data-list_id='" + result[t][0] + "']").html(result[t][1]); self.$el.find(".oe_kanban_list_many2many[data-model='" + model + "'] [data-list_id='" + result[t][0] + "']").html(result[t][1]);
} }
}, },
function(r){ function(r){
@ -197,7 +203,6 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
} }
); );
} }
} }
}, },