python - OpenERP (View) - change look of selection field? (aka radio button) -


is there way change how selection field looks? need change bunch of boolean fields (technically 1 field, not multiple boolean fields. change)?

it should (it looks there multiple fields, technically should one):

enter image description here

and should function selection field - can select 1 value. possible it?

update: found - http://help.openerp.com/question/29061/how-to-add-radio-button-widget/

it seems possible widget on openerp 8 (using radio widget selection field). think might possible move such functionality in openerp 7.

i managed move radio widget openerp 8 openerp 7. post how i've done. maybe 1 need too.

basically need 2 main files, 1 js , 1 xml (also empty __init__.py needed, because openerp throw error didn't find module).

in __openerp__.py:

 'js': ['static/src/js/widget_radio.js'], 'qweb': ['static/src/xml/widget_radio.xml'], 

widget_radio.js (web_widget_radio addon name):

openerp.web_widget_radio = function (instance) {     instance.web.form.widgets.add('radio', 'instance.web_widget_radio.fieldradio');     instance.web_widget_radio.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" display in column             * - "no_radiolabel" don't display text values             */             this._super(field_manager, node);             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);             }         },         /** selection , render          *  selection: [[identifier, value_to_display], ...]          *  selection fields: directly given this.field.selection          *  many2one fields:  perform search on relation of 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;                     var ds = new instance.web.datasetstatic(self, self.field.relation, self.build_context());                     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 () {             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] : "");             }         }     }); }; 

widget_radio.xml:

<?xml version="1.0" encoding="utf-8"?> <templates id="template" xml:space="preserve">     <t t-name="fieldradio">         <span t-attf-class="oe_form_field oe_form_field_radio #{widget.options.horizontal ? 'oe_horizontal' : 'oe_vertical'}" t-att-style="widget.node.attrs.style">             <span t-if="!widget.get('effective_readonly')">                 <t t-if="widget.options.horizontal">                     <t t-set="width" t-value="math.floor(100 / widget.selection.length)"/>                     <t t-if="!widget.options.no_radiolabel">                         <t t-foreach="widget.selection" t-as="selection">                             <label t-att-for="widget.uniqueid + '_' + selection[0]" t-att-style="'width: ' + width + '%;'"><t t-esc="selection[1]"/></label>                         </t>                         <br/>                     </t>                     <t t-foreach="widget.selection" t-as="selection">                         <div t-att-style="'width: ' + width + '%;'">                             <span class="oe_radio_input"><input type="radio" t-att-name="widget.uniqueid" t-att-id="widget.uniqueid + '_' + selection[0]" t-att-value="selection[0]"/></span>                         </div>                     </t>                 </t>                 <t t-if="!widget.options.horizontal">                     <t t-foreach="widget.selection" t-as="selection">                         <div>                             <span class="oe_radio_input"><input type="radio" t-att-id="widget.uniqueid + '_' + selection[0]" t-att-name="widget.uniqueid" t-att-value="selection[0]"/></span><label t-if="!widget.options.no_radiolabel" t-att-for="widget.uniqueid + '_' + selection[0]"><t t-esc="selection[1]"/></label>                         </div>                     </t>                 </t>             </span>             <span t-if="widget.get('effective_readonly')" class="oe_radio_readonly"><t t-esc="widget.get('value')[1]"/></span>         </span>     </t> </templates>  

p.s. can find original code in openerp trunk version.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -