[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
This commit is contained in:
commit
b79c25ccfd
|
@ -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']
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -670,7 +670,7 @@
|
|||
</t>
|
||||
<tr t-name="ListView.row" t-att-class="row_parity"
|
||||
t-att-data-id="record.get('id')"
|
||||
t-att-style="view.color_for(record)">
|
||||
t-att-style="view.style_for(record)">
|
||||
<t t-foreach="columns" t-as="column">
|
||||
<td t-if="column.meta">
|
||||
|
||||
|
|
Loading…
Reference in New Issue