diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index a6fd8da472c..52107bc84d7 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2315,24 +2315,26 @@ .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_form_required .oe_radio_input { + border: 1px solid transparent; + display: inline-block; + height: 12px; + width: 12px; + vertical-align: bottom; + border-radius: 10px; + margin: 1px 0; +} +.openerp .oe_form_field_radio.oe_form_required.oe_form_invalid .oe_radio_input { + border-color: red; +} +.openerp .oe_form_field_radio.oe_horizontal label, +.openerp .oe_form_field_radio.oe_horizontal div { display: inline-block; text-align: center; + height: 16px; } -.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_radio.oe_vertical label { + margin-left: 4px; } .openerp .oe_form_field_progressbar.ui-progressbar { height: 22px; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index b79580d8225..072fda44357 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -483,21 +483,25 @@ $sheet-padding: 16px .oe_form_field_radio &.oe_horizontal white-space: nowrap - .oe_radio_header + label display: inline-block text-align: center + height: 16px &.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 + label + margin-left: 4px + &.oe_form_required + .oe_radio_input + border: 2px solid transparent + display: inline-block + height: 12px + width: 12px + vertical-align: bottom + border-radius: 10px + margin: 1px 0 + &.oe_form_invalid + .oe_radio_input + border-color: red .oe_tags &.oe_inline min-width: 250px diff --git a/addons/web/static/src/img/icons/input_radio-off.png b/addons/web/static/src/img/icons/input_radio-off.png deleted file mode 100644 index 790f7ed13b2..00000000000 Binary files a/addons/web/static/src/img/icons/input_radio-off.png and /dev/null differ diff --git a/addons/web/static/src/img/icons/input_radio-on.png b/addons/web/static/src/img/icons/input_radio-on.png deleted file mode 100644 index d55c291e795..00000000000 Binary files a/addons/web/static/src/img/icons/input_radio-on.png and /dev/null differ diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 9d79a32d60d..53a7425c036 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2806,35 +2806,94 @@ 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 * - "no_radiolabel" don't display text values - * - "display_readonly" to display radio button (not clickable) in read only mode */ - var self = this; this._super(field_manager, node); - this.horizontal = +this.options.horizontal; - this.no_radiolabel = +this.options.no_radiolabel; - this.display_readonly = +this.options.display_readonly; + this.selection = _.clone(this.field.selection) || []; + this.domain = false; }, initialize_content: function () { + 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(); + }, + click_change_value: function (event) { + var val = $(event.target).val(); + val = this.field.type == "selection" ? val : +val; + if (val == this.get_value()) { + this.set_value(false); + } else { + this.set_value(val); + } + }, + /** Get the selection and render it + * selection: [[identifier, value_to_display], ...] + * For selection fields: this is directly given by this.field.selection + * For many2one fields: perform a search on the relation of the many2one field + */ + get_selection: function() { var self = this; - this.$el.on('click', '.oe_radio_input,.oe_radio_header', function (event) { - var id = $(event.target).data("id"); - id = isNaN(+id) ? id : +id; - if (id && !self.get("effective_readonly")) { - if (!self.field.required && id == self.get_value()) { - self.set_value(false); - } else { - self.set_value(id); - } + var selection = []; + var def = $.Deferred(); + if (self.field.type == "many2one") { + var domain = instance.web.pyeval.eval('domain', this.build_domain()) || []; + if (! _.isEqual(self.domain, domain)) { + self.domain = domain; + var ds = new instance.web.DataSet(self, self.field.relation); + ds.call('search', [self.domain]) + .then(function (records) { + ds.name_get(records).then(function (records) { + selection = records; + def.resolve(); + }); + }); + } else { + selection = self.selection; + def.resolve(); + } + } + else if (self.field.type == "selection") { + selection = self.field.selection || []; + def.resolve(); + } + return def.then(function () { + if (! _.isEqual(selection, self.selection)) { + self.selection = _.clone(selection); + self.renderElement(); + self.render_value(); } }); }, + set_value: function (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_); + }, + get_value: function () { + var value = this.get('value'); + return value instanceof Array ? value[0] : value; + }, render_value: function () { - this.$(".oe_radio_input_on").removeClass("oe_radio_input_on"); - this.$(".oe_radio_input[data-id='" + this.get_value() + "'], .oe_radio_header[data-id='" + this.get_value() + "'] .oe_radio_input").addClass("oe_radio_input_on"); + var self = this; + this.$el.toggleClass("oe_readonly", this.get('effective_readonly')); + this.$("input:checked").prop("checked", false); + if (this.get_value()) { + 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 405ee81e0cd..943326f5011 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1112,26 +1112,31 @@ - - - - - -
+ + + + + + + + +
+
+ +
+ +
-
- -
 
+ + +
+ +
+
-
- - -
-
 
-
-
-
+
+