diff options
| author | Christophe Matthieu <chm@openerp.com> | 2013-03-28 10:53:45 +0100 |
|---|---|---|
| committer | Christophe Matthieu <chm@openerp.com> | 2013-03-28 10:53:45 +0100 |
| commit | 2653bcf329ebe2d5eb9e94247440d6c3d17a8f2a (patch) | |
| tree | ebddad4daffa44c955aae1e95734935667675bb3 /addons/web | |
| parent | b1e422ceb0777bbfaa47e3fb2233c1d21b3ccda2 (diff) | |
| parent | 7e895d90cbf2735fd07723d25c22c874133d7e13 (diff) | |
[MERGE] radio button: display vertical and horizontal; click on radio label = select the label; click on field label = do nothing; bounce effect on edit in page mode; the goal is replacement of some selection box -> desable other options; not clickable in read only mode
bzr revid: chm@openerp.com-20130328095345-nc5rizcmste0bncp
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/src/css/base.css | 22 | ||||
| -rw-r--r-- | addons/web/static/src/css/base.sass | 19 | ||||
| -rw-r--r-- | addons/web/static/src/img/icons/input_radio-off.png | bin | 0 -> 512 bytes | |||
| -rw-r--r-- | addons/web/static/src/img/icons/input_radio-on.png | bin | 0 -> 559 bytes | |||
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 35 | ||||
| -rw-r--r-- | addons/web/static/src/xml/base.xml | 23 |
6 files changed, 98 insertions, 1 deletions
diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index be0bb19748c..559b0e40e35 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2309,6 +2309,28 @@ display: inline-block; min-width: 70px; } +.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 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 e2c047f11e1..d687ce21869 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -480,7 +480,24 @@ $sheet-padding: 16px .oe_tag_dark background: $tag-bg-dark color: #eee - + .oe_form_field_radio + &.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 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 Binary files differnew file mode 100644 index 00000000000..790f7ed13b2 --- /dev/null +++ b/addons/web/static/src/img/icons/input_radio-off.png diff --git a/addons/web/static/src/img/icons/input_radio-on.png b/addons/web/static/src/img/icons/input_radio-on.png Binary files differnew file mode 100644 index 00000000000..d55c291e795 --- /dev/null +++ b/addons/web/static/src/img/icons/input_radio-on.png diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index b057616b6ab..3b851568fe6 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2804,6 +2804,40 @@ 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 = +this.options.horizontal; + this.no_radiolabel = +this.options.no_radiolabel; + this.display_readonly = +this.options.display_readonly; + }, + 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); + } + } + }); + }, + 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"); + } +}); + // jquery autocomplete tweak to allow html and classnames (function() { var proto = $.ui.autocomplete.prototype, @@ -5423,6 +5457,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 bcd5763a37e..41067240b52 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1111,6 +1111,29 @@ </select> </span> </t> +<t t-name="FieldRadio"> + <span t-attf-class="oe_form_field oe_form_field_radio #{widget.horizontal ? 'oe_horizontal' : 'oe_vertical'}" t-att-style="widget.node.attrs.style"> + <t t-if="widget.horizontal"> + <t t-set="width" t-value="Math.floor(100 / widget.field.selection.length)"/> + <t t-if="!widget.no_radiolabel"> + <t t-foreach="widget.field.selection" t-as="selection"> + <div class="oe_radio_header" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></div> + </t> + <br/> + </t> + <t t-foreach="widget.field.selection" t-as="selection"> + <div class="oe_radio_input" t-att-style="'width: ' + width + '%;'" t-att-data-id="selection[0]">&nbsp;</div> + </t> + </t> + <t t-if="!widget.horizontal"> + <t t-foreach="widget.field.selection" t-as="selection"> + <div class="oe_radio_header" t-att-style="'width: ' + width + '%;'" t-att-data-id="selection[0]"> + <div class="oe_radio_input">&nbsp;</div><t t-if="!widget.no_radiolabel" t-esc="selection[1]"/> + </div> + </t> + </t> + </span> +</t> <t t-name="FieldMany2One"> <span class="oe_form_field oe_form_field_many2one oe_form_field_with_button" t-att-style="widget.node.attrs.style"> <t t-if="widget.get('effective_readonly')"> |
