From ed46400a55401257aca6cbb6bd1a97f3b4d632a6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 15 Apr 2013 12:30:41 +0200 Subject: [PATCH] [IMP] view_form: widget radio: clean code bzr revid: chm@openerp.com-20130415103041-8xogdacjx43v4cgk --- addons/web/static/src/css/base.css | 4 ---- addons/web/static/src/css/base.sass | 6 ------ addons/web/static/src/js/view_form.js | 28 +++++++++++++++------------ addons/web/static/src/xml/base.xml | 14 +++++++------- 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 @@ - - - + + + - + @@ -1128,15 +1128,15 @@ - +
- +
- +