[IMP] view_form: widget radio: clean code

bzr revid: chm@openerp.com-20130415103041-8xogdacjx43v4cgk
This commit is contained in:
Christophe Matthieu 2013-04-15 12:30:41 +02:00
parent 5623719b1c
commit ed46400a55
4 changed files with 23 additions and 29 deletions

View File

@ -2315,10 +2315,6 @@
.openerp .oe_form_field_radio.oe_horizontal {
white-space: nowrap;
}
.openerp .oe_form_field_radio:not(.oe_readonly) .oe_radio_read_only,
.openerp .oe_form_field_radio.oe_readonly .oe_radio_edit_only {
display: none;
}
.openerp .oe_form_field_radio.oe_form_required .oe_radio_input {
border: 1px solid transparent;
display: inline-block;

View File

@ -490,12 +490,6 @@ $sheet-padding: 16px
&.oe_vertical
label
margin-left: 4px
&:not(.oe_readonly)
.oe_radio_read_only
display: none
&.oe_readonly
.oe_radio_read_only
display: none
&.oe_form_required
.oe_radio_input
border: 2px solid transparent

View File

@ -2815,8 +2815,6 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
* - "no_radiolabel" don't display text values
*/
this._super(field_manager, node);
this.horizontal = +this.options.horizontal || false;
this.no_radiolabel = +this.options.no_radiolabel || false;
this.selection = _.clone(this.field.selection) || [];
this.domain = false;
},
@ -2828,7 +2826,7 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
},
click_change_value: function (event) {
var val = $(event.target).val();
val = isNaN(+val) ? val : +val;
val = this.field.type == "selection" ? val : +val;
if (val == this.get_value()) {
this.set_value(false);
} else {
@ -2856,6 +2854,9 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
def.resolve();
});
});
} else {
selection = self.selection;
def.resolve();
}
}
else if (self.field.type == "selection") {
@ -2865,17 +2866,19 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
return def.then(function () {
if (! _.isEqual(selection, self.selection)) {
self.selection = _.clone(selection);
self.$el.html($(QWeb.render("FieldRadio", {'widget': self})).html());
self.renderElement();
self.render_value();
}
});
},
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_];
if (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_);
},
@ -2884,11 +2887,12 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
return value instanceof Array ? value[0] : value;
},
render_value: function () {
var self = this;
this.$el.toggleClass("oe_readonly", this.get('effective_readonly'));
this.$("input[checked]").attr("checked", false);
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] : "");
this.$("input").filter(function () {return this.value == self.get_value()}).prop("checked", true);
this.$(".oe_radio_readonly").text(this.get('value') ? this.get('value')[1] : "");
}
}
});

View File

@ -1112,11 +1112,11 @@
</span>
</t>
<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 class="oe_radio_edit_only">
<t t-if="widget.horizontal">
<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')">
<t t-if="widget.options.horizontal">
<t t-set="width" t-value="Math.floor(100 / widget.selection.length)"/>
<t t-if="!widget.no_radiolabel">
<t t-if="!widget.options.no_radiolabel">
<t t-foreach="widget.selection" t-as="selection">
<label t-att-for="widget.uniqueId + '_' + selection[0]" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></label>
</t>
@ -1128,15 +1128,15 @@
</div>
</t>
</t>
<t t-if="!widget.horizontal">
<t t-if="!widget.options.horizontal">
<t t-foreach="widget.selection" t-as="selection">
<div>
<span class="oe_radio_input"><input type="radio" t-att-id="widget.uniqueId + '_' + selection[0]" t-att-name="widget.uniqueId" t-att-value="selection[0]"/></span><label t-if="!widget.no_radiolabel" t-att-for="widget.uniqueId + '_' + selection[0]"><t t-esc="selection[1]"/></label>
<span class="oe_radio_input"><input type="radio" t-att-id="widget.uniqueId + '_' + selection[0]" t-att-name="widget.uniqueId" t-att-value="selection[0]"/></span><label t-if="!widget.options.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"><t t-esc="widget.get('value')[1]"/></span>
<span t-if="widget.get('effective_readonly')" class="oe_radio_readonly"><t t-esc="widget.get('value')[1]"/></span>
</span>
</t>
<t t-name="FieldMany2One">