forked from Techsystech/web
Merge branch 'Antiun-pr-web_m2x_options_fix' into 8.0
commit
dae7460ce8
|
@ -67,11 +67,11 @@ openerp.web_m2x_options = function (instance) {
|
||||||
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
|
||||||
// returned.
|
// returned.
|
||||||
if (_.isUndefined(this.view))
|
if (_.isUndefined(this.view))
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
|
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
|
||||||
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
|
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof this.options.limit === 'number') {
|
if (typeof this.options.limit === 'number') {
|
||||||
this.limit = this.options.limit;
|
this.limit = this.options.limit;
|
||||||
|
@ -99,8 +99,7 @@ openerp.web_m2x_options = function (instance) {
|
||||||
self.build_context()));
|
self.build_context()));
|
||||||
|
|
||||||
var create_rights;
|
var create_rights;
|
||||||
if (typeof this.options.create === "undefined" ||
|
if (!(self.options && (self.options.no_create || self.options.no_create_edit))) {
|
||||||
typeof this.options.create_edit === "undefined") {
|
|
||||||
create_rights = new instance.web.Model(this.field.relation).call(
|
create_rights = new instance.web.Model(this.field.relation).call(
|
||||||
"check_access_rights", ["create", false]);
|
"check_access_rights", ["create", false]);
|
||||||
}
|
}
|
||||||
|
@ -119,7 +118,7 @@ openerp.web_m2x_options = function (instance) {
|
||||||
id: x[0],
|
id: x[0],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Search result value colors
|
// Search result value colors
|
||||||
|
|
||||||
if (self.colors && self.field_color) {
|
if (self.colors && self.field_color) {
|
||||||
|
@ -127,7 +126,7 @@ openerp.web_m2x_options = function (instance) {
|
||||||
for (var index in values) {
|
for (var index in values) {
|
||||||
value_ids.push(values[index].id);
|
value_ids.push(values[index].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPC request to get field_color from Objects
|
// RPC request to get field_color from Objects
|
||||||
Objects.query([self.field_color])
|
Objects.query([self.field_color])
|
||||||
.filter([['id', 'in', value_ids]])
|
.filter([['id', 'in', value_ids]])
|
||||||
|
@ -137,7 +136,7 @@ openerp.web_m2x_options = function (instance) {
|
||||||
if (values[index_value].id == objects[index].id) {
|
if (values[index_value].id == objects[index].id) {
|
||||||
// Find value in values by comparing ids
|
// Find value in values by comparing ids
|
||||||
var value = values[index_value];
|
var value = values[index_value];
|
||||||
|
|
||||||
// Find color with field value as key
|
// Find color with field value as key
|
||||||
var color = self.colors[objects[index][self.field_color]] || 'black';
|
var color = self.colors[objects[index][self.field_color]] || 'black';
|
||||||
value.label = '<span style="color:'+color+'">'+value.label+'</span>';
|
value.label = '<span style="color:'+color+'">'+value.label+'</span>';
|
||||||
|
@ -171,10 +170,15 @@ openerp.web_m2x_options = function (instance) {
|
||||||
var raw_result = _(data.result).map(function (x) {
|
var raw_result = _(data.result).map(function (x) {
|
||||||
return x[1];
|
return x[1];
|
||||||
});
|
});
|
||||||
|
var no_quick_create = (
|
||||||
|
self.options && (self.options.no_create ||
|
||||||
|
self.options.no_quick_create)
|
||||||
|
)
|
||||||
|
var m2x_create_undef = _.isUndefined(self.view.ir_options['web_m2x_options.create'])
|
||||||
|
var m2x_create = self.view.ir_options['web_m2x_options.create'] == "True"
|
||||||
|
|
||||||
if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create']) && can_create) ||
|
if (!no_quick_create && ((m2x_create_undef && can_create) ||
|
||||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == "True") ||
|
m2x_create)) {
|
||||||
self.options.create) {
|
|
||||||
|
|
||||||
if (search_val.length > 0 &&
|
if (search_val.length > 0 &&
|
||||||
!_.include(raw_result, search_val)) {
|
!_.include(raw_result, search_val)) {
|
||||||
|
@ -192,10 +196,15 @@ openerp.web_m2x_options = function (instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create...
|
// create...
|
||||||
|
var no_create_edit = (
|
||||||
|
self.options && (self.options.no_create ||
|
||||||
|
self.options.no_create_edit)
|
||||||
|
)
|
||||||
|
var m2x_create_edit_undef = _.isUndefined(self.view.ir_options['web_m2x_options.create_edit'])
|
||||||
|
var m2x_create_edit = self.view.ir_options['web_m2x_options.create_edit'] == "True"
|
||||||
|
|
||||||
if ((_.isUndefined(self.options.create_edit) && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit']) && can_create) ||
|
if (!no_create_edit && ((m2x_create_edit_undef && can_create) ||
|
||||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == "True") ||
|
m2x_create_edit)) {
|
||||||
self.options.create_edit) {
|
|
||||||
|
|
||||||
values.push({
|
values.push({
|
||||||
label: _t("Create and Edit..."),
|
label: _t("Create and Edit..."),
|
||||||
|
@ -207,7 +216,7 @@ openerp.web_m2x_options = function (instance) {
|
||||||
classname: 'oe_m2o_dropdown_option'
|
classname: 'oe_m2o_dropdown_option'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if colors specified to wait for RPC
|
// Check if colors specified to wait for RPC
|
||||||
if (!(self.field_color && self.colors)){
|
if (!(self.field_color && self.colors)){
|
||||||
def.resolve(values);
|
def.resolve(values);
|
||||||
|
@ -226,28 +235,28 @@ openerp.web_m2x_options = function (instance) {
|
||||||
new instance.web.form.M2ODialog(this).open();
|
new instance.web.form.M2ODialog(this).open();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function() {
|
|
||||||
this._super.apply(this, arguments);
|
|
||||||
return this.get_options();
|
|
||||||
},
|
|
||||||
|
|
||||||
get_options: function() {
|
start: function() {
|
||||||
var self = this;
|
this._super.apply(this, arguments);
|
||||||
if (_.isUndefined(this.view.ir_options_loaded)) {
|
return this.get_options();
|
||||||
this.view.ir_options_loaded = $.Deferred();
|
},
|
||||||
this.view.ir_options = {};
|
|
||||||
(new instance.web.Model("ir.config_parameter"))
|
get_options: function() {
|
||||||
.query(["key", "value"]).filter([['key', 'in', OPTIONS]])
|
var self = this;
|
||||||
.all().then(function(records) {
|
if (_.isUndefined(this.view.ir_options_loaded)) {
|
||||||
_(records).each(function(record) {
|
this.view.ir_options_loaded = $.Deferred();
|
||||||
self.view.ir_options[record.key] = record.value;
|
this.view.ir_options = {};
|
||||||
});
|
(new instance.web.Model("ir.config_parameter"))
|
||||||
self.view.ir_options_loaded.resolve();
|
.query(["key", "value"]).filter([['key', 'in', OPTIONS]])
|
||||||
});
|
.all().then(function(records) {
|
||||||
}
|
_(records).each(function(record) {
|
||||||
return this.view.ir_options_loaded;
|
self.view.ir_options[record.key] = record.value;
|
||||||
},
|
});
|
||||||
|
self.view.ir_options_loaded.resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.view.ir_options_loaded;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this method to search using a string.
|
* Call this method to search using a string.
|
||||||
|
@ -258,10 +267,10 @@ openerp.web_m2x_options = function (instance) {
|
||||||
|
|
||||||
// add options limit used to change number of selections record
|
// add options limit used to change number of selections record
|
||||||
// returned.
|
// returned.
|
||||||
|
|
||||||
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
|
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
|
||||||
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
|
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof this.options.limit === 'number') {
|
if (typeof this.options.limit === 'number') {
|
||||||
this.limit = this.options.limit;
|
this.limit = this.options.limit;
|
||||||
|
@ -300,10 +309,14 @@ openerp.web_m2x_options = function (instance) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// quick create
|
// quick create
|
||||||
|
var no_quick_create = (
|
||||||
|
self.options && (self.options.no_create ||
|
||||||
|
self.options.no_quick_create)
|
||||||
|
)
|
||||||
|
var m2x_create_undef = _.isUndefined(self.view.ir_options['web_m2x_options.create'])
|
||||||
|
var m2x_create = self.view.ir_options['web_m2x_options.create'] == "True"
|
||||||
|
|
||||||
if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create'])) ||
|
if (!no_quick_create && (m2x_create_undef || m2x_create)) {
|
||||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == 'True') ||
|
|
||||||
self.options.create) {
|
|
||||||
|
|
||||||
var raw_result = _(data.result).map(function(x) {return x[1];});
|
var raw_result = _(data.result).map(function(x) {return x[1];});
|
||||||
if (search_val.length > 0 && !_.include(raw_result, search_val)) {
|
if (search_val.length > 0 && !_.include(raw_result, search_val)) {
|
||||||
|
@ -319,10 +332,14 @@ openerp.web_m2x_options = function (instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create...
|
// create...
|
||||||
|
var no_create_edit = (
|
||||||
|
self.options && (self.options.no_create ||
|
||||||
|
self.options.no_create_edit)
|
||||||
|
)
|
||||||
|
var m2x_create_edit_undef = _.isUndefined(self.view.ir_options['web_m2x_options.create_edit'])
|
||||||
|
var m2x_create_edit = self.view.ir_options['web_m2x_options.create_edit'] == "True"
|
||||||
|
|
||||||
if ((_.isUndefined(self.options.create_edit === 'undefined') && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit'])) ||
|
if (!no_create_edit && (m2x_create_edit_undef || m2x_create_edit)) {
|
||||||
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == 'True') ||
|
|
||||||
self.options.create_edit) {
|
|
||||||
|
|
||||||
values.push({
|
values.push({
|
||||||
label: _t("Create and Edit..."),
|
label: _t("Create and Edit..."),
|
||||||
|
|
Loading…
Reference in New Issue