[IMP] URL widget for list view columns

closes #4338
closes #3592
This commit is contained in:
Harrison Hubbell
2015-01-26 16:58:10 +01:00
committed by Xavier Morel
parent e19ec6a8be
commit 4caeda8669
+27
View File
@@ -2160,6 +2160,7 @@ instance.web.list.columns = new instance.web.Registry({
'field.many2onebutton': 'instance.web.list.Many2OneButton',
'field.reference': 'instance.web.list.Reference',
'field.many2many': 'instance.web.list.Many2Many',
'field.url': 'instance.web.list.Url',
'button.toggle_button': 'instance.web.list.toggle_button',
});
instance.web.list.columns.for_ = function (id, field, node) {
@@ -2399,6 +2400,32 @@ instance.web.list.Reference = instance.web.list.Column.extend({
return this._super(row_data, options);
}
});
instance.web.list.Url = instance.web.list.Column.extend({
/**
* Regex checking if a URL has a scheme
*/
PROTOCOL_REGEX: /^(?!\w+:?\/\/)/,
/**
* Format a column as a URL if the column has content.
* Add "//" (inherit current protocol) specified in
* RFC 1808, 2396, and 3986 if no other protocol is included.
*
* @param row_data record whose values should be displayed in the cell
* @param options
*/
_format: function(row_data, options) {
var value = row_data[this.id].value;
if (value) {
return _.template("<a href='<%-href%>' target='_blank'><%-text%></a>", {
href: value.trim().replace(this.PROTOCOL_REGEX, '//'),
text: value
});
}
return this._super(row_data, options);
}
});
instance.web.list.toggle_button = instance.web.list.Column.extend({
format: function (row_data, options) {
this._super(row_data, options);