2011-07-29 18:37:11 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.ui.findElement = function() {
|
2011-08-24 06:19:34 +00:00
|
|
|
var findIndex = pandora.user.ui.find.index,
|
|
|
|
findKey = pandora.user.ui.find.key,
|
|
|
|
findValue = pandora.user.ui.find.value;
|
2011-06-19 17:49:25 +00:00
|
|
|
var that = Ox.FormElementGroup({
|
2011-06-06 15:48:11 +00:00
|
|
|
elements: $.merge(pandora.user.ui.list ? [
|
2011-06-19 17:49:25 +00:00
|
|
|
pandora.$ui.findListSelect = Ox.Select({
|
2011-05-25 19:42:45 +00:00
|
|
|
items: [
|
2011-06-06 15:48:11 +00:00
|
|
|
{id: 'all', title: 'Find: All ' + pandora.site.itemName.plural},
|
2011-08-24 06:19:34 +00:00
|
|
|
{id: 'list', title: 'Find: This List', checked: true}
|
2011-05-25 19:42:45 +00:00
|
|
|
],
|
|
|
|
overlap: 'right',
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
change: function(event, data) {
|
|
|
|
var key = data.selected[0].id;
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.findInput.options({
|
2011-05-25 19:42:45 +00:00
|
|
|
autocomplete: autocompleteFunction()
|
|
|
|
}).focus();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
] : [], [
|
2011-06-19 17:49:25 +00:00
|
|
|
pandora.$ui.findSelect = Ox.Select({
|
2011-05-25 19:42:45 +00:00
|
|
|
id: 'select',
|
2011-08-24 06:19:34 +00:00
|
|
|
items: Ox.merge(
|
|
|
|
pandora.site.findKeys.map(function(key, i) {
|
|
|
|
return {
|
|
|
|
id: key.id,
|
|
|
|
title: 'Find: ' + key.title,
|
|
|
|
checked: findKey == key.id
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
[{}, {
|
|
|
|
id: 'advanced',
|
|
|
|
title: 'Find: Advanced',
|
|
|
|
checked: findKey == 'advanced'
|
|
|
|
}]
|
|
|
|
),
|
2011-05-25 19:42:45 +00:00
|
|
|
overlap: 'right',
|
|
|
|
width: 112
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
change: function(event, data) {
|
|
|
|
var key = data.selected[0].id;
|
|
|
|
if (key == 'advanced') {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
2011-08-24 08:25:08 +00:00
|
|
|
pandora.$ui.findInput.options({placeholder: 'Edit...'})
|
2011-05-25 19:42:45 +00:00
|
|
|
} else {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.mainMenu.checkItem('findMenu_find_' + key);
|
|
|
|
pandora.$ui.findInput.options({
|
2011-08-24 08:25:08 +00:00
|
|
|
autocomplete: autocompleteFunction(),
|
|
|
|
placeholder: ''
|
2011-05-25 19:42:45 +00:00
|
|
|
}).focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
2011-06-19 17:49:25 +00:00
|
|
|
pandora.$ui.findInput = Ox.Input({
|
2011-05-25 19:42:45 +00:00
|
|
|
autocomplete: autocompleteFunction(),
|
|
|
|
autocompleteSelect: true,
|
|
|
|
autocompleteSelectHighlight: true,
|
|
|
|
autocompleteSelectSubmit: true,
|
|
|
|
clear: true,
|
|
|
|
id: 'input',
|
2011-08-24 06:19:34 +00:00
|
|
|
placeholder: findKey == 'advanced' ? 'Edit...' : '',
|
2011-05-25 19:42:45 +00:00
|
|
|
value: findValue,
|
|
|
|
width: 192
|
|
|
|
})
|
|
|
|
.bindEvent({
|
2011-08-24 06:19:34 +00:00
|
|
|
focus: function(data) {
|
2011-08-24 08:25:08 +00:00
|
|
|
if (pandora.$ui.findSelect.value() == 'advanced') {
|
2011-08-24 06:19:34 +00:00
|
|
|
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
submit: function(data) {
|
|
|
|
var findInList = pandora.user.ui.list
|
|
|
|
&& pandora.$ui.findListSelect.value() == 'list',
|
|
|
|
key = pandora.$ui.findSelect.value(),
|
2011-08-24 06:32:59 +00:00
|
|
|
conditions = data.value ? [{
|
2011-08-24 06:19:34 +00:00
|
|
|
key: key == 'all' ? '' : key,
|
|
|
|
value: data.value,
|
|
|
|
operator: ''
|
2011-08-24 06:32:59 +00:00
|
|
|
}] : [];
|
2011-08-24 06:19:34 +00:00
|
|
|
if (findInList) {
|
|
|
|
pandora.user.ui.query = {
|
2011-08-24 06:32:59 +00:00
|
|
|
conditions: Ox.merge([{
|
2011-08-24 06:19:34 +00:00
|
|
|
key: 'list',
|
|
|
|
value: pandora.user.ui.list,
|
|
|
|
operator: ''
|
2011-08-24 06:32:59 +00:00
|
|
|
}], conditions),
|
2011-08-24 06:19:34 +00:00
|
|
|
operator: '&'
|
|
|
|
}
|
2011-08-24 06:32:59 +00:00
|
|
|
data.value && findIndex == 0 && pandora.user.ui.query.conditions.reverse();
|
2011-08-24 06:19:34 +00:00
|
|
|
} else {
|
|
|
|
if (pandora.user.ui.list) {
|
|
|
|
Ox.forEach(pandora.$ui.folderList, function($list) {
|
|
|
|
$list.options({selected: []});
|
|
|
|
});
|
|
|
|
pandora.UI.set({list: ''});
|
|
|
|
}
|
|
|
|
pandora.user.ui.query = {
|
2011-08-24 06:32:59 +00:00
|
|
|
conditions: conditions,
|
2011-08-24 06:19:34 +00:00
|
|
|
operator: ''
|
|
|
|
}
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
pandora.URL.set(pandora.Query.toString());
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]),
|
|
|
|
id: 'findElement'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
float: 'right',
|
|
|
|
margin: '4px'
|
|
|
|
});
|
|
|
|
function autocompleteFunction() {
|
2011-08-24 06:19:34 +00:00
|
|
|
return pandora.user.ui.query.conditions.length ? function(value, callback) {
|
2011-05-25 19:42:45 +00:00
|
|
|
var elementValue = that.value(),
|
2011-06-06 15:48:11 +00:00
|
|
|
key = elementValue[pandora.user.ui.list ? 1 : 0],
|
|
|
|
findKey = Ox.getObjectById(pandora.site.findKeys, key);
|
2011-05-25 19:42:45 +00:00
|
|
|
Ox.print('!!!!', key, findKey, 'autocomplete' in findKey && findKey.autocomplete)
|
|
|
|
value === '' && Ox.print('Warning: autocomplete function should never be called with empty value');
|
|
|
|
if ('autocomplete' in findKey && findKey.autocomplete) {
|
|
|
|
pandora.api.autocomplete({
|
|
|
|
key: key,
|
2011-06-06 15:48:11 +00:00
|
|
|
query: elementValue[0].id == 'list' ? pandora.user.ui.listQuery : {conditions: [], operator: ''},
|
2011-05-25 19:42:45 +00:00
|
|
|
range: [0, 20],
|
|
|
|
sort: [{
|
|
|
|
key: 'votes',
|
|
|
|
operator: '-'
|
|
|
|
}],
|
|
|
|
value: value
|
|
|
|
}, function(result) {
|
|
|
|
callback(result.data.items);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
callback([]);
|
|
|
|
}
|
|
|
|
} : null;
|
|
|
|
}
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|