Browse Source

Merge branch 'steveferry-8.0' into 8.0

pull/209/merge
Yannick Vaucher 9 years ago
parent
commit
90ce428753
  1. 28
      web_m2x_options/README.rst
  2. 2
      web_m2x_options/__openerp__.py
  3. 69
      web_m2x_options/static/src/js/form.js

28
web_m2x_options/README.rst

@ -47,6 +47,22 @@ New options
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
---------------------------
@ -61,15 +77,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.
``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``)
Number of displayed record 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:
- web_m2x_options.create: False
- web_m2x_options.create_edit: False
- web_m2x_options.m2o_dialog: False
- web_m2x_options.limit: 10
- web_m2x_options.search_more: True
Example
@ -78,7 +104,7 @@ Example
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

2
web_m2x_options/__openerp__.py

@ -2,7 +2,7 @@
{
"name": 'web_m2x_options',
"version": "0.1",
"version": "8.0.0.2",
"depends": [
'base',
'web',

69
web_m2x_options/static/src/js/form.js

@ -10,9 +10,11 @@ openerp.web_m2x_options = function (instance) {
var OPTIONS = ['web_m2x_options.create',
'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() {
this._super.apply(this, arguments);
@ -37,14 +39,30 @@ openerp.web_m2x_options = function (instance) {
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 () {
if ((typeof this.options.m2o_dialog === 'undefined' && this.can_create) ||
this.options.m2o_dialog) {
if(this.is_option_set(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();
}
},
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
@ -59,6 +77,15 @@ openerp.web_m2x_options = function (instance) {
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,
self.build_context());
var blacklist = this.get_search_blacklist();
@ -93,9 +120,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 that max
if (values.length > self.limit) {
if (values.length > self.limit || self.search_more) {
values = values.slice(0, self.limit);
values.push({
label: _t("Search More..."),
@ -152,7 +208,10 @@ openerp.web_m2x_options = function (instance) {
});
}
// Check if colors specified to wait for RPC
if (!(self.field_color && self.colors)){
def.resolve(values);
}
});
return def;

Loading…
Cancel
Save