magisuggest can NOT work setting an empty autocomplete url, using an empty options list instead

This commit is contained in:
Ralf Becker 2014-02-06 09:40:47 +00:00
parent 9df623c4ca
commit 84586b196b

View File

@ -69,7 +69,7 @@ var et2_taglist = et2_selectbox.extend(
}, },
"onchange": { "onchange": {
"description": "Callback when tags are changed. Argument is the new selection.", "description": "Callback when tags are changed. Argument is the new selection."
}, },
"onclick": { "onclick": {
"description": "Callback when a tag is clicked. The clicked tag is passed." "description": "Callback when a tag is clicked. The clicked tag is passed."
@ -140,7 +140,10 @@ var et2_taglist = et2_selectbox.extend(
this.taglist = $j('<div/>').appendTo(this.div); this.taglist = $j('<div/>').appendTo(this.div);
var options = jQuery.extend( { var options = jQuery.extend( {
data: this.options.select_options && !jQuery.isEmptyObject(this.options.select_options) ? this._options2data(this.options.select_options) : this.options.autocomplete_url, // magisuggest can NOT work setting an empty autocomplete url, it will then call page url!
// --> setting an empty options list instead
data: this.options.select_options && !jQuery.isEmptyObject(this.options.select_options) || !this.options.autocomplete_url ?
this._options2data(this.options.select_options || {}) : this.options.autocomplete_url,
dataUrlParams: this.options.autocomplete_params, dataUrlParams: this.options.autocomplete_params,
method: 'GET', method: 'GET',
displayField: "label", displayField: "label",
@ -198,7 +201,7 @@ var et2_taglist = et2_selectbox.extend(
/** /**
* convert _options to taglist data [{id:...,label:...},...] format * convert _options to taglist data [{id:...,label:...},...] format
* *
* @param object|array _options id: label or id: {label: ..., title: ...} pairs, or array if id's are 0, 1, ... * @param {(object|array)} _options id: label or id: {label: ..., title: ...} pairs, or array if id's are 0, 1, ...
*/ */
_options2data: function(_options) _options2data: function(_options)
{ {
@ -246,20 +249,21 @@ var et2_taglist = et2_selectbox.extend(
set_autocomplete_url: function(source) set_autocomplete_url: function(source)
{ {
if(source.indexOf('http') != 0) if(source && source.indexOf('http') != 0)
{ {
source = this.egw().ajaxUrl(source); source = this.egw().ajaxUrl(source);
} }
this.options.autocomplete_url = source; this.options.autocomplete_url = source;
if(this.taglist == null) return; // do NOT set an empty autocomplete_url, magicsuggest would use page url instead!
if(this.taglist == null || !source) return;
this.taglist.setData(source); this.taglist.setData(source);
}, },
/** /**
* Set the list of suggested options to a static list. * Set the list of suggested options to a static list.
* *
* $param Array _options usual format see _options2data * @param {array} _options usual format see _options2data
*/ */
set_select_options: function(_options) set_select_options: function(_options)
{ {
@ -299,7 +303,7 @@ var et2_taglist = et2_selectbox.extend(
values[i] = { values[i] = {
id: v, id: v,
label: v label: v
} };
} }
else else
{ {
@ -308,12 +312,11 @@ var et2_taglist = et2_selectbox.extend(
values[i] = { values[i] = {
id: v, id: v,
label: this.options.select_options[v] label: this.options.select_options[v]
} };
} }
} }
} }
this.taglist.addToSelection(values); this.taglist.addToSelection(values);
}, },
@ -336,10 +339,10 @@ var et2_taglist_email = et2_taglist.extend(
{ {
attributes: { attributes: {
"autocomplete_url": { "autocomplete_url": {
"default": "home.etemplate_widget_taglist.ajax_email.etemplate", "default": "home.etemplate_widget_taglist.ajax_email.etemplate"
}, },
"autocomplete_params": { "autocomplete_params": {
"default": {}, "default": {}
}, },
allowFreeEntries: { allowFreeEntries: {
"default": true, "default": true,