Support background colors (& icon) in link search results

This commit is contained in:
Nathan Gray 2012-06-06 18:47:04 +00:00
parent 2bb8169ded
commit 63a8718dd8
3 changed files with 49 additions and 1 deletions

View File

@ -503,6 +503,15 @@ class etemplate_new extends etemplate_widget_template
return $etemplate_old->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row);
}
/**
* Avoid fatal error from addressbook
*/
public static function cats2color($cats)
{
trigger_error('Calling etemplate_old', E_USER_NOTICE);
return etemplate_old::cats2color($cats);
}
}

View File

@ -393,6 +393,41 @@ var et2_link_entry = et2_inputWidget.extend({
minLength: self.minimum_characters,
disabled: self.options.disabled
});
// Custom display (colors)
this.search.data("autocomplete")._renderItem = function(ul, item) {
var li = jQuery(document.createElement('li'))
.data("item.autocomplete", item);
var extra = {};
// Extra stuff
if(typeof item.label == 'object') {
extra = item.label;
item.label = extra.label ? extra.label : extra;
if(extra['style.backgroundColor'] || extra.color)
{
li.css('backgroundColor', extra.color ? extra.color : extra['style.backgroundColor']);
}
// Careful with this, some browsers may have trouble loading all at once, which can slow display
if(extra.icon)
{
var img = self.egw().image(extra.icon);
if(img)
{
jQuery(document.createElement("img"))
.attr("src", img)
.css("float", "right")
.appendTo(li);
}
}
}
// Normal stuff
li.append(jQuery( "<a></a>" ).text( item.label ))
.appendTo(ul);
return li;
};
// Bind to enter key to start search early
this.search.keydown(function(e) {

View File

@ -490,7 +490,11 @@ var et2_selectAccount_ro = et2_link_string.extend([et2_IDetachedDOM], {
},
set_value: function(_value) {
this._super.apply(this, arguments);
// Don't bother to lookup if it's not an array, or a number
if(typeof _value == 'object' || !isNaN(_value))
{
this._super.apply(this, arguments);
}
// Don't make it look like a link though
jQuery('li',this.list).removeClass("et2_link et2_link_string");