diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/web/static/src/js/widgets/ribbon.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/web/static/src/js/widgets/ribbon.js')
| -rw-r--r-- | addons/web/static/src/js/widgets/ribbon.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/addons/web/static/src/js/widgets/ribbon.js b/addons/web/static/src/js/widgets/ribbon.js new file mode 100644 index 00000000..a682c65a --- /dev/null +++ b/addons/web/static/src/js/widgets/ribbon.js @@ -0,0 +1,48 @@ +odoo.define('web.ribbon', function (require) { + 'use strict'; + + /** + * This widget adds a ribbon on the top right side of the form + * + * - You can specify the text with the title attribute. + * - You can specify the tooltip with the tooltip attribute. + * - You can specify a background color for the ribbon with the bg_color attribute + * using bootstrap classes : + * (bg-primary, bg-secondary, bg-success, bg-danger, bg-warning, bg-info, + * bg-light, bg-dark, bg-white) + * + * If you don't specify the bg_color attribute the bg-success class will be used + * by default. + */ + + var widgetRegistry = require('web.widget_registry'); + var Widget = require('web.Widget'); + + var RibbonWidget = Widget.extend({ + template: 'web.ribbon', + xmlDependencies: ['/web/static/src/xml/ribbon.xml'], + + /** + * @param {Object} options + * @param {string} options.attrs.title + * @param {string} options.attrs.text same as title + * @param {string} options.attrs.tooltip + * @param {string} options.attrs.bg_color + */ + init: function (parent, data, options) { + this._super.apply(this, arguments); + this.text = options.attrs.title || options.attrs.text; + this.tooltip = options.attrs.tooltip; + this.className = options.attrs.bg_color ? options.attrs.bg_color : 'bg-success'; + if (this.text.length > 15) { + this.className += ' o_small'; + } else if (this.text.length > 10) { + this.className += ' o_medium'; + } + }, + }); + + widgetRegistry.add('web_ribbon', RibbonWidget); + + return RibbonWidget; +}); |
