summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2013-10-22 14:19:52 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2013-10-22 14:19:52 +0200
commitd0145bd0ec5b27c5fb76e1a0814e588ed8758e2e (patch)
treedb12469610d90901961177ebe7658a2ccb03a663 /addons/web/static/src
parentebeeae0ed4c57e36db143c11de11174ca1330892 (diff)
Now selection fields on m2o query the records directly
bzr revid: nicolas.vanhoren@openerp.com-20131022121952-piye1e3k80w217r0
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/view_form.js57
-rw-r--r--addons/web/static/src/xml/base.xml26
2 files changed, 60 insertions, 23 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 7a0890bdcfa..1bcd01e255e 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -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);
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index 46241435fcf..f7cde7ce54d 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -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')">