summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2013-04-15 12:30:41 +0200
committerChristophe Matthieu <chm@openerp.com>2013-04-15 12:30:41 +0200
commited46400a55401257aca6cbb6bd1a97f3b4d632a6 (patch)
tree9ce5f89ad4e6056c100806d8a0d6905c679a3bde /addons/web
parent5623719b1c98fe22b9c71bb77113bff0f6d3d082 (diff)
[IMP] view_form: widget radio: clean code
bzr revid: chm@openerp.com-20130415103041-8xogdacjx43v4cgk
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/src/css/base.css4
-rw-r--r--addons/web/static/src/css/base.sass6
-rw-r--r--addons/web/static/src/js/view_form.js28
-rw-r--r--addons/web/static/src/xml/base.xml14
4 files changed, 23 insertions, 29 deletions
diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css
index d84b19a867e..52107bc84d7 100644
--- a/addons/web/static/src/css/base.css
+++ b/addons/web/static/src/css/base.css
@@ -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;
diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass
index df157249d83..072fda44357 100644
--- a/addons/web/static/src/css/base.sass
+++ b/addons/web/static/src/css/base.sass
@@ -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
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 2ffd80d5962..53a7425c036 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -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] : "");
}
}
});
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index d501e76f875..943326f5011 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -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">