fix autocomplete function

This commit is contained in:
rolux 2013-07-22 12:59:42 +00:00
parent 7588e81f71
commit f381c6d786

View file

@ -19,9 +19,7 @@ pandora.ui.findElement = function() {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
pandora.$ui.findInput.options({ pandora.$ui.findInput.focusInput(true);
autocomplete: autocompleteFunction()
}).focusInput(true);
} }
}), }),
] : [], [ ] : [], [
@ -116,38 +114,36 @@ pandora.ui.findElement = function() {
margin: '4px' margin: '4px'
}); });
function autocompleteFunction() { function autocompleteFunction() {
return pandora.user.ui.find.conditions.length ? function(value, callback) { var key = !that
var elementValue = that.value(), ? pandora.user.ui._findState.key
key = elementValue[pandora.user.ui._list ? 1 : 0], : that.value()[pandora.user.ui._list ? 1 : 0],
findKey = Ox.getObjectById(pandora.site.findKeys, key); findKey = Ox.getObjectById(pandora.site.findKeys, key);
return findKey.autocomplete ? function(value, callback) {
value === '' && Ox.Log('', 'Warning: autocomplete function should never be called with empty value'); value === '' && Ox.Log('', 'Warning: autocomplete function should never be called with empty value');
if (findKey.autocomplete) { pandora.api.autocomplete({
pandora.api.autocomplete({ key: key,
key: key, query: {
query: { conditions: pandora.user.ui._list
conditions: pandora.user.ui._list && pandora.$ui.findListSelect.value() == 'list'
&& pandora.$ui.findListSelect.value() == 'list' ? [{key: 'list', value: pandora.user.ui._list, operator: '=='}] : [],
? [{key: 'list', value: pandora.user.ui._list, operator: '=='}] : [], operator: '&'
operator: '&' },
}, range: [0, 20],
range: [0, 20], sort: findKey.autocompleteSort,
sort: [{key: 'votes', operator: '-'}], value: value
value: value }, function(result) {
}, function(result) { callback(result.data.items);
callback(result.data.items); });
});
} else {
callback([]);
}
} : null; } : null;
} }
that.updateElement = function() { that.updateElement = function() {
var findState = pandora.user.ui._findState; var findState = pandora.user.ui._findState;
pandora.$ui.findSelect.value(findState.key); pandora.$ui.findSelect.value(findState.key);
pandora.$ui.findInput.options( pandora.$ui.findInput.options(
findState.key == 'advanced' findState.key == 'advanced' ? {
? {placeholder: Ox._('Edit Query...'), value: ''} placeholder: Ox._('Edit Query...'),
: { value: ''
} : {
autocomplete: autocompleteFunction(), autocomplete: autocompleteFunction(),
placeholder: '', placeholder: '',
value: findState.value value: findState.value