diff options
| author | Thibault Delavallée <tde@openerp.com> | 2012-04-19 13:45:57 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2012-04-19 13:45:57 +0200 |
| commit | b79c25ccfdae553bfb570918ed8d7fd1547c183b (patch) | |
| tree | 3a9ff84953fa15d85f3a11bf5841659d23df3671 /addons/web/static/src/js | |
| parent | cc7726a25f618e8cc5a60155b203b8b4c509f3ce (diff) | |
| parent | 6589bfeb81c1346af3383688c404fd2c245cb3ac (diff) | |
[MERGE] Merged web-side branch of feature allowing to use 'fonts=bold:expression' in list views. This comes with a server branch to add the 'fonts' attribute in RNG, and an addon branch using this feature with the need_action mechanism.
bzr revid: tde@openerp.com-20120419114557-mv7uf9h5p2i5t3os
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/view_editor.js | 5 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_list.js | 49 |
2 files changed, 45 insertions, 9 deletions
diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 59d1fed9345..6a14c0ef7f9 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -873,7 +873,8 @@ instance.web.ViewEditor = instance.web.OldWidget.extend({ 'widget' : {'name':'widget', 'string': 'widget', 'type': 'selection'}, 'colors' : {'name':'colors', 'string': 'Colors', 'type': 'char'}, 'editable' : {'name':'editable', 'string': 'Editable', 'type': 'selection', 'selection': [["",""],["top","Top"],["bottom", "Bottom"]]}, - 'groups' : {'name':'groups', 'string': 'Groups', 'type': 'selection_multi'} + 'groups' : {'name':'groups', 'string': 'Groups', 'type': 'selection_multi'}, + 'fonts' : {'name':'fonts', 'string': 'fonts', 'type': 'char'}, }; var arch_val = self.get_object_by_id(this.one_object.clicked_tr_id,this.one_object['main_object'], []); this.edit_node_dialog.$element.append('<table id="rec_table" style="width:400px" class="oe_forms"></table>'); @@ -1149,7 +1150,7 @@ var _PROPERTIES = { 'board': ['style'], 'column' : [], 'action' : ['name', 'string', 'colspan', 'groups'], - 'tree' : ['string', 'colors', 'editable', 'link', 'limit', 'min_rows'], + 'tree' : ['string', 'colors', 'editable', 'link', 'limit', 'min_rows', 'fonts'], 'graph' : ['string', 'type'], 'calendar' : ['string', 'date_start', 'date_stop', 'date_delay', 'day_length', 'color', 'mode'] }; diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index c29957cac2d..1fa3ca4fcee 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -56,6 +56,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi this.view_id = view_id; this.previous_colspan = null; this.colors = null; + this.fonts = null; this.columns = []; @@ -140,29 +141,53 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi return this.reload_view(null, null, true); }, /** - * Returns the color for the provided record in the current view (from the - * ``@colors`` attribute) + * 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 color declaration + * @returns {String} CSS style declaration */ - color_for: function (record) { - if (!this.colors) { return ''; } + style_for: function (record) { + var style= ''; + var context = _.extend({}, record.attributes, { uid: this.session.uid, current_date: new Date().toString('yyyy-MM-dd') // TODO: time, datetime, relativedelta }); + + if (this.fonts) { + for(var i=0, len=this.fonts.length; i<len; ++i) { + var pair = this.fonts[i], + font = pair[0], + expression = pair[1]; + if (py.evaluate(expression, context).toJSON()) { + 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(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).toJSON()) { - return 'color: ' + color + ';'; + return style += 'color: ' + color + ';'; } // TODO: handle evaluation errors } - return ''; + return style; }, /** * Called after loading the list view's description, sets up such things @@ -203,6 +228,16 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi }).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(); + } + this.setup_columns(this.fields_view.fields, grouped); this.$element.html(QWeb.render(this._template, this)); |
