mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-23 07:09:20 +01:00
fixed taglist to no longer require ids to be set in select_options, IF allowFreeEntries is left on its default true
This commit is contained in:
parent
118657ddee
commit
b70f4bcd27
@ -24,7 +24,7 @@
|
|||||||
*
|
*
|
||||||
* Uses MagicSuggest library
|
* Uses MagicSuggest library
|
||||||
* @see http://nicolasbize.github.io/magicsuggest/
|
* @see http://nicolasbize.github.io/magicsuggest/
|
||||||
* @augments et2_inputWidget
|
* @augments et2_selectbox
|
||||||
*/
|
*/
|
||||||
var et2_taglist = et2_selectbox.extend(
|
var et2_taglist = et2_selectbox.extend(
|
||||||
{
|
{
|
||||||
@ -93,7 +93,7 @@ var et2_taglist = et2_selectbox.extend(
|
|||||||
"description": "Callback to provide a custom renderer for each suggested item. Function parameter is the select_option data for that ID."
|
"description": "Callback to provide a custom renderer for each suggested item. Function parameter is the select_option data for that ID."
|
||||||
},
|
},
|
||||||
"width": {
|
"width": {
|
||||||
default: "100%"
|
"default": "100%"
|
||||||
},
|
},
|
||||||
"maxSelection": {
|
"maxSelection": {
|
||||||
"name": "max Selection",
|
"name": "max Selection",
|
||||||
@ -167,8 +167,8 @@ var et2_taglist = et2_selectbox.extend(
|
|||||||
|
|
||||||
// Display / hide a loading icon while fetching
|
// Display / hide a loading icon while fetching
|
||||||
$j(this.taglist)
|
$j(this.taglist)
|
||||||
.on("beforeload", function() {this.container.prepend('<div class="ui-icon loading"/>')})
|
.on("beforeload", function() {this.container.prepend('<div class="ui-icon loading"/>');})
|
||||||
.on("load", function() {$j('.loading',this.container).remove()});
|
.on("load", function() {$j('.loading',this.container).remove();});
|
||||||
|
|
||||||
// onChange
|
// onChange
|
||||||
if(this.options.onchange)
|
if(this.options.onchange)
|
||||||
@ -194,6 +194,7 @@ var et2_taglist = et2_selectbox.extend(
|
|||||||
var label = '<span title="'+(typeof item.title != "undefined" ?item.title:'')+'">'+item.label+'</span>';
|
var label = '<span title="'+(typeof item.title != "undefined" ?item.title:'')+'">'+item.label+'</span>';
|
||||||
return label;
|
return label;
|
||||||
},
|
},
|
||||||
|
|
||||||
set_autocomplete_url: function(source)
|
set_autocomplete_url: function(source)
|
||||||
{
|
{
|
||||||
if(source.indexOf('http') != 0)
|
if(source.indexOf('http') != 0)
|
||||||
@ -220,19 +221,24 @@ var et2_taglist = et2_selectbox.extend(
|
|||||||
{
|
{
|
||||||
var option = {id: key};
|
var option = {id: key};
|
||||||
|
|
||||||
// Translate the options
|
|
||||||
if(!this.options.no_lang)
|
|
||||||
{
|
|
||||||
if (typeof _options[key] === 'object')
|
if (typeof _options[key] === 'object')
|
||||||
{
|
{
|
||||||
if(_options[key]["label"]) option["label"] = this.egw().lang(_options[key]["label"]);
|
jQuery.extend(option, _options[key]);
|
||||||
if(_options[key]["title"]) option["title"] = this.egw().lang(_options[key]["title"]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
option.label = this.egw().lang(_options[key]);
|
option.label = _options[key];
|
||||||
}
|
}
|
||||||
|
// Translate the options
|
||||||
|
if (!this.options.no_lang)
|
||||||
|
{
|
||||||
|
option.label = this.egw().lang(option.label);
|
||||||
|
if (typeof option.title == 'string') option.title = this.egw().lang(option.title);
|
||||||
}
|
}
|
||||||
|
// for magicsuggest label are html! so we need to do a minimal escaping
|
||||||
|
option.label = option.label.replace(/&/g, '&').replace(/</g, '≶');
|
||||||
|
if (typeof option.title == 'string') option.title = option.title.replace(/&/g, '&').replace(/</g, '≶');
|
||||||
|
|
||||||
this.options.select_options.push(option);
|
this.options.select_options.push(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,17 +254,40 @@ var et2_taglist = et2_selectbox.extend(
|
|||||||
disabled ? this.taglist.disable() : this.taglist.enable();
|
disabled ? this.taglist.disable() : this.taglist.enable();
|
||||||
},
|
},
|
||||||
|
|
||||||
set_value: function(value) {
|
/**
|
||||||
if(this.options.readonly && !this.options.select_options)
|
* Set value(s) of taglist, add them automatic to select-options, if allowFreeEntries
|
||||||
|
*
|
||||||
|
* @param value (array of) ids
|
||||||
|
*/
|
||||||
|
set_value: function(value)
|
||||||
{
|
{
|
||||||
this.options.select_options = value;
|
if (value && this.options.allowFreeEntries)
|
||||||
|
{
|
||||||
|
var values = jQuery.isArray(value) ? value : [value];
|
||||||
|
var options = jQuery.isArray(this.options.select_options) ? this.options.select_options : [];
|
||||||
|
outerloop:
|
||||||
|
for(var i=0; i < values.length; ++i)
|
||||||
|
{
|
||||||
|
var v = values[i];
|
||||||
|
for(var j=0; j < options.length; ++j)
|
||||||
|
{
|
||||||
|
var o = options[j];
|
||||||
|
if (o.id == v)
|
||||||
|
{
|
||||||
|
continue outerloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options.push({id: v, label: v.replace(/&/g, '&').replace(/</g, '≶')});
|
||||||
|
}
|
||||||
|
this.options.select_options = options;
|
||||||
}
|
}
|
||||||
if(this.taglist == null) return;
|
if(this.taglist == null) return;
|
||||||
this.taglist.clear(true);
|
this.taglist.clear(true);
|
||||||
this.taglist.setValue(value);
|
this.taglist.setValue(value);
|
||||||
},
|
},
|
||||||
getValue: function() {
|
|
||||||
|
|
||||||
|
getValue: function()
|
||||||
|
{
|
||||||
if(this.taglist == null) return null;
|
if(this.taglist == null) return null;
|
||||||
return this.taglist.getValue();
|
return this.taglist.getValue();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user