Code review comment for lp:~domsense/web-addons/adding_web_field_style

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

I'm not in favor to include addons in the community addons which needs to manually patch the server or the addons.

By the way, there is a way, a bit tricky I have to admit, to use the 'options' attribute on the fields.

Basically, the options defined in a field are available in this.node.attrs.options and are stored as JSON. That's far to be as convenient as new attributes for bgcolor, fgcolor and cssclass, but this method does not require to patch the server.

Example (customize the name of the 'create' button on one2many fields):

    openerp.web_custom = function (openerp) {
        var QWeb = openerp.web.qweb;

        var _t = openerp.web._t;

        openerp.web.form.FieldOne2Many.include({

            load_views: function() {
                var self = this;
                var result = this._super();
                var custom_options_str = this.node.attrs.options || '{}';
                var custom_options = JSON.parse(custom_options_str);
                _.each(this.views, function(view) {
                    // apply the custom options defined in the xml field like
                    // <field name="descr_ids" options='{"addable": "+"}'>
                    _.extend(view.options, custom_options);

                    // re-apply the read-only deactivation because they
                    // have the priority in all cases
                    if(view.view_type === "list") {
                        if (self.is_readonly()) {
                            view.options.addable = null;
                            view.options.deletable = null;
                            view.options.isClarkGable = false;
                        }
                    } else if (view.view_type === "form") {
                        if (self.is_readonly()) {
                            view.view_type = 'page';
                        }
                    }
                });
                return result;
            }

        });
    };

review: Abstain

« Back to merge proposal