From 039e42110f6abeeb92bdd522d0c029fa5a88a8af Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 11 Oct 2011 13:29:24 +0200 Subject: [IMP] copy colorization code from listview to treeview bzr revid: xmo@openerp.com-20111011112924-ih7on411mirf5wmi --- addons/web/static/src/js/view_tree.js | 42 ++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/view_tree.js') diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js index 7988d65805c..78818c069c0 100644 --- a/addons/web/static/src/js/view_tree.js +++ b/addons/web/static/src/js/view_tree.js @@ -32,6 +32,8 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView# this.records = {}; this.options = _.extend({}, this.defaults, options || {}); + + _.bindAll(this, 'color_for'); }, start: function () { @@ -107,6 +109,43 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView# $select.change(); } }); + + if (this.fields_view.arch.attrs.colors) { + return; + } + 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(); + }, + /** + * Returns the color for the provided record in the current view (from the + * ``@colors`` attribute) + * + * @param {Object} record record for the current row + * @returns {String} CSS color declaration + */ + color_for: function (record) { + if (!this.colors) { return ''; } + var context = _.extend({}, record, { + uid: this.session.uid, + current_date: new Date().toString('yyyy-MM-dd') + // TODO: time, datetime, relativedelta + }); + for(var i=0, len=this.colors.length; i