diff options
| author | qsm-odoo <qsm@odoo.com> | 2018-02-16 14:58:20 +0100 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2018-04-18 14:47:42 +0200 |
| commit | 374af562e86d8f534665ff793478f7a8b0f4ede2 (patch) | |
| tree | 2bd0555dad539b9dd3b1c9276c081e6a7e7beeb0 /addons/web/static/src/js/views/basic/basic_renderer.js | |
| parent | 5ea27d471e3c4458361b2fc9862e9a4474b1278b (diff) | |
[REF] web: review button rendering
Button rendering was most of the time wrong, incomplete or performed
with duplicated code. This led to:
- Both primary and default classes were put on some statusbar buttons
- Icons were not able to be put for statusbar buttons
- Stat buttons and list buttons code were duplicated
- Classes and style were added twice
- ...
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_renderer.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_renderer.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js index 80cdd05bff5..c05d467052e 100644 --- a/addons/web/static/src/js/views/basic/basic_renderer.js +++ b/addons/web/static/src/js/views/basic/basic_renderer.js @@ -356,6 +356,9 @@ var BasicRenderer = AbstractRenderer.extend({ * @param {Object} node */ _handleAttributes: function ($el, node) { + if ($el.is('button')) { + return; + } if (node.attrs.class) { $el.addClass(node.attrs.class); } @@ -515,6 +518,35 @@ var BasicRenderer = AbstractRenderer.extend({ }); }, /** + * Renders a button according to a given node element. + * + * @private + * @param {Object} node + * @param {Object} [options] + * @param {string} [options.extraClass] + * @param {boolean} [options.textAsTitle=false] + * @returns {jQuery} + */ + _renderButtonFromNode: function (node, options) { + var btnOptions = { + attrs: _.omit(node.attrs, 'icon', 'string', 'type', 'name', 'attrs', 'modifiers', 'options'), + icon: node.attrs.icon, + }; + if (options && options.extraClass) { + var classes = btnOptions.attrs.class ? btnOptions.attrs.class.split(' ') : []; + btnOptions.attrs.class = _.uniq(classes.concat(options.extraClass.split(' '))).join(' '); + } + var str = (node.attrs.string || '').replace(/_/g, ''); + if (str) { + if (options && options.textAsTitle) { + btnOptions.attrs.title = str; + } else { + btnOptions.text = str; + } + } + return dom.renderButton(btnOptions); + }, + /** * Instantiates the appropriate AbstractField specialization for the given * node and prepares its rendering and addition to the DOM. Indeed, the * rendering of the widget will be started and the associated deferred will |
