From 6e56422483d031706d50069d83713577aa283389 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Sat, 2 Mar 2013 22:38:49 +0100 Subject: [PATCH 01/12] [IMP] view_form: radio button bzr revid: chm@openerp.com-20130302213849-wk5snztonvy8v0vr --- addons/web/static/src/js/view_form.js | 66 +++++++++++++++++++++++++++ addons/web/static/src/xml/base.xml | 3 ++ 2 files changed, 69 insertions(+) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index ccfc17a0288..41e24edb31a 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2776,6 +2776,71 @@ 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', + init: function(field_manager, node) { + var self = this; + this._super(field_manager, node); + this.node = node; + }, + initialize_content: function() { + var self = this; + this.$table = $(''); + this.$el.append(this.$table); + if (this.node.horizontal) { + var $tr = $(''); + _.each(this.field.selection, function (value) { + self.$tr.append(""); + }); + this.$table.append($tr); + } + this.$el.on('click', '.oe_radio_button,.oe_radio_label', function (event) { + if (!self.get("effective_readonly")) { + var value = $(event.target).attr('data'); + if (!self.field.required && value == self.get_value()) { + value = false; + } + self.set_value(value); + } + }); + }, + render_value_input: function (value) { + var check = value[0] == this.get_value(); + return '' + check + ''; + }, + render_value: function () { + var self = this; + if (this.node.horizontal) { + this.$table.find("tr:eq(2,)").remove(); + var $tr = $(''); + _.each(this.field.selection, function (value) { + self.$tr.append(''); + }); + this.$table.append($tr); + } else { + this.$table.find("tr").remove(); + _.each(this.field.selection, function (value) { + self.$table.append(''); + }); + } + } +}); // jquery autocomplete tweak to allow html and classnames (function() { @@ -5362,6 +5427,7 @@ instance.web.form.widgets = new instance.web.Registry({ 'date' : 'instance.web.form.FieldDate', 'datetime' : 'instance.web.form.FieldDatetime', 'selection' : 'instance.web.form.FieldSelection', + 'radio' : 'instance.web.form.FieldRadio', 'many2one' : 'instance.web.form.FieldMany2One', 'many2onebutton' : 'instance.web.form.Many2OneButton', 'many2many' : 'instance.web.form.FieldMany2Many', diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 8fbd02525a1..68973632dab 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1087,6 +1087,9 @@ + + + From ee7d866def4ec63328e5ffce7659722a841648e9 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Sat, 2 Mar 2013 23:09:08 +0100 Subject: [PATCH 02/12] [IMP] view_form: radio button, attrs horizontal & noradiolabel bzr revid: chm@openerp.com-20130302220908-f2weyrdh8qf37r3q --- addons/web/static/src/js/view_form.js | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 41e24edb31a..d4cb08ef331 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2797,18 +2797,28 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w init: function(field_manager, node) { var self = this; this._super(field_manager, node); - this.node = node; + this.horizontal = !!node.attrs.horizontal; + this.noradiolabel = !!node.attrs.noradiolabel; }, initialize_content: function() { var self = this; this.$table = $('
" + value[1] + "
' + self.render_value_input(value) + '
' + self.render_value_input(value) + '' + value[1] + '
'); this.$el.append(this.$table); - if (this.node.horizontal) { - var $tr = $(''); - _.each(this.field.selection, function (value) { - self.$tr.append(""); - }); - this.$table.append($tr); + if (this.horizontal) { + var width = Math.floor(100 / self.field.selection.length); + if (!this.noradiolabel) { + var $tr = $(''); + _.each(this.field.selection, function (value) { + $tr.append('"); + }); + this.$table.append($tr); + } else { + var $column = $(''); + _.each(this.field.selection, function (value) { + $column.append(''); + }); + this.$table.append($column); + } } this.$el.on('click', '.oe_radio_button,.oe_radio_label', function (event) { if (!self.get("effective_readonly")) { @@ -2826,17 +2836,17 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w }, render_value: function () { var self = this; - if (this.node.horizontal) { - this.$table.find("tr:eq(2,)").remove(); + if (this.horizontal) { + this.$table.find(!this.noradiolabel ? "tr:not(:first)": "tr").remove(); var $tr = $(''); _.each(this.field.selection, function (value) { - self.$tr.append(''); + $tr.append(''); }); this.$table.append($tr); } else { this.$table.find("tr").remove(); _.each(this.field.selection, function (value) { - self.$table.append(''); + self.$table.append('' + (!self.noradiolabel ? '' : '') +''); }); } } From de11e467514971fa5cedfeb029626c24de6500a6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Sat, 2 Mar 2013 23:40:18 +0100 Subject: [PATCH 03/12] [IMP] view_form: radio button css bzr revid: chm@openerp.com-20130302224018-olnclhjzug3edrmx --- addons/web/static/src/css/base.css | 12 ++++++++++++ addons/web/static/src/css/base.sass | 11 ++++++++++- addons/web/static/src/js/view_form.js | 23 ++++------------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 018f9f7bbe4..00246de578c 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2283,6 +2283,18 @@ display: inline-block; min-width: 70px; } +.openerp .oe_form_field_radio .oe_radio_input { + cursor: pointer; + display: inline-block; + width: 20px; + background: transparent url(/web/static/src/img/icons/star-off.png) no-repeat 0px 0px; +} +.openerp .oe_form_field_radio .oe_radio_input_on { + background: transparent url(/web/static/src/img/icons/star-on.png) no-repeat 0px 0px; +} +.openerp .oe_form_field_radio .oe_radio_label { + cursor: help; +} .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 0a73728678d..b922b76cdcd 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -476,7 +476,16 @@ $sheet-padding: 16px .oe_tag_dark background: $tag-bg-dark color: #eee - + .oe_form_field_radio + .oe_radio_input + cursor: pointer + display: inline-block + width: 20px + background: transparent url(/web/static/src/img/icons/gtk-no.png) no-repeat 0px 0px + .oe_radio_input_on + background: transparent url(/web/static/src/img/icons/gtk-yes.png) no-repeat 0px 0px + .oe_radio_label + cursor: help .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 d4cb08ef331..4605d362dc7 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2776,21 +2776,7 @@ 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', @@ -2807,7 +2793,7 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w if (this.horizontal) { var width = Math.floor(100 / self.field.selection.length); if (!this.noradiolabel) { - var $tr = $(''); + var $tr = $(''); _.each(this.field.selection, function (value) { $tr.append('"); }); @@ -2820,7 +2806,7 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.$table.append($column); } } - this.$el.on('click', '.oe_radio_button,.oe_radio_label', function (event) { + this.$el.on('click', '.oe_radio_input,.oe_radio_label', function (event) { if (!self.get("effective_readonly")) { var value = $(event.target).attr('data'); if (!self.field.required && value == self.get_value()) { @@ -2832,19 +2818,18 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w }, render_value_input: function (value) { var check = value[0] == this.get_value(); - return '' + check + ''; + return ' '; }, render_value: function () { var self = this; + this.$table.find("tr:not(.oe_radio_header)").remove(); if (this.horizontal) { - this.$table.find(!this.noradiolabel ? "tr:not(:first)": "tr").remove(); var $tr = $(''); _.each(this.field.selection, function (value) { $tr.append(''); }); this.$table.append($tr); } else { - this.$table.find("tr").remove(); _.each(this.field.selection, function (value) { self.$table.append('' + (!self.noradiolabel ? '' : '') +''); }); From 02c3b2997b780846d44067f9b98838a4d996d125 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Sun, 3 Mar 2013 12:18:21 +0100 Subject: [PATCH 04/12] [IMP] view form: radio button refact and layout bzr revid: chm@openerp.com-20130303111821-l9du75yj6dwjy2qo --- addons/web/static/src/css/base.css | 6 +- addons/web/static/src/css/base.sass | 6 +- .../static/src/img/icons/input_radio-off.png | Bin 0 -> 512 bytes .../static/src/img/icons/input_radio-on.png | Bin 0 -> 559 bytes addons/web/static/src/js/view_form.js | 75 +++++++++++------- 5 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 addons/web/static/src/img/icons/input_radio-off.png create 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 00246de578c..24fcaa69aaf 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2287,13 +2287,13 @@ cursor: pointer; display: inline-block; width: 20px; - background: transparent url(/web/static/src/img/icons/star-off.png) no-repeat 0px 0px; + background: transparent url(/web/static/src/img/icons/input_radio-off.png) no-repeat 0px 0px; } .openerp .oe_form_field_radio .oe_radio_input_on { - background: transparent url(/web/static/src/img/icons/star-on.png) no-repeat 0px 0px; + background: transparent url(/web/static/src/img/icons/input_radio-on.png) no-repeat 0px 0px; } .openerp .oe_form_field_radio .oe_radio_label { - cursor: help; + cursor: default; } .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 b922b76cdcd..627e51a00e4 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -481,11 +481,11 @@ $sheet-padding: 16px cursor: pointer display: inline-block width: 20px - background: transparent url(/web/static/src/img/icons/gtk-no.png) no-repeat 0px 0px + background: transparent url(/web/static/src/img/icons/input_radio-off.png) no-repeat 0px 0px .oe_radio_input_on - background: transparent url(/web/static/src/img/icons/gtk-yes.png) no-repeat 0px 0px + background: transparent url(/web/static/src/img/icons/input_radio-on.png) no-repeat 0px 0px .oe_radio_label - cursor: help + 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 new file mode 100644 index 0000000000000000000000000000000000000000..790f7ed13b250830ca15af29fcb18e9713349bc9 GIT binary patch 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#|'); this.$el.append(this.$table); - if (this.horizontal) { - var width = Math.floor(100 / self.field.selection.length); - if (!this.noradiolabel) { - var $tr = $(''); - _.each(this.field.selection, function (value) { - $tr.append('"); - }); - this.$table.append($tr); - } else { - var $column = $(''); - _.each(this.field.selection, function (value) { - $column.append(''); - }); - this.$table.append($column); - } - } - this.$el.on('click', '.oe_radio_input,.oe_radio_label', function (event) { + }, + _action_click: function ($tag, value) { + var self = this; + $tag.on('click', $tag, function (event) { if (!self.get("effective_readonly")) { - var value = $(event.target).attr('data'); - if (!self.field.required && value == self.get_value()) { - value = false; + if (!self.field.required && value[0] == self.get_value()) { + self.set_value(undefined); + } else { + self.set_value(value[0]); } - self.set_value(value); } }); }, - render_value_input: function (value) { + _render_input: function (value) { var check = value[0] == this.get_value(); - return ' '; + var $input = $(' '); + this._action_click($input, value); + return $input; + }, + _render_label: function (value, width) { + $label = $(''); + this._action_click($label, value); + return $label; }, render_value: function () { var self = this; - this.$table.find("tr:not(.oe_radio_header)").remove(); + this.$table.empty(); + if (this.horizontal) { + var width = Math.floor(100 / this.field.selection.length); + if (!this.noradiolabel) { + var $tr = $(''); + _.each(this.field.selection, function (value) { + $tr.append(self._render_label(value, width)); + }); + this.$table.append($tr); + } + var $tr = $(''); _.each(this.field.selection, function (value) { - $tr.append(''); + var $td = $('") + } + else { _.each(this.field.selection, function (value) { - self.$table.append('' + (!self.noradiolabel ? '' : '') +''); + var $tr = $(''); + var $td = $('
" + value[1] + "
' + value[1] + "
' + self.render_value_input(value) + '' + self.render_value_input(value) + '
' + self.render_value_input(value) + '' + value[1] + '
' + self.render_value_input(value) + '' + value[1] + '
' + value[1] + "
' + self.render_value_input(value) + '
' + self.render_value_input(value) + '' + value[1] + '
' + value[1] + "
' + value[1] + '
' + self.render_value_input(value) + ''); + $td.append(self._render_input(value)); + $tr.append($td); }); this.$table.append($tr); - } else { + } + else if (self.get("effective_readonly")) { + var value = _.find(this.field.selection, function (val) { return val[0] == self.get_value() }); + this.$table.append("
" + (value ? value[1] : "") + "
' + self.render_value_input(value) + '' + value[1] + '
'); + $td.append(self._render_input(value)); + $tr.append($td); + if (!self.noradiolabel) { + var $td = $(''); + $td.append(self._render_label(value)); + $tr.append($td); + } + self.$table.append($tr); }); } } From e31af80fd695f6c4d10418d3ff63f5824b5b4639 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Sun, 3 Mar 2013 12:22:26 +0100 Subject: [PATCH 05/12] [IMP] view form: radio, add display_readonly attributes bzr revid: chm@openerp.com-20130303112226-sy0curjd252pmg2k --- addons/web/static/src/js/view_form.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index e63ee886b9a..0bd98cf60dc 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2784,7 +2784,8 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w var self = this; this._super(field_manager, node); this.horizontal = !!node.attrs.horizontal; - this.noradiolabel = !!node.attrs.noradiolabel; + this.no_radiolabel = !!node.attrs.no_radiolabel; + this.display_readonly = !!node.attrs.display_readonly; }, initialize_content: function() { this.$table = $(''); @@ -2817,9 +2818,13 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w var self = this; this.$table.empty(); - if (this.horizontal) { + if (self.get("effective_readonly") && !self.display_readonly) { + var value = _.find(this.field.selection, function (val) { return val[0] == self.get_value() }); + this.$table.append("") + } + else if (this.horizontal) { var width = Math.floor(100 / this.field.selection.length); - if (!this.noradiolabel) { + if (!this.no_radiolabel) { var $tr = $(''); _.each(this.field.selection, function (value) { $tr.append(self._render_label(value, width)); @@ -2835,17 +2840,13 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w }); this.$table.append($tr); } - else if (self.get("effective_readonly")) { - var value = _.find(this.field.selection, function (val) { return val[0] == self.get_value() }); - this.$table.append("") - } else { _.each(this.field.selection, function (value) { var $tr = $(''); var $td = $('
" + (value ? value[1] : "") + "
" + (value ? value[1] : "") + "
'); $td.append(self._render_input(value)); $tr.append($td); - if (!self.noradiolabel) { + if (!self.no_radiolabel) { var $td = $(''); $td.append(self._render_label(value)); $tr.append($td); From c4f70b450e74a0f30f12bb9db7735e20a0c0f901 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Sun, 3 Mar 2013 12:42:16 +0100 Subject: [PATCH 06/12] [IMP] view form: radio, fix and text align bzr revid: chm@openerp.com-20130303114216-opzxi8f3nsltbnbm --- addons/web/static/src/css/base.css | 3 +++ addons/web/static/src/css/base.sass | 2 ++ addons/web/static/src/js/view_form.js | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 24fcaa69aaf..3d1769bf345 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2283,6 +2283,9 @@ display: inline-block; min-width: 70px; } +.openerp .oe_form_field_radio td, .openerp .oe_form_field_radio th { + text-align: center; +} .openerp .oe_form_field_radio .oe_radio_input { cursor: pointer; display: inline-block; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 627e51a00e4..a809e77f62a 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -477,6 +477,8 @@ $sheet-padding: 16px background: $tag-bg-dark color: #eee .oe_form_field_radio + td,th + text-align: center .oe_radio_input cursor: pointer display: inline-block diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0bd98cf60dc..f6219b5d624 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2783,9 +2783,9 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w init: function(field_manager, node) { var self = this; this._super(field_manager, node); - this.horizontal = !!node.attrs.horizontal; - this.no_radiolabel = !!node.attrs.no_radiolabel; - this.display_readonly = !!node.attrs.display_readonly; + this.horizontal = +node.attrs.horizontal; + this.no_radiolabel = +node.attrs.no_radiolabel; + this.display_readonly = +node.attrs.display_readonly; }, initialize_content: function() { this.$table = $(''); From e4b805fd7bfa37e8f188f7a20b623b3af5b48543 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 4 Mar 2013 09:22:54 +0100 Subject: [PATCH 07/12] [IMP] wev_form: radio style width bzr revid: chm@openerp.com-20130304082254-wyv571d2c7y9y9gj --- addons/web/static/src/js/view_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index f6219b5d624..b587871bb0a 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2810,7 +2810,7 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w return $input; }, _render_label: function (value, width) { - $label = $(''); + $label = $(''); this._action_click($label, value); return $label; }, From 39206d8013fe990544f23adba1c3b7ffcf429697 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 4 Mar 2013 09:58:19 +0100 Subject: [PATCH 08/12] [IMP] web_form: radio layout bzr revid: chm@openerp.com-20130304085819-6q0vx9hc89mm0s0i --- addons/web/static/src/js/view_form.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index b587871bb0a..e7e8f623b29 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2787,10 +2787,6 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.no_radiolabel = +node.attrs.no_radiolabel; this.display_readonly = +node.attrs.display_readonly; }, - initialize_content: function() { - this.$table = $('
' + value[1] + '' + value[1] + '
'); - this.$el.append(this.$table); - }, _action_click: function ($tag, value) { var self = this; $tag.on('click', $tag, function (event) { @@ -2816,13 +2812,14 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w }, render_value: function () { var self = this; - this.$table.empty(); - + this.$el.empty(); if (self.get("effective_readonly") && !self.display_readonly) { var value = _.find(this.field.selection, function (val) { return val[0] == self.get_value() }); - this.$table.append("") + this.$el.append(value ? value[1] : ""); } else if (this.horizontal) { + this.$table = $('
" + (value ? value[1] : "") + "
'); + this.$el.append(this.$table); var width = Math.floor(100 / this.field.selection.length); if (!this.no_radiolabel) { var $tr = $(''); @@ -2841,9 +2838,11 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.$table.append($tr); } else { + this.$table = $('
'); + this.$el.append(this.$table); _.each(this.field.selection, function (value) { var $tr = $(''); - var $td = $(''); - this._action_click($label, value); - return $label; - }, render_value: function () { - var self = this; - this.$el.empty(); - if (self.get("effective_readonly") && !self.display_readonly) { - var value = _.find(this.field.selection, function (val) { return val[0] == self.get_value() }); - this.$el.append(value ? value[1] : ""); - } - else if (this.horizontal) { - this.$table = $('
'); + var $td = $(''); $td.append(self._render_input(value)); $tr.append($td); if (!self.no_radiolabel) { From cad21aff66fa3517e6d5e1c79cff93c0792c03f6 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 4 Mar 2013 10:04:27 +0100 Subject: [PATCH 09/12] [IMP] web_form: radio help bzr revid: chm@openerp.com-20130304090427-p342lf7a2evmuqvn --- addons/web/static/src/js/view_form.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index e7e8f623b29..28d6c38fcd3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2777,10 +2777,14 @@ 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', 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 = +node.attrs.horizontal; From 7d5ea8896ea71fc4031dbe8f2e8f34888a117aed Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 21 Mar 2013 16:04:05 +0100 Subject: [PATCH 10/12] [IMP] view_form radio button with div inline-block bzr revid: chm@openerp.com-20130321150405-fz61r51opx2m9kmt --- addons/web/static/src/css/base.css | 13 +++-- addons/web/static/src/css/base.sass | 16 +++++-- addons/web/static/src/js/view_form.js | 69 ++++----------------------- addons/web/static/src/xml/base.xml | 22 ++++++++- 4 files changed, 52 insertions(+), 68 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 3d1769bf345..368218b1293 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2283,17 +2283,24 @@ display: inline-block; min-width: 70px; } -.openerp .oe_form_field_radio td, .openerp .oe_form_field_radio th { +.openerp .oe_form_field_radio.oe_horizontal { + white-space: nowrap; +} +.openerp .oe_form_field_radio.oe_horizontal .oe_radio_header { + 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 0px 0px; + 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 0px 0px; + 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; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index a809e77f62a..5ff3c91442f 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -477,15 +477,21 @@ $sheet-padding: 16px background: $tag-bg-dark color: #eee .oe_form_field_radio - td,th - text-align: center - .oe_radio_input + &.oe_horizontal + white-space: nowrap + .oe_radio_header + 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 0px 0px + 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 0px 0px + background: transparent url(/web/static/src/img/icons/input_radio-on.png) no-repeat center center .oe_radio_label cursor: default .oe_tags diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 28d6c38fcd3..ce0f0ab23e7 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2791,72 +2791,23 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w this.no_radiolabel = +node.attrs.no_radiolabel; this.display_readonly = +node.attrs.display_readonly; }, - _action_click: function ($tag, value) { + initialize_content: function () { var self = this; - $tag.on('click', $tag, function (event) { - if (!self.get("effective_readonly")) { - if (!self.field.required && value[0] == self.get_value()) { - self.set_value(undefined); + 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(value[0]); + self.set_value(id); } } }); }, - _render_input: function (value) { - var check = value[0] == this.get_value(); - var $input = $(' '); - this._action_click($input, value); - return $input; - }, - _render_label: function (value, width) { - $label = $('' + value[1] + '
'); - this.$el.append(this.$table); - var width = Math.floor(100 / this.field.selection.length); - if (!this.no_radiolabel) { - var $tr = $(''); - _.each(this.field.selection, function (value) { - $tr.append(self._render_label(value, width)); - }); - this.$table.append($tr); - } - - var $tr = $(''); - _.each(this.field.selection, function (value) { - var $td = $('
'); - $td.append(self._render_input(value)); - $tr.append($td); - }); - this.$table.append($tr); - } - else { - this.$table = $(''); - this.$el.append(this.$table); - _.each(this.field.selection, function (value) { - var $tr = $(''); - var $td = $('
'); - $td.append(self._render_input(value)); - $tr.append($td); - if (!self.no_radiolabel) { - var $td = $(''); - $td.append(self._render_label(value)); - $tr.append($td); - } - self.$table.append($tr); - }); - } + 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"); } }); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 68973632dab..02129b2fb9a 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1088,7 +1088,27 @@ - + + + + + +
+
+
+
+ +
&nbsp;
+
+
+ + +
+
&nbsp;
+
+
+
+
From f0b8314554b7f9e7543c87a504dd1dae44da2d57 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 21 Mar 2013 16:18:27 +0100 Subject: [PATCH 11/12] [IMP] view_form radio button: raw to esc bzr revid: chm@openerp.com-20130321151827-p24pduqmcgy1k35u --- addons/web/static/src/xml/base.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 02129b2fb9a..56faec7ad42 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1093,7 +1093,7 @@ -
+

@@ -1104,7 +1104,7 @@
-
&nbsp;
+
&nbsp;
From 3ecc55c583af6f3de0cd14b3542a051afbbbd681 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 21 Mar 2013 17:31:00 +0100 Subject: [PATCH 12/12] [IMP] view_form: radio options bzr revid: chm@openerp.com-20130321163100-j92sqrut1m4d0zgi --- addons/web/static/src/js/view_form.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index ce0f0ab23e7..91a752fad72 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2787,9 +2787,9 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w */ var self = this; this._super(field_manager, node); - this.horizontal = +node.attrs.horizontal; - this.no_radiolabel = +node.attrs.no_radiolabel; - this.display_readonly = +node.attrs.display_readonly; + this.horizontal = +this.options.horizontal; + this.no_radiolabel = +this.options.no_radiolabel; + this.display_readonly = +this.options.display_readonly; }, initialize_content: function () { var self = this;