diff options
| author | Aaron Bohy <aab@odoo.com> | 2015-05-13 14:20:18 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2015-05-15 09:17:18 +0200 |
| commit | e7ff2d2c6a564823dd05e2d53cb32c47b826caed (patch) | |
| tree | 374733c39e2a346777f6a8710353ac2af09e6a48 /addons/web/static/src/js/compatibility.js | |
| parent | a9522cb46ffc750faece04bb2cb96fa2b22a7131 (diff) | |
[IMP] Web: ListView: semantics classes for row decoration
based on bootstrap contextual colors, and bold/italic fonts.
Backward compatibility is ensured as the ListView is monkey-patched
to keep interpreting colors and fonts attributes.
Diffstat (limited to 'addons/web/static/src/js/compatibility.js')
| -rw-r--r-- | addons/web/static/src/js/compatibility.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/addons/web/static/src/js/compatibility.js b/addons/web/static/src/js/compatibility.js index cb1b3b795de..cc80915735a 100644 --- a/addons/web/static/src/js/compatibility.js +++ b/addons/web/static/src/js/compatibility.js @@ -183,6 +183,84 @@ function start_modules (modules) { return openerp; }; +// Monkey-patching of the ListView for backward compatibiliy of the colors and +// fonts row's attributes, as they are deprecated in 9.0. +ListView.include({ + load_list: function(data) { + this._super(data); + if (this.fields_view.arch.attrs.colors) { + this.colors = _(this.fields_view.arch.attrs.colors.split(';')).chain() + .compact() + .map(function(color_pair) { + var pair = color_pair.split(':'), + color = pair[0], + expr = pair[1]; + return [color, py.parse(py.tokenize(expr)), expr]; + }).value(); + } + + if (this.fields_view.arch.attrs.fonts) { + this.fonts = _(this.fields_view.arch.attrs.fonts.split(';')).chain().compact() + .map(function(font_pair) { + var pair = font_pair.split(':'), + font = pair[0], + expr = pair[1]; + return [font, py.parse(py.tokenize(expr)), expr]; + }).value(); + } + }, + /** + * Returns the style for the provided record in the current view (from the + * ``@colors`` and ``@fonts`` attributes) + * + * @param {Record} record record for the current row + * @returns {String} CSS style declaration + */ + style_for: function (record) { + var len, style= ''; + + var context = _.extend({}, record.attributes, { + uid: session.uid, + current_date: moment().format('YYYY-MM-DD') + // TODO: time, datetime, relativedelta + }); + var i; + var pair; + var expression; + if (this.fonts) { + for(i=0, len=this.fonts.length; i<len; ++i) { + pair = this.fonts[i]; + var font = pair[0]; + expression = pair[1]; + if (py.PY_isTrue(py.evaluate(expression, context))) { + switch(font) { + case 'bold': + style += 'font-weight: bold;'; + break; + case 'italic': + style += 'font-style: italic;'; + break; + case 'underline': + style += 'text-decoration: underline;'; + break; + } + } + } + } + + if (!this.colors) { return style; } + for(i=0, len=this.colors.length; i<len; ++i) { + pair = this.colors[i]; + var color = pair[0]; + expression = pair[1]; + if (py.PY_isTrue(py.evaluate(expression, context))) { + return style += 'color: ' + color + ';'; + } + } + return style; + }, +}); + }); |
