Browse Source

Add options to colors many2x field depending on specified field

pull/209/merge
David Coninckx 9 years ago
committed by Yannick Vaucher
parent
commit
165caa8cee
  1. 38
      web_m2x_options/static/src/js/form.js

38
web_m2x_options/static/src/js/form.js

@ -12,7 +12,7 @@ openerp.web_m2x_options = function (instance) {
'web_m2x_options.create_edit',
'web_m2x_options.limit',];
instance.web.form.FieldMany2One.include({
instance.web.form.FieldMany2One = instance.web.form.FieldMany2One.extend({
start: function() {
this._super.apply(this, arguments);
@ -45,6 +45,7 @@ openerp.web_m2x_options = function (instance) {
},
get_search_result: function (search_val) {
var Objects = new instance.web.Model(this.field.relation);
var def = $.Deferred();
var self = this;
// add options limit used to change number of selections record
@ -63,7 +64,11 @@ openerp.web_m2x_options = function (instance) {
if(typeof this.options.search_more === 'boolean') {
this.search_more = this.options.search_more
}
// add options field_color and colors to color item(s) depending on field_color value
this.field_color = this.options.field_color
this.colors = this.options.colors
var dataset = new instance.web.DataSet(this, this.field.relation,
self.build_context());
var blacklist = this.get_search_blacklist();
@ -97,6 +102,28 @@ openerp.web_m2x_options = function (instance) {
id: x[0],
};
});
// Search result value colors
if (self.colors && self.field_color) {
var value_ids = [];
for (var index in values) {
value_ids.push(values[index].id);
}
// RPC request to get field_color from Objects
Objects.query([self.field_color])
.filter([['id', 'in', value_ids]])
.all().done(function (objects) {
console.log(objects);
for (var index in objects) {
var value = values[index];
var color = self.colors[objects[index].state] || 'black';
value.label = '<span style="color:'+color+'">'+value.label+'</span>';
}
def.resolve(values);
});
}
// search more... if more results that max
@ -156,8 +183,11 @@ openerp.web_m2x_options = function (instance) {
classname: 'oe_m2o_dropdown_option'
});
}
def.resolve(values);
// Check if colors specified to wait for RPC
if (!(self.field_color && self.colors)){
def.resolve(values);
}
});
return def;

Loading…
Cancel
Save