[IMP] view_form: field radio, display only the selected text in read only mode
bzr revid: chm@openerp.com-20130410135643-szjzolgpbr73kpxh
This commit is contained in:
parent
c756cb72b6
commit
60be4d49c5
|
@ -2820,8 +2820,8 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
|
||||||
this.domain = false;
|
this.domain = false;
|
||||||
},
|
},
|
||||||
initialize_content: function () {
|
initialize_content: function () {
|
||||||
var self = this;
|
this.$el.on('click', '.oe_radio_input,.oe_radio_header', this, this.on_click_change_value);
|
||||||
this.$el.on('click', '.oe_radio_input,.oe_radio_header', function (e) {self.on_click_change_value(e)});
|
this.on("change:effective_readonly", this, this.render_value);
|
||||||
this.field_manager.on("view_content_has_changed", this, this.get_selection);
|
this.field_manager.on("view_content_has_changed", this, this.get_selection);
|
||||||
this.get_selection();
|
this.get_selection();
|
||||||
},
|
},
|
||||||
|
@ -2871,14 +2871,25 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
set_value: function (value_) {
|
||||||
|
if (this.field.type == "selection") {
|
||||||
|
value_ = _.find(this.field.selection, function (sel) { return sel[0] == value_});
|
||||||
|
}
|
||||||
|
else if (!this.selection.length) {
|
||||||
|
this.selection = [value_];
|
||||||
|
}
|
||||||
|
this._super(value_);
|
||||||
|
},
|
||||||
get_value: function () {
|
get_value: function () {
|
||||||
var id = this.get('value');
|
var value = this.get('value');
|
||||||
return _.isNumber(id) ? id : id[0];
|
return value instanceof Array ? value[0] : value;
|
||||||
},
|
},
|
||||||
render_value: function () {
|
render_value: function () {
|
||||||
var self = this;
|
this.$(".oe_radio_edit_only, .oe_radio_read_only").hide();
|
||||||
self.$(".oe_radio_input_on").removeClass("oe_radio_input_on");
|
this.$(this.get('effective_readonly') ? ".oe_radio_read_only" : ".oe_radio_edit_only").show();
|
||||||
self.$(".oe_radio_input[data-id='" + self.get_value() + "'], [data-id='" + self.get_value() + "'] .oe_radio_input").addClass("oe_radio_input_on");
|
this.$(".oe_radio_input_on").removeClass("oe_radio_input_on");
|
||||||
|
this.$(".oe_radio_input[data-id='" + this.get_value() + "'], [data-id='" + this.get_value() + "'] .oe_radio_input").addClass("oe_radio_input_on");
|
||||||
|
this.$(".oe_radio_read_only .oe_radio_header").text(this.get('value') ? this.get('value')[1] : "");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1113,25 +1113,28 @@
|
||||||
</t>
|
</t>
|
||||||
<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">
|
<span class="oe_radio_edit_only">
|
||||||
<t t-set="width" t-value="Math.floor(100 / widget.selection.length)"/>
|
<t t-if="widget.horizontal">
|
||||||
<t t-if="!widget.no_radiolabel">
|
<t t-set="width" t-value="Math.floor(100 / widget.selection.length)"/>
|
||||||
<t t-foreach="widget.selection" t-as="selection">
|
<t t-if="!widget.no_radiolabel">
|
||||||
<div class="oe_radio_header" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></div>
|
<t t-foreach="widget.selection" t-as="selection">
|
||||||
|
<div class="oe_radio_header" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></div>
|
||||||
|
</t>
|
||||||
|
<br/>
|
||||||
|
</t>
|
||||||
|
<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>
|
||||||
</t>
|
</t>
|
||||||
<br/>
|
|
||||||
</t>
|
</t>
|
||||||
<t t-foreach="widget.selection" t-as="selection">
|
<t t-if="!widget.horizontal">
|
||||||
<div class="oe_radio_input" t-att-style="'width: ' + width + '%;'" t-att-data-id="selection[0]">&nbsp;</div>
|
<t t-foreach="widget.selection" t-as="selection">
|
||||||
|
<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>
|
||||||
|
</t>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</span>
|
||||||
<t t-if="!widget.horizontal">
|
<span class="oe_radio_read_only"><div class="oe_radio_header"><t t-esc="widget.get('value')[1]"/></div></span>
|
||||||
<t t-foreach="widget.selection" t-as="selection">
|
|
||||||
<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>
|
|
||||||
</t>
|
|
||||||
</t>
|
|
||||||
</span>
|
</span>
|
||||||
</t>
|
</t>
|
||||||
<t t-name="FieldMany2One">
|
<t t-name="FieldMany2One">
|
||||||
|
|
Loading…
Reference in New Issue