|
@ -8,8 +8,35 @@ openerp.web_m2x_options = function (instance) { |
|
|
_t = instance.web._t, |
|
|
_t = instance.web._t, |
|
|
_lt = instance.web._lt; |
|
|
_lt = instance.web._lt; |
|
|
|
|
|
|
|
|
|
|
|
var OPTIONS = ['web_m2x_options.create', |
|
|
|
|
|
'web_m2x_options.create_edit', |
|
|
|
|
|
'web_m2x_options.limit',]; |
|
|
|
|
|
|
|
|
instance.web.form.FieldMany2One.include({ |
|
|
instance.web.form.FieldMany2One.include({ |
|
|
|
|
|
|
|
|
|
|
|
start: function() { |
|
|
|
|
|
this._super.apply(this, arguments); |
|
|
|
|
|
return this.get_options(); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get_options: function() { |
|
|
|
|
|
var self = this; |
|
|
|
|
|
if (!_.isUndefined(this.view) && _.isUndefined(this.view.ir_options_loaded)) { |
|
|
|
|
|
this.view.ir_options_loaded = $.Deferred(); |
|
|
|
|
|
this.view.ir_options = {}; |
|
|
|
|
|
(new instance.web.Model("ir.config_parameter")) |
|
|
|
|
|
.query(["key", "value"]).filter([['key', 'in', OPTIONS]]) |
|
|
|
|
|
.all().then(function(records) { |
|
|
|
|
|
_(records).each(function(record) { |
|
|
|
|
|
self.view.ir_options[record.key] = record.value; |
|
|
|
|
|
}); |
|
|
|
|
|
self.view.ir_options_loaded.resolve(); |
|
|
|
|
|
}); |
|
|
|
|
|
return this.view.ir_options_loaded; |
|
|
|
|
|
} |
|
|
|
|
|
return $.when(); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
show_error_displayer: function () { |
|
|
show_error_displayer: function () { |
|
|
if ((typeof this.options.m2o_dialog === 'undefined' && this.can_create) || |
|
|
if ((typeof this.options.m2o_dialog === 'undefined' && this.can_create) || |
|
|
this.options.m2o_dialog) { |
|
|
this.options.m2o_dialog) { |
|
@ -18,11 +45,15 @@ openerp.web_m2x_options = function (instance) { |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
get_search_result: function (search_val) { |
|
|
get_search_result: function (search_val) { |
|
|
|
|
|
|
|
|
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
|
|
|
// returned.
|
|
|
// returned.
|
|
|
|
|
|
if (_.isUndefined(this.view)) |
|
|
|
|
|
return this._super.apply(this, arguments); |
|
|
|
|
|
if (!_.isUndefined(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; |
|
@ -47,10 +78,7 @@ openerp.web_m2x_options = function (instance) { |
|
|
"check_access_rights", ["create", false]); |
|
|
"check_access_rights", ["create", false]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$.when(search_result, create_rights).then(function (_data, _can_create) { |
|
|
|
|
|
var data = _data[0]; |
|
|
|
|
|
|
|
|
|
|
|
var can_create = _can_create ? _can_create[0] : null; |
|
|
|
|
|
|
|
|
$.when(search_result, create_rights).then(function (data, can_create) { |
|
|
|
|
|
|
|
|
self.can_create = can_create; // for ``.show_error_displayer()``
|
|
|
self.can_create = can_create; // for ``.show_error_displayer()``
|
|
|
self.last_search = data; |
|
|
self.last_search = data; |
|
@ -88,7 +116,8 @@ openerp.web_m2x_options = function (instance) { |
|
|
return x[1]; |
|
|
return x[1]; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if ((typeof self.options.create === 'undefined' && can_create) || |
|
|
|
|
|
|
|
|
if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create']) && can_create) || |
|
|
|
|
|
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == "True") || |
|
|
self.options.create) { |
|
|
self.options.create) { |
|
|
|
|
|
|
|
|
if (search_val.length > 0 && |
|
|
if (search_val.length > 0 && |
|
@ -108,7 +137,8 @@ openerp.web_m2x_options = function (instance) { |
|
|
|
|
|
|
|
|
// create...
|
|
|
// create...
|
|
|
|
|
|
|
|
|
if ((typeof self.options.create_edit === 'undefined' && can_create) || |
|
|
|
|
|
|
|
|
if ((_.isUndefined(self.options.create_edit) && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit']) && can_create) || |
|
|
|
|
|
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == "True") || |
|
|
self.options.create_edit) { |
|
|
self.options.create_edit) { |
|
|
|
|
|
|
|
|
values.push({ |
|
|
values.push({ |
|
@ -138,6 +168,28 @@ openerp.web_m2x_options = function (instance) { |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
start: function() { |
|
|
|
|
|
this._super.apply(this, arguments); |
|
|
|
|
|
return this.get_options(); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get_options: function() { |
|
|
|
|
|
var self = this; |
|
|
|
|
|
if (_.isUndefined(this.view.ir_options_loaded)) { |
|
|
|
|
|
this.view.ir_options_loaded = $.Deferred(); |
|
|
|
|
|
this.view.ir_options = {}; |
|
|
|
|
|
(new instance.web.Model("ir.config_parameter")) |
|
|
|
|
|
.query(["key", "value"]).filter([['key', 'in', OPTIONS]]) |
|
|
|
|
|
.all().then(function(records) { |
|
|
|
|
|
_(records).each(function(record) { |
|
|
|
|
|
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. |
|
|
*/ |
|
|
*/ |
|
@ -148,6 +200,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'])) { |
|
|
|
|
|
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; |
|
|
} |
|
|
} |
|
@ -186,7 +242,8 @@ openerp.web_m2x_options = function (instance) { |
|
|
} |
|
|
} |
|
|
// quick create
|
|
|
// quick create
|
|
|
|
|
|
|
|
|
if ((typeof self.options.create === 'undefined') || |
|
|
|
|
|
|
|
|
if ((_.isUndefined(self.options.create) && _.isUndefined(self.view.ir_options['web_m2x_options.create'])) || |
|
|
|
|
|
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create'] == 'True') || |
|
|
self.options.create) { |
|
|
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];}); |
|
@ -204,7 +261,8 @@ openerp.web_m2x_options = function (instance) { |
|
|
|
|
|
|
|
|
// create...
|
|
|
// create...
|
|
|
|
|
|
|
|
|
if ((typeof self.options.create_edit === 'undefined') || |
|
|
|
|
|
|
|
|
if ((_.isUndefined(self.options.create_edit === 'undefined') && _.isUndefined(self.view.ir_options['web_m2x_options.create_edit'])) || |
|
|
|
|
|
(_.isUndefined(self.options.create) && self.view.ir_options['web_m2x_options.create_edit'] == 'True') || |
|
|
self.options.create_edit) { |
|
|
self.options.create_edit) { |
|
|
|
|
|
|
|
|
values.push({ |
|
|
values.push({ |
|
|