[IMP] view_form: radio button for many2one
bzr revid: chm@openerp.com-20130329113827-me6d3ho6jrp525f0
This commit is contained in:
parent
2653bcf329
commit
e3d1e4fb44
|
@ -2814,21 +2814,60 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
|
||||||
*/
|
*/
|
||||||
var self = this;
|
var self = this;
|
||||||
this._super(field_manager, node);
|
this._super(field_manager, node);
|
||||||
this.horizontal = +this.options.horizontal;
|
this.horizontal = +this.options.horizontal || false;
|
||||||
this.no_radiolabel = +this.options.no_radiolabel;
|
this.no_radiolabel = +this.options.no_radiolabel || false;
|
||||||
this.display_readonly = +this.options.display_readonly;
|
this.display_readonly = +this.options.display_readonly || false;
|
||||||
|
this.selection = this.field.selection || [];
|
||||||
|
this.domain = false;
|
||||||
},
|
},
|
||||||
initialize_content: function () {
|
initialize_content: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$el.on('click', '.oe_radio_input,.oe_radio_header', function (event) {
|
this.$el.on('click', '.oe_radio_input,.oe_radio_header', function (e) {self.on_click_change_value(e)});
|
||||||
var id = $(event.target).data("id");
|
this.field_manager.on("view_content_has_changed", this, this.get_selection);
|
||||||
id = isNaN(+id) ? id : +id;
|
},
|
||||||
if (id && !self.get("effective_readonly")) {
|
on_click_change_value: function (event) {
|
||||||
if (!self.field.required && id == self.get_value()) {
|
var id = $(event.target).data("id") || $(event.target).parent().data("id");
|
||||||
self.set_value(false);
|
id = isNaN(+id) ? id : +id;
|
||||||
} else {
|
if (id && !this.get("effective_readonly")) {
|
||||||
self.set_value(id);
|
if (!this.field.required && id == this.get_value()) {
|
||||||
}
|
this.set_value(false);
|
||||||
|
} else {
|
||||||
|
this.set_value(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** Get the selection and render it
|
||||||
|
* selection: [[identifier, value_to_display], ...]
|
||||||
|
* For selection fields: this is directly given by this.field.selection
|
||||||
|
* For many2one fields: perform a search on the relation of the many2one field
|
||||||
|
*/
|
||||||
|
get_selection: function() {
|
||||||
|
var self = this;
|
||||||
|
var selection = [];
|
||||||
|
var def = $.Deferred();
|
||||||
|
if (self.field.type == "many2one") {
|
||||||
|
var domain = instance.web.pyeval.eval('domain', this.build_domain()) || [];
|
||||||
|
if (! _.isEqual(self.domain, domain)) {
|
||||||
|
self.domain = domain;
|
||||||
|
new instance.web.DataSetSearch(self, self.field.relation, self.build_context(), self.domain)
|
||||||
|
.read_slice(['name'], {})
|
||||||
|
.then(function (records) {
|
||||||
|
for(var i = 0; i < records.length; i++) {
|
||||||
|
selection.push([records[i].id, records[i].name]);
|
||||||
|
}
|
||||||
|
def.resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (self.field.type == "selection") {
|
||||||
|
selection = self.field.selection || [];
|
||||||
|
def.resolve();
|
||||||
|
}
|
||||||
|
def.then(function () {
|
||||||
|
if (! _.isEqual(selection, self.get('selection'))) {
|
||||||
|
self.selection = selection;
|
||||||
|
self.$el.html($(QWeb.render("FieldRadio", {'widget': self})).html());
|
||||||
|
self.set("selection", _.clone(this.selection));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1114,20 +1114,20 @@
|
||||||
<t t-name="FieldRadio">
|
<t t-name="FieldRadio">
|
||||||
<span t-attf-class="oe_form_field oe_form_field_radio #{widget.horizontal ? 'oe_horizontal' : 'oe_vertical'}" t-att-style="widget.node.attrs.style">
|
<span t-attf-class="oe_form_field oe_form_field_radio #{widget.horizontal ? 'oe_horizontal' : 'oe_vertical'}" t-att-style="widget.node.attrs.style">
|
||||||
<t t-if="widget.horizontal">
|
<t t-if="widget.horizontal">
|
||||||
<t t-set="width" t-value="Math.floor(100 / widget.field.selection.length)"/>
|
<t t-set="width" t-value="Math.floor(100 / widget.selection.length)"/>
|
||||||
<t t-if="!widget.no_radiolabel">
|
<t t-if="!widget.no_radiolabel">
|
||||||
<t t-foreach="widget.field.selection" t-as="selection">
|
<t t-foreach="widget.selection" t-as="selection">
|
||||||
<div class="oe_radio_header" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></div>
|
<div class="oe_radio_header" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></div>
|
||||||
</t>
|
</t>
|
||||||
<br/>
|
<br/>
|
||||||
</t>
|
</t>
|
||||||
<t t-foreach="widget.field.selection" t-as="selection">
|
<t t-foreach="widget.selection" t-as="selection">
|
||||||
<div class="oe_radio_input" t-att-style="'width: ' + width + '%;'" t-att-data-id="selection[0]">&nbsp;</div>
|
<div class="oe_radio_input" t-att-style="'width: ' + width + '%;'" t-att-data-id="selection[0]">&nbsp;</div>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
<t t-if="!widget.horizontal">
|
<t t-if="!widget.horizontal">
|
||||||
<t t-foreach="widget.field.selection" t-as="selection">
|
<t t-foreach="widget.selection" t-as="selection">
|
||||||
<div class="oe_radio_header" t-att-style="'width: ' + width + '%;'" t-att-data-id="selection[0]">
|
<div class="oe_radio_header" t-att-data-id="selection[0]">
|
||||||
<div class="oe_radio_input">&nbsp;</div><t t-if="!widget.no_radiolabel" t-esc="selection[1]"/>
|
<div class="oe_radio_input">&nbsp;</div><t t-if="!widget.no_radiolabel" t-esc="selection[1]"/>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
Loading…
Reference in New Issue