[IMP] view_form: radio button, replace image by input type radio

bzr revid: chm@openerp.com-20130410160917-4meevyiff65adspx
This commit is contained in:
Christophe Matthieu 2013-04-10 18:09:17 +02:00
parent 60be4d49c5
commit f2beb97168
6 changed files with 23 additions and 47 deletions

View File

@ -2312,25 +2312,10 @@
.openerp .oe_form_field_radio.oe_horizontal {
white-space: nowrap;
}
.openerp .oe_form_field_radio.oe_horizontal .oe_radio_header {
.openerp .oe_form_field_radio.oe_horizontal label {
display: inline-block;
text-align: center;
}
.openerp .oe_form_field_radio.oe_vertical .oe_radio_header {
cursor: pointer;
}
.openerp .oe_form_field_radio .oe_radio_input {
cursor: pointer;
display: inline-block;
width: 20px;
background: transparent url(/web/static/src/img/icons/input_radio-off.png) no-repeat center center;
}
.openerp .oe_form_field_radio .oe_radio_input_on {
background: transparent url(/web/static/src/img/icons/input_radio-on.png) no-repeat center center;
}
.openerp .oe_form_field_radio .oe_radio_label {
cursor: default;
}
.openerp .oe_form_field_progressbar.ui-progressbar {
height: 22px;
font-size: 10px;

View File

@ -483,21 +483,9 @@ $sheet-padding: 16px
.oe_form_field_radio
&.oe_horizontal
white-space: nowrap
.oe_radio_header
label
display: inline-block
text-align: center
&.oe_vertical
.oe_radio_header
cursor: pointer
.oe_radio_input {
cursor: pointer
display: inline-block
width: 20px
background: transparent url(/web/static/src/img/icons/input_radio-off.png) no-repeat center center
.oe_radio_input_on
background: transparent url(/web/static/src/img/icons/input_radio-on.png) no-repeat center center
.oe_radio_label
cursor: default
.oe_tags
&.oe_inline
min-width: 250px

Binary file not shown.

Before

Width:  |  Height:  |  Size: 512 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 559 B

View File

@ -2806,6 +2806,9 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
template: 'FieldRadio',
events: {
'click input': 'click_change_value'
},
init: function(field_manager, node) {
/* Radio button widget: Attributes options:
* - "horizontal" to display in column
@ -2820,20 +2823,18 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
this.domain = false;
},
initialize_content: function () {
this.$el.on('click', '.oe_radio_input,.oe_radio_header', this, this.on_click_change_value);
this.uniqueId = _.uniqueId("radio");
this.on("change:effective_readonly", this, this.render_value);
this.field_manager.on("view_content_has_changed", this, this.get_selection);
this.get_selection();
},
on_click_change_value: function (event) {
var id = $(event.target).data("id") || $(event.target).parent().data("id");
id = isNaN(+id) ? id : +id;
if (id && !this.get("effective_readonly")) {
if (!this.field.required && id == this.get_value()) {
this.set_value(false);
} else {
this.set_value(id);
}
click_change_value: function (event) {
var val = $(event.target).val();
val = isNaN(+val) ? val : +val;
if (val == this.get_value()) {
this.set_value(false);
} else {
this.set_value(val);
}
},
/** Get the selection and render it
@ -2887,9 +2888,11 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
render_value: function () {
this.$(".oe_radio_edit_only, .oe_radio_read_only").hide();
this.$(this.get('effective_readonly') ? ".oe_radio_read_only" : ".oe_radio_edit_only").show();
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] : "");
this.$("input[checked]").prop("checked", false);
if (this.get_value()) {
this.$("input[value='" + this.get_value() + "']").attr("checked", true);
this.$(".oe_radio_read_only .oe_radio_header").text(this.get('value') ? this.get('value')[1] : "");
}
}
});

View File

@ -1118,23 +1118,23 @@
<t t-set="width" t-value="Math.floor(100 / widget.selection.length)"/>
<t t-if="!widget.no_radiolabel">
<t t-foreach="widget.selection" t-as="selection">
<div class="oe_radio_header" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></div>
<label t-att-for="widget.uniqueId + '_' + selection[0]" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></label>
</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]">&amp;nbsp;</div>
<input type="radio" t-att-name="widget.uniqueId" t-att-id="widget.uniqueId + '_' + selection[0]" t-att-style="'width: ' + width + '%;'" t-att-value="selection[0]"/>
</t>
</t>
<t t-if="!widget.horizontal">
<t t-foreach="widget.selection" t-as="selection">
<div class="oe_radio_header" t-att-data-id="selection[0]">
<div class="oe_radio_input">&amp;nbsp;</div><t t-if="!widget.no_radiolabel" t-esc="selection[1]"/>
<div t-att-data-id="selection[0]">
<input type="radio" t-att-id="widget.uniqueId + '_' + selection[0]" t-att-name="widget.uniqueId" t-att-value="selection[0]"/>&amp;nbsp;<label t-if="!widget.no_radiolabel" t-att-for="widget.uniqueId + '_' + selection[0]"><t t-esc="selection[1]"/></label>
</div>
</t>
</t>
</span>
<span class="oe_radio_read_only"><div class="oe_radio_header"><t t-esc="widget.get('value')[1]"/></div></span>
<span class="oe_radio_read_only"><t t-esc="widget.get('value')[1]"/></span>
</span>
</t>
<t t-name="FieldMany2One">