Now selection fields on m2o query the records directly
bzr revid: nicolas.vanhoren@openerp.com-20131022121952-piye1e3k80w217r0
This commit is contained in:
parent
ebeeae0ed4
commit
d0145bd0ec
|
@ -2803,10 +2803,44 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
|
|||
init: function(field_manager, node) {
|
||||
var self = this;
|
||||
this._super(field_manager, node);
|
||||
this.values = _(this.field.selection).chain()
|
||||
.reject(function (v) { return v[0] === false && v[1] === ''; })
|
||||
.unshift([false, ''])
|
||||
.value();
|
||||
this.set("value", false);
|
||||
this.set("values", [[false, '']]);
|
||||
this.records_orderer = new instance.web.DropMisordered();
|
||||
this.field_manager.on("view_content_has_changed", this, function() {
|
||||
var domain = new openerp.web.CompoundDomain(this.build_domain()).eval();
|
||||
if (! _.isEqual(domain, this.get("domain"))) {
|
||||
this.set("domain", domain);
|
||||
}
|
||||
});
|
||||
},
|
||||
initialize_field: function() {
|
||||
instance.web.form.ReinitializeFieldMixin.initialize_field.call(this);
|
||||
this.on("change:domain", this, this.query_values);
|
||||
this.set("domain", new openerp.web.CompoundDomain(this.build_domain()).eval());
|
||||
this.on("change:values", this, this.render_value);
|
||||
},
|
||||
query_values: function() {
|
||||
var self = this;
|
||||
var def;
|
||||
if (this.field.type === "many2one") {
|
||||
var model = new openerp.Model(openerp.session, this.field.relation);
|
||||
def = model.call("search", [this.get("domain")], {"context": this.build_context()}).then(function(record_ids) {
|
||||
return model.call("name_get", [record_ids] , {"context": self.build_context()});
|
||||
}).then(function(res) {
|
||||
return [[false, '']].concat(res);
|
||||
});
|
||||
} else {
|
||||
var values = _(this.field.selection).chain()
|
||||
.reject(function (v) { return v[0] === false && v[1] === ''; })
|
||||
.unshift([false, ''])
|
||||
.value();
|
||||
def = $.when(values);
|
||||
}
|
||||
this.records_orderer.add(def).then(function(values) {
|
||||
if (! _.isEqual(values, self.get("values"))) {
|
||||
self.set("values", values);
|
||||
}
|
||||
});
|
||||
},
|
||||
initialize_content: function() {
|
||||
// Flag indicating whether we're in an event chain containing a change
|
||||
|
@ -2838,7 +2872,7 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
|
|||
store_dom_value: function () {
|
||||
if (!this.get('effective_readonly') && this.$('select').length) {
|
||||
this.internal_set_value(
|
||||
this.values[this.$('select')[0].selectedIndex][0]);
|
||||
this.get("values")[this.$('select')[0].selectedIndex][0]);
|
||||
}
|
||||
},
|
||||
set_value: function(value_) {
|
||||
|
@ -2847,17 +2881,18 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
|
|||
this._super(value_);
|
||||
},
|
||||
render_value: function() {
|
||||
if (!this.get("effective_readonly")) {
|
||||
if (! this.get("effective_readonly")) {
|
||||
this.$().html(QWeb.render("FieldSelectionSelect", {widget: this}));
|
||||
var index = 0;
|
||||
for (var i = 0, ii = this.values.length; i < ii; i++) {
|
||||
if (this.values[i][0] === this.get('value')) index = i;
|
||||
for (var i = 0, ii = this.get("values").length; i < ii; i++) {
|
||||
if (this.get("values")[i][0] === this.get('value')) index = i;
|
||||
}
|
||||
this.$el.find('select')[0].selectedIndex = index;
|
||||
} else {
|
||||
var self = this;
|
||||
var option = _(this.values)
|
||||
var option = _(this.get("values"))
|
||||
.detect(function (record) { return record[0] === self.get('value'); });
|
||||
this.$el.text(option ? option[1] : this.values[0][1]);
|
||||
this.$el.text(option ? option[1] : this.get("values")[0][1]);
|
||||
}
|
||||
},
|
||||
focus: function() {
|
||||
|
@ -5649,7 +5684,7 @@ instance.web.form.FieldMany2ManyCheckBoxes = instance.web.form.AbstractField.ext
|
|||
this.records_orderer = new instance.web.DropMisordered();
|
||||
},
|
||||
initialize_field: function() {
|
||||
instance.web.form.ReinitializeFieldMixin.initialize_field.call(this)
|
||||
instance.web.form.ReinitializeFieldMixin.initialize_field.call(this);
|
||||
this.on("change:domain", this, this.query_records);
|
||||
this.set("domain", new openerp.web.CompoundDomain(this.build_domain()).eval());
|
||||
this.on("change:records", this, this.render_value);
|
||||
|
|
|
@ -1099,20 +1099,22 @@
|
|||
</t>
|
||||
<t t-name="FieldSelection">
|
||||
<span class="oe_form_field oe_form_field_selection" t-att-style="widget.node.attrs.style">
|
||||
<select t-if="!widget.get('effective_readonly')"
|
||||
t-att-name="widget.name"
|
||||
t-att-tabindex="widget.node.attrs.tabindex"
|
||||
t-att-autofocus="widget.node.attrs.autofocus"
|
||||
t-att-id="widget.id_for_label">
|
||||
<t t-foreach="widget.values" t-as="option">
|
||||
<option>
|
||||
<t t-esc="widget.node.attrs.placeholder" t-if="option[0] === false and widget.node.attrs.placeholder"/>
|
||||
<t t-esc="option[1]" t-if="option[0] !== false"/>
|
||||
</option>
|
||||
</t>
|
||||
</select>
|
||||
</span>
|
||||
</t>
|
||||
<t t-name="FieldSelectionSelect">
|
||||
<select t-if="!widget.get('effective_readonly')"
|
||||
t-att-name="widget.name"
|
||||
t-att-tabindex="widget.node.attrs.tabindex"
|
||||
t-att-autofocus="widget.node.attrs.autofocus"
|
||||
t-att-id="widget.id_for_label">
|
||||
<t t-foreach="widget.get('values')" t-as="option">
|
||||
<option>
|
||||
<t t-esc="widget.node.attrs.placeholder" t-if="option[0] === false and widget.node.attrs.placeholder"/>
|
||||
<t t-esc="option[1]" t-if="option[0] !== false"/>
|
||||
</option>
|
||||
</t>
|
||||
</select>
|
||||
</t>
|
||||
<t t-name="FieldRadio">
|
||||
<span t-attf-class="oe_form_field oe_form_field_radio #{widget.options.horizontal ? 'oe_horizontal' : 'oe_vertical'}" t-att-style="widget.node.attrs.style">
|
||||
<span t-if="!widget.get('effective_readonly')">
|
||||
|
|
Loading…
Reference in New Issue