forked from Techsystech/web
commit
506f2cc49d
|
@ -47,6 +47,22 @@ New option
|
||||||
|
|
||||||
Number of displayed record in drop-down panel
|
Number of displayed record in drop-down panel
|
||||||
|
|
||||||
|
``search_more`` *boolean*
|
||||||
|
|
||||||
|
Used to force disable/enable search more button.
|
||||||
|
|
||||||
|
``field_color`` *string*
|
||||||
|
|
||||||
|
A string to define the field used to define color.
|
||||||
|
This option has to be used with colors.
|
||||||
|
|
||||||
|
``colors`` *dictionary*
|
||||||
|
|
||||||
|
A dictionary to link field value with a HTML color.
|
||||||
|
This option has to be used with field_color.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ir.config_parameter options
|
ir.config_parameter options
|
||||||
---------------------------
|
---------------------------
|
||||||
|
@ -62,15 +78,25 @@ If you disable one option, you can enable it for particular field by setting "cr
|
||||||
|
|
||||||
Whether to display "Create and Edit..." entry in dropdown panel for all fields in the odoo instance.
|
Whether to display "Create and Edit..." entry in dropdown panel for all fields in the odoo instance.
|
||||||
|
|
||||||
|
``web_m2x_options.m2o_dialog`` *boolean* (Default: depends if user have create rights)
|
||||||
|
|
||||||
|
Whether to display the many2one dialog in case of validation error for all fields in the odoo instance.
|
||||||
|
|
||||||
``web_m2x_options.limit`` *int* (Default: openerp default value is ``7``)
|
``web_m2x_options.limit`` *int* (Default: openerp default value is ``7``)
|
||||||
|
|
||||||
Number of displayed records in drop-down panel for all fields in the odoo instance
|
Number of displayed records in drop-down panel for all fields in the odoo instance
|
||||||
|
|
||||||
|
``web_m2x_options.search_more`` *boolean* (Default: default value is ``False``)
|
||||||
|
|
||||||
|
Whether the field should always show "Search more..." entry or not.
|
||||||
|
|
||||||
To add these parameters go to Configuration -> Technical -> Parameters -> System Parameters and add new parameters like:
|
To add these parameters go to Configuration -> Technical -> Parameters -> System Parameters and add new parameters like:
|
||||||
|
|
||||||
- web_m2x_options.create: False
|
- web_m2x_options.create: False
|
||||||
- web_m2x_options.create_edit: False
|
- web_m2x_options.create_edit: False
|
||||||
|
- web_m2x_options.m2o_dialog: False
|
||||||
- web_m2x_options.limit: 10
|
- web_m2x_options.limit: 10
|
||||||
|
- web_m2x_options.search_more: True
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
|
@ -79,7 +105,7 @@ Example
|
||||||
Your XML form view definition could contain::
|
Your XML form view definition could contain::
|
||||||
|
|
||||||
...
|
...
|
||||||
<field name="partner_id" options="{'limit': 10, 'create': false, 'create_edit': false}"/>
|
<field name="partner_id" options="{'limit': 10, 'create': false, 'create_edit': false, 'search_more':true 'field_color':'state', 'colors':{'active':'green'}}"/>
|
||||||
...
|
...
|
||||||
|
|
||||||
Note
|
Note
|
||||||
|
|
|
@ -12,12 +12,16 @@ Add new options for many2one and many2manytags field:
|
||||||
- create_edit: true/false -> disable "create and edit" entry in dropdown panel
|
- create_edit: true/false -> disable "create and edit" entry in dropdown panel
|
||||||
- limit: 10 (int) -> change number of selected record return in dropdown panel
|
- limit: 10 (int) -> change number of selected record return in dropdown panel
|
||||||
- m2o_dialog: true/false -> disable quick create M20Dialog triggered on error.
|
- m2o_dialog: true/false -> disable quick create M20Dialog triggered on error.
|
||||||
|
- search_more: true/false -> force disable/enable search more button.
|
||||||
|
- field_color -> define the field used to define color.
|
||||||
|
- colors -> link field values to a HTML color.
|
||||||
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
--------
|
--------
|
||||||
|
|
||||||
``<field name="partner_id" options="{'limit': 10, 'create': false,
|
``<field name="partner_id" options="{'limit': 10, 'create': false,
|
||||||
'create_edit': false}"/>``
|
'create_edit': false, 'field_color':'state', 'colors':{'active':'green'}}"/>``
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
-----
|
-----
|
||||||
|
|
|
@ -10,9 +10,11 @@ openerp.web_m2x_options = function (instance) {
|
||||||
|
|
||||||
var OPTIONS = ['web_m2x_options.create',
|
var OPTIONS = ['web_m2x_options.create',
|
||||||
'web_m2x_options.create_edit',
|
'web_m2x_options.create_edit',
|
||||||
'web_m2x_options.limit',];
|
'web_m2x_options.limit',
|
||||||
|
'web_m2x_options.search_more',
|
||||||
|
'web_m2x_options.m2o_dialog',];
|
||||||
|
|
||||||
instance.web.form.FieldMany2One.include({
|
instance.web.form.FieldMany2One = instance.web.form.FieldMany2One.extend({
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
|
@ -37,15 +39,30 @@ openerp.web_m2x_options = function (instance) {
|
||||||
return $.when();
|
return $.when();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
is_option_set: function(option) {
|
||||||
|
if (_.isUndefined(option)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var is_string = typeof option === 'string'
|
||||||
|
var is_bool = typeof option === 'boolean'
|
||||||
|
if (is_string) {
|
||||||
|
return option === 'true' || option === 'True'
|
||||||
|
} else if (is_bool) {
|
||||||
|
return option
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
|
||||||
show_error_displayer: function () {
|
show_error_displayer: function () {
|
||||||
if ((typeof this.options.m2o_dialog === 'undefined' && this.can_create) ||
|
if(this.is_option_set(this.options.m2o_dialog) ||
|
||||||
this.options.m2o_dialog) {
|
_.isUndefined(this.options.m2o_dialog) && this.is_option_set(this.view.ir_options['web_m2x_options.m2o_dialog']) ||
|
||||||
|
this.can_create && _.isUndefined(this.options.m2o_dialog) && _.isUndefined(this.view.ir_options['web_m2x_options.m2o_dialog'])) {
|
||||||
new instance.web.form.M2ODialog(this).open();
|
new instance.web.form.M2ODialog(this).open();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get_search_result: function (search_val) {
|
get_search_result: function (search_val) {
|
||||||
|
var Objects = new instance.web.Model(this.field.relation);
|
||||||
var def = $.Deferred();
|
var def = $.Deferred();
|
||||||
var self = this;
|
var self = this;
|
||||||
// add options limit used to change number of selections record
|
// add options limit used to change number of selections record
|
||||||
|
@ -61,6 +78,15 @@ openerp.web_m2x_options = function (instance) {
|
||||||
this.limit = this.options.limit;
|
this.limit = this.options.limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add options search_more to force enable or disable search_more button
|
||||||
|
if (this.is_option_set(this.options.search_more) || _.isUndefined(this.options.search_more) && this.is_option_set(self.view.ir_options['web_m2x_options.search_more'])) {
|
||||||
|
this.search_more = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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,
|
var dataset = new instance.web.DataSet(this, this.field.relation,
|
||||||
self.build_context());
|
self.build_context());
|
||||||
var blacklist = this.get_search_blacklist();
|
var blacklist = this.get_search_blacklist();
|
||||||
|
@ -98,9 +124,38 @@ openerp.web_m2x_options = function (instance) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
for (var index in objects) {
|
||||||
|
for (var index_value in values) {
|
||||||
|
if (values[index_value].id == objects[index].id) {
|
||||||
|
// Find value in values by comparing ids
|
||||||
|
var value = values[index_value];
|
||||||
|
|
||||||
|
// Find color with field value as key
|
||||||
|
var color = self.colors[objects[index][self.field_color]] || 'black';
|
||||||
|
value.label = '<span style="color:'+color+'">'+value.label+'</span>';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
def.resolve(values);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// search more... if more results than max
|
// search more... if more results than max
|
||||||
|
|
||||||
if (values.length > self.limit) {
|
if (values.length > self.limit || self.search_more) {
|
||||||
values = values.slice(0, self.limit);
|
values = values.slice(0, self.limit);
|
||||||
values.push({
|
values.push({
|
||||||
label: _t("Search More..."),
|
label: _t("Search More..."),
|
||||||
|
@ -158,7 +213,10 @@ openerp.web_m2x_options = function (instance) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if colors specified to wait for RPC
|
||||||
|
if (!(self.field_color && self.colors)){
|
||||||
def.resolve(values);
|
def.resolve(values);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|
Loading…
Reference in New Issue