From e3d1e4fb44a1958b8d135dd892b950a306c9e77a Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 29 Mar 2013 12:38:27 +0100 Subject: [PATCH 01/10] [IMP] view_form: radio button for many2one bzr revid: chm@openerp.com-20130329113827-me6d3ho6jrp525f0 --- addons/web/static/src/js/view_form.js | 63 ++++++++++++++++++++++----- addons/web/static/src/xml/base.xml | 10 ++--- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 3b851568fe6..d95e5a9306d 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2814,21 +2814,60 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w */ 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.horizontal = +this.options.horizontal || false; + this.no_radiolabel = +this.options.no_radiolabel || false; + this.display_readonly = +this.options.display_readonly || false; + this.selection = this.field.selection || []; + this.domain = false; }, initialize_content: 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); - } + this.$el.on('click', '.oe_radio_input,.oe_radio_header', function (e) {self.on_click_change_value(e)}); + this.field_manager.on("view_content_has_changed", this, 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); + } + } + }, + /** 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; + 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; + new instance.web.DataSetSearch(self, self.field.relation, self.build_context(), self.domain) + .read_slice(['name'], {}) + .then(function (records) { + for(var i = 0; i < records.length; i++) { + selection.push([records[i].id, records[i].name]); + } + def.resolve(); + }); + } + } + else if (self.field.type == "selection") { + selection = self.field.selection || []; + def.resolve(); + } + def.then(function () { + if (! _.isEqual(selection, self.get('selection'))) { + self.selection = selection; + self.$el.html($(QWeb.render("FieldRadio", {'widget': self})).html()); + self.set("selection", _.clone(this.selection)); } }); }, diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 41067240b52..e74ff0bb796 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1114,20 +1114,20 @@ - + - +

- +
&nbsp;
- -
+ +
&nbsp;
From 90f6175053410237cc3921ce67c0f8b83d90dae3 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 29 Mar 2013 12:44:49 +0100 Subject: [PATCH 02/10] [IMP] view_form: radio button for many2one: check context bzr revid: chm@openerp.com-20130329114449-93yghqpenjb1sd22 --- addons/web/static/src/js/view_form.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index d95e5a9306d..08dc2f0dcaf 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2819,6 +2819,7 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.display_readonly = +this.options.display_readonly || false; this.selection = this.field.selection || []; this.domain = false; + this.context = false; }, initialize_content: function () { var self = this; @@ -2847,9 +2848,11 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w var def = $.Deferred(); if (self.field.type == "many2one") { var domain = instance.web.pyeval.eval('domain', this.build_domain()) || []; - if (! _.isEqual(self.domain, domain)) { + var context = instance.web.pyeval.eval('context', this.build_context()) || []; + if (! _.isEqual(self.domain, domain) || ! _.isEqual(self.context, context)) { self.domain = domain; - new instance.web.DataSetSearch(self, self.field.relation, self.build_context(), self.domain) + self.context = context; + new instance.web.DataSetSearch(self, self.field.relation, self.context, self.domain) .read_slice(['name'], {}) .then(function (records) { for(var i = 0; i < records.length; i++) { From dbd331ee6dc9396e3d8991ef6a5de6370eea0390 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 29 Mar 2013 15:10:38 +0100 Subject: [PATCH 03/10] [IMP] view_form: radio button for many2one read name_get bzr revid: chm@openerp.com-20130329141038-uobzji7e8fxkq4rr --- addons/web/static/src/js/view_form.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 08dc2f0dcaf..fe396d4be1e 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2812,7 +2812,6 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w * - "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 || false; this.no_radiolabel = +this.options.no_radiolabel || false; @@ -2852,13 +2851,13 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w if (! _.isEqual(self.domain, domain) || ! _.isEqual(self.context, context)) { self.domain = domain; self.context = context; - new instance.web.DataSetSearch(self, self.field.relation, self.context, self.domain) - .read_slice(['name'], {}) + var ds = new instance.web.DataSet(self, self.field.relation, self.context); + ds.call('search', [self.domain]) .then(function (records) { - for(var i = 0; i < records.length; i++) { - selection.push([records[i].id, records[i].name]); - } - def.resolve(); + ds.name_get(records).then(function (records) { + selection = records; + def.resolve(); + }); }); } } From c756cb72b67d0af3c5e36c53596c31b9829506d2 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 8 Apr 2013 19:17:02 +0200 Subject: [PATCH 04/10] [FIX] view_form: radio button bzr revid: chm@openerp.com-20130408171702-n7u1ingd33ke8bn4 --- addons/web/static/src/js/view_form.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index fe396d4be1e..73d5b7b501e 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2816,14 +2816,14 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.horizontal = +this.options.horizontal || false; this.no_radiolabel = +this.options.no_radiolabel || false; this.display_readonly = +this.options.display_readonly || false; - this.selection = this.field.selection || []; + this.selection = _.clone(this.field.selection) || []; this.domain = false; - this.context = false; }, initialize_content: function () { var self = this; this.$el.on('click', '.oe_radio_input,.oe_radio_header', function (e) {self.on_click_change_value(e)}); 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"); @@ -2847,11 +2847,9 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w var def = $.Deferred(); if (self.field.type == "many2one") { var domain = instance.web.pyeval.eval('domain', this.build_domain()) || []; - var context = instance.web.pyeval.eval('context', this.build_context()) || []; - if (! _.isEqual(self.domain, domain) || ! _.isEqual(self.context, context)) { + if (! _.isEqual(self.domain, domain)) { self.domain = domain; - self.context = context; - var ds = new instance.web.DataSet(self, self.field.relation, self.context); + 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) { @@ -2865,17 +2863,22 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w selection = self.field.selection || []; def.resolve(); } - def.then(function () { - if (! _.isEqual(selection, self.get('selection'))) { - self.selection = selection; + return def.then(function () { + if (! _.isEqual(selection, self.selection)) { + self.selection = _.clone(selection); self.$el.html($(QWeb.render("FieldRadio", {'widget': self})).html()); - self.set("selection", _.clone(this.selection)); + self.render_value(); } }); }, + get_value: function () { + var id = this.get('value'); + return _.isNumber(id) ? id : id[0]; + }, 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; + self.$(".oe_radio_input_on").removeClass("oe_radio_input_on"); + self.$(".oe_radio_input[data-id='" + self.get_value() + "'], [data-id='" + self.get_value() + "'] .oe_radio_input").addClass("oe_radio_input_on"); } }); From 60be4d49c5f5d74c140cf16fb6040528b6f222e8 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 10 Apr 2013 15:56:43 +0200 Subject: [PATCH 05/10] [IMP] view_form: field radio, display only the selected text in read only mode bzr revid: chm@openerp.com-20130410135643-szjzolgpbr73kpxh --- addons/web/static/src/js/view_form.js | 25 +++++++++++++------ addons/web/static/src/xml/base.xml | 35 +++++++++++++++------------ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 73d5b7b501e..600f5657503 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2820,8 +2820,8 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.domain = false; }, initialize_content: function () { - var self = this; - this.$el.on('click', '.oe_radio_input,.oe_radio_header', function (e) {self.on_click_change_value(e)}); + this.$el.on('click', '.oe_radio_input,.oe_radio_header', this, this.on_click_change_value); + this.on("change:effective_readonly", this, this.render_value); this.field_manager.on("view_content_has_changed", this, this.get_selection); this.get_selection(); }, @@ -2871,14 +2871,25 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w } }); }, + 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_]; + } + this._super(value_); + }, get_value: function () { - var id = this.get('value'); - return _.isNumber(id) ? id : id[0]; + var value = this.get('value'); + return value instanceof Array ? value[0] : value; }, render_value: function () { - var self = this; - self.$(".oe_radio_input_on").removeClass("oe_radio_input_on"); - self.$(".oe_radio_input[data-id='" + self.get_value() + "'], [data-id='" + self.get_value() + "'] .oe_radio_input").addClass("oe_radio_input_on"); + 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] : ""); } }); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index e74ff0bb796..e89865e42e1 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1113,25 +1113,28 @@ - - - - -
+ + + + + +
+
+
+
+ +
&nbsp;
-
- -
&nbsp;
+ + +
+
&nbsp;
+
+
-
- - -
-
&nbsp;
-
-
-
+
+
From f2beb97168c474b11b80eff24cab7ff4a450a2ab Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 10 Apr 2013 18:09:17 +0200 Subject: [PATCH 06/10] [IMP] view_form: radio button, replace image by input type radio bzr revid: chm@openerp.com-20130410160917-4meevyiff65adspx --- addons/web/static/src/css/base.css | 17 +--------- addons/web/static/src/css/base.sass | 14 +-------- .../static/src/img/icons/input_radio-off.png | Bin 512 -> 0 bytes .../static/src/img/icons/input_radio-on.png | Bin 559 -> 0 bytes addons/web/static/src/js/view_form.js | 29 ++++++++++-------- addons/web/static/src/xml/base.xml | 10 +++--- 6 files changed, 23 insertions(+), 47 deletions(-) delete mode 100644 addons/web/static/src/img/icons/input_radio-off.png delete mode 100644 addons/web/static/src/img/icons/input_radio-on.png diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 559b0e40e35..e2115440717 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -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; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index d687ce21869..c92e7fd3c55 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -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 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 790f7ed13b250830ca15af29fcb18e9713349bc9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 512 zcmV+b0{{JqP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0hLKaK~yMHm6F*` z!cY)~Eu_%p6ap=KOaQ|w@+#mZKA>C*FX4?BhCRq?LIQ;Zf+?F)>R(D|OpL*~Xs7+Z z^Pf30htf3d>f*3mOzI$Y_EuH3R-9z> z5ueWoS(fGgU@)Cd^SK-$#8{xyaD6NmBjIp5ecSF17RwI^qRSb(2{#*!!EpFcC>T5F zb)x|I#S_Wrm)FhiQxru>l2r9jskM@+6eIwKw@$yc+c(i@xBt%b#349rG)*|x=aoF7 z8}&c}VA2y=M#YQe(&-QwJ1y{xlduBMdL;LLuR;P~(ne;dX^yo6auAN^Ir}k?;8YgN zsnPlit7o&BB)Sg!FP5<(=woQwK_Fy4pW_&&cOo9|_50VM;C8#&?sgPKLEEDURpmGi z5&)CVX0wyYq}6KTKtL5`wOX&y6NX_bl?o&PX1|ePI!~pN-|t7)F-80Vgz4aUpU?l8 zjPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0mMl}K~yMHWBmXB zKLgQ#iD;D|g^X~s|Ni}Z`O1~sw{Jgx{v0SFDJiL{s;aA_!_3SKHxa7(%a<=3Hf|IX z6H`)D6c-lgwt}eERI_?MKWk z%*NVk;v#| -
+

-
&nbsp;
+
-
-
&nbsp;
+
+ &nbsp;
-
+ From 67452d290eac4e26a0d940510960e2cdc36c657b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 11 Apr 2013 11:06:54 +0200 Subject: [PATCH 07/10] [IMP] view_form: radio button: change style for required field bzr revid: chm@openerp.com-20130411090654-ujf7fio6lnsppv90 --- addons/web/static/src/css/base.css | 19 ++++++++++++++++++- addons/web/static/src/css/base.sass | 16 ++++++++++++++++ addons/web/static/src/js/view_form.js | 5 ++--- addons/web/static/src/xml/base.xml | 10 ++++++---- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index e2115440717..7e3b3e1a43c 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2312,9 +2312,26 @@ .openerp .oe_form_field_radio.oe_horizontal { white-space: nowrap; } -.openerp .oe_form_field_radio.oe_horizontal label { +.openerp .oe_form_field_radio.oe_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_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 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 c92e7fd3c55..4e3dc656882 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -486,6 +486,22 @@ $sheet-padding: 16px label display: inline-block text-align: center + height: 16px + &.oe_vertical + label + margin-left: 4px + &.oe_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/js/view_form.js b/addons/web/static/src/js/view_form.js index e1c5208358c..42c021f9717 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2813,14 +2813,13 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w /* 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 */ this._super(field_manager, node); this.horizontal = +this.options.horizontal || false; this.no_radiolabel = +this.options.no_radiolabel || false; - this.display_readonly = +this.options.display_readonly || false; this.selection = _.clone(this.field.selection) || []; this.domain = false; + console.log(this); }, initialize_content: function () { this.uniqueId = _.uniqueId("radio"); @@ -2888,7 +2887,7 @@ 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.$("input[checked]").prop("checked", false); + this.$("input[checked]").attr("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] : ""); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index df289bbb2ea..d57dc2107f5 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1112,7 +1112,7 @@ - + @@ -1123,13 +1123,15 @@
- +
+ +
-
- &nbsp; +
+
From 93193565371a8ac9642a917390f33ee1ad9068c1 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 11 Apr 2013 11:33:19 +0200 Subject: [PATCH 08/10] [IMP] view_form: radio css readonly bzr revid: chm@openerp.com-20130411093319-q25a0fbybsjzwvfe --- addons/web/static/src/css/base.css | 8 ++++++-- addons/web/static/src/css/base.sass | 8 +++++++- addons/web/static/src/js/view_form.js | 3 +-- addons/web/static/src/xml/base.xml | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 1d7d2fa8c7a..d84b19a867e 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2315,7 +2315,11 @@ .openerp .oe_form_field_radio.oe_horizontal { white-space: nowrap; } -.openerp .oe_form_field_radio.oe_required .oe_radio_input { +.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; height: 12px; @@ -2324,7 +2328,7 @@ border-radius: 10px; margin: 1px 0; } -.openerp .oe_form_field_radio.oe_required.oe_form_invalid .oe_radio_input { +.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, diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 004204f73c5..df157249d83 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -490,7 +490,13 @@ $sheet-padding: 16px &.oe_vertical label margin-left: 4px - &.oe_required + &: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 display: inline-block diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 971e2b96d6e..4f036722ba7 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2885,8 +2885,7 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w return value instanceof Array ? value[0] : value; }, 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.$el.toggleClass("oe_readonly", this.get('effective_readonly')); this.$("input[checked]").attr("checked", false); if (this.get_value()) { this.$("input[value='" + this.get_value() + "']").attr("checked", true); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 4a5a7527e28..d501e76f875 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1112,7 +1112,7 @@ - + From 5623719b1c98fe22b9c71bb77113bff0f6d3d082 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 11 Apr 2013 11:34:33 +0200 Subject: [PATCH 09/10] [IMP] view_form: radio remove console log bzr revid: chm@openerp.com-20130411093433-jmsrcxjw0xb6vp1m --- addons/web/static/src/js/view_form.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 4f036722ba7..2ffd80d5962 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2819,7 +2819,6 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.no_radiolabel = +this.options.no_radiolabel || false; this.selection = _.clone(this.field.selection) || []; this.domain = false; - console.log(this); }, initialize_content: function () { this.uniqueId = _.uniqueId("radio"); From ed46400a55401257aca6cbb6bd1a97f3b4d632a6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 15 Apr 2013 12:30:41 +0200 Subject: [PATCH 10/10] [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 @@
- +
- +
- +