[IMP] kanban: new widget 'many2many_tags' for kanban view. Call by : '<div widget=many2many_tags t-att-data=record.your_field_ids.raw_value model=note.tag/>'

bzr revid: chm@openerp.com-20120912081729-j6a77wqopbu3ked4
This commit is contained in:
Christophe Matthieu 2012-09-12 10:17:29 +02:00
parent e0cedfcb0b
commit 9b44f9b709
1 changed files with 39 additions and 4 deletions

View File

@ -163,9 +163,43 @@ 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"/>
*/
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(",");
//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] );
});
// 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);
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 + "']")
.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);
}
);
}
}
},
transform_list_many2many: function(){ transform_list_many2many: function(){
var self = this; var self = this;
var arg={}; var arg={};
/* Set the lists of tag/categories */ /* Set the lists of tag/categories */
@ -195,7 +229,8 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
dataset.name_get(_.uniq( arg[model] )).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-model='" + model + "'] [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){
@ -204,7 +239,6 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
); );
} }
} }
}, },
do_add_record: function() { do_add_record: function() {
this.dataset.index = null; this.dataset.index = null;
@ -395,6 +429,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
} }
this.transform_list_many2many(); this.transform_list_many2many();
this.transform_widget_many2many();
}, },
on_record_moved : function(record, old_group, old_index, new_group, new_index) { on_record_moved : function(record, old_group, old_index, new_group, new_index) {
var self = this; var self = this;
@ -411,7 +446,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
var data = {}; var data = {};
data[this.group_by] = new_group.value; data[this.group_by] = new_group.value;
this.dataset.write(record.id, data, {}, function() { this.dataset.write(record.id, data, {}, function() {
record.do_reload(); //self.do_reload();
new_group.do_save_sequences(); new_group.do_save_sequences();
}).fail(function(error, evt) { }).fail(function(error, evt) {
evt.preventDefault(); evt.preventDefault();