diff options
| author | Xavier Morel <xmo@openerp.com> | 2011-09-29 16:40:36 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2011-09-29 16:40:36 +0200 |
| commit | 3cde15fe013d384fd8a12a6240ec12921e6823c1 (patch) | |
| tree | bba8bbe4a8bee1641ab5b9ccb89786e5d51bb431 /addons/web/static/src | |
| parent | 911c47adf4d790292077d07ac198ca221e00a455 (diff) | |
| parent | d793d6c1aeddc4c7f79d22cc7f1c8a12533e70e6 (diff) | |
[ADD] evaluator proof of concept: colors in list rows
bzr revid: xmo@openerp.com-20110929144036-7u2w6pf6lwkvzck0
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/view_list.js | 36 | ||||
| -rw-r--r-- | addons/web/static/src/xml/base.xml | 3 |
2 files changed, 38 insertions, 1 deletions
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index eeda44c4c99..144e0309c16 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -49,6 +49,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# this.model = dataset.model; this.view_id = view_id; this.previous_colspan = null; + this.colors = null; this.columns = []; @@ -75,6 +76,7 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# } self.compute_aggregates(); }); + }, /** * Retrieves the view's number of records per page (|| section) @@ -132,6 +134,30 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# return this.reload_view(null, null, true); }, /** + * Returns the color for the provided record in the current view (from the + * ``@colors`` attribute) + * + * @param {Record} record record for the current row + * @returns {String} CSS color declaration + */ + color_for: function (record) { + if (!this.colors) { return ''; } + var context = _.extend({}, record.attributes, { + 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<len; ++i) { + var pair = this.colors[i], + color = pair[0], + expression = pair[1]; + if (py.evaluate(expression, context)) { + return 'color: ' + color + ';'; + } + } + return ''; + }, + /** * Called after loading the list view's description, sets up such things * as the view table's columns, renders the table itself and hooks up the * various table-level and row-level DOM events (action buttons, deletion @@ -159,6 +185,16 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# this.fields_view = data; this.name = "" + this.fields_view.arch.attrs.string; + if (this.fields_view.arch.attrs.colors) { + this.colors = _(this.fields_view.arch.attrs.colors.split(';')).map( + function (color_pair) { + var pair = color_pair.split(':'), + color = pair[0], + expr = pair[1]; + return [color, py.parse(py.tokenize(expr))]; + }); + } + this.setup_columns(this.fields_view.fields, grouped); this.$element.html(QWeb.render("ListView", this)); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index ac231e744e4..b7b7658cda5 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -616,7 +616,8 @@ </t> </t> <tr t-name="ListView.row" t-att-class="row_parity" - t-att-data-id="record.get('id')"> + t-att-data-id="record.get('id')" + t-att-style="view.color_for(record)"> <t t-foreach="columns" t-as="column"> <td t-if="column.meta"> |
