From 0cdb5ca5c9570e31d2347bed720ea3e5fb1e129d Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 4 Aug 2017 12:18:49 +0200 Subject: [PATCH] [REF] web: add utility function to render checkboxes Odoo checkboxes have a special style which requires a special DOM structure. Instead of having to build this structure each time we need a checkbox to be rendered, it is better to have a function that does that. It is also better to have a JS function for this instead of a qweb template so that this has not to be lazy loaded by the frontend for something as simple as a checkbox. --- addons/web/static/src/js/core/dom.js | 29 +++++++++++++++++++ .../web/static/src/js/fields/field_utils.js | 27 ++++++++--------- .../static/src/js/views/list/list_renderer.js | 3 +- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/addons/web/static/src/js/core/dom.js b/addons/web/static/src/js/core/dom.js index e1592c53f73..0ce30e2ac4e 100644 --- a/addons/web/static/src/js/core/dom.js +++ b/addons/web/static/src/js/core/dom.js @@ -201,6 +201,35 @@ return { } return $button; }, + /** + * Renders a checkbox with standard odoo template. This does not use any xml + * template to avoid forcing the frontend part to lazy load a xml file for + * each widget which might want to create a simple checkbox. + * + * @param {Object} [options] + * @param {Object} [options.prop] + * Allows to set the input properties (disabled and checked states). + * @param {string} [options.text] + * The checkbox's associated text. If none is given then a simple + * checkbox without label structure is rendered. + * @returns {jQuery} + */ + renderCheckbox: function (options) { + var $container = $('
'); + if (options && options.prop) { + $container.children('input').prop(options.prop); + } + if (options && options.text) { + $container = $('