diff options
| author | Christophe Matthieu <chm@openerp.com> | 2013-03-02 23:09:08 +0100 |
|---|---|---|
| committer | Christophe Matthieu <chm@openerp.com> | 2013-03-02 23:09:08 +0100 |
| commit | ee7d866def4ec63328e5ffce7659722a841648e9 (patch) | |
| tree | e532dd3e5d394cacc9b17b1346a2311fcc298ca9 /addons/web/static/src | |
| parent | 6e56422483d031706d50069d83713577aa283389 (diff) | |
[IMP] view_form: radio button, attrs horizontal & noradiolabel
bzr revid: chm@openerp.com-20130302220908-f2weyrdh8qf37r3q
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 32 |
1 files 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 = $('<table width="100%"/>'); this.$el.append(this.$table); - if (this.node.horizontal) { - var $tr = $('<tr/>'); - _.each(this.field.selection, function (value) { - self.$tr.append("<th>" + value[1] + "</th>"); - }); - this.$table.append($tr); + if (this.horizontal) { + var width = Math.floor(100 / self.field.selection.length); + if (!this.noradiolabel) { + var $tr = $('<tr/>'); + _.each(this.field.selection, function (value) { + $tr.append('<th width="' + width + '%">' + value[1] + "</th>"); + }); + this.$table.append($tr); + } else { + var $column = $('<columns/>'); + _.each(this.field.selection, function (value) { + $column.append('<col width="' + width + '%"/>'); + }); + 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 = $('<tr/>'); _.each(this.field.selection, function (value) { - self.$tr.append('<td>' + self.render_value_input(value) + '</td>'); + $tr.append('<td>' + self.render_value_input(value) + '</td>'); }); this.$table.append($tr); } else { this.$table.find("tr").remove(); _.each(this.field.selection, function (value) { - self.$table.append('<tr><td>' + self.render_value_input(value) + '</td><th class="oe_radio_label" data="' + value[0] + '">' + value[1] + '</th></tr>'); + self.$table.append('<tr><td>' + self.render_value_input(value) + '</td>' + (!self.noradiolabel ? '<th class="oe_radio_label" data="' + value[0] + '">' + value[1] + '</th>' : '') +'</tr>'); }); } } |
