2011-07-29 18:37:11 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-11-05 17:04:10 +00:00
|
|
|
'use strict';
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.ui.findElement = function() {
|
2011-09-23 10:44:54 +00:00
|
|
|
var findIndex = pandora.user.ui._findState.index,
|
|
|
|
findKey = pandora.user.ui._findState.key,
|
2012-02-19 16:29:34 +00:00
|
|
|
findValue = pandora.user.ui._findState.value,
|
2012-03-18 15:11:16 +00:00
|
|
|
hasPressedClear = false,
|
2012-05-24 08:22:56 +00:00
|
|
|
previousFindKey = findKey,
|
|
|
|
that = Ox.FormElementGroup({
|
|
|
|
elements: [].concat(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: [
|
2013-05-09 10:13:58 +00:00
|
|
|
{id: 'all', title: Ox._('Find: All {0}', [Ox._(pandora.site.itemName.plural)])},
|
|
|
|
{id: 'list', title: Ox._('Find: This List')}
|
2011-05-25 19:42:45 +00:00
|
|
|
],
|
|
|
|
overlap: 'right',
|
2011-12-22 18:30:03 +00:00
|
|
|
type: 'image',
|
2013-08-05 10:19:03 +00:00
|
|
|
tooltip: Ox._('Find: This List'),
|
2011-12-22 18:30:03 +00:00
|
|
|
value: 'list'
|
2011-05-25 19:42:45 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
2011-09-17 17:40:15 +00:00
|
|
|
change: function(data) {
|
2013-08-05 10:19:03 +00:00
|
|
|
pandora.$ui.findListSelect.options({
|
|
|
|
tooltip: data.value == 'all'
|
|
|
|
? Ox._('Find: All {0}', [Ox._(pandora.site.itemName.plural)])
|
|
|
|
: Ox._('Find: This List')
|
|
|
|
});
|
2013-07-22 12:59:42 +00:00
|
|
|
pandora.$ui.findInput.focusInput(true);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
] : [], [
|
2011-06-19 17:49:25 +00:00
|
|
|
pandora.$ui.findSelect = Ox.Select({
|
2011-05-25 19:42:45 +00:00
|
|
|
id: 'select',
|
2012-05-24 08:22:56 +00:00
|
|
|
items: [].concat(
|
2012-05-22 15:07:34 +00:00
|
|
|
pandora.site.findKeys.filter(function(key, i) {
|
2011-11-07 19:09:20 +00:00
|
|
|
return !key.capability
|
2012-05-22 15:07:34 +00:00
|
|
|
|| pandora.site.capabilities[key.capability][pandora.user.level];
|
|
|
|
}).map(function(key) {
|
|
|
|
return {
|
2011-08-24 06:19:34 +00:00
|
|
|
id: key.id,
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Find: {0}', [Ox._(key.title)])
|
2012-05-22 15:07:34 +00:00
|
|
|
};
|
2011-08-24 06:19:34 +00:00
|
|
|
}),
|
|
|
|
[{}, {
|
|
|
|
id: 'advanced',
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Find: Advanced...')
|
2011-08-24 06:19:34 +00:00
|
|
|
}]
|
|
|
|
),
|
2011-05-25 19:42:45 +00:00
|
|
|
overlap: 'right',
|
2011-12-22 07:27:48 +00:00
|
|
|
value: findKey,
|
2011-05-25 19:42:45 +00:00
|
|
|
width: 112
|
|
|
|
})
|
|
|
|
.bindEvent({
|
2011-09-17 17:40:15 +00:00
|
|
|
change: function(data) {
|
2011-12-21 15:34:28 +00:00
|
|
|
if (data.value == 'advanced') {
|
2012-05-28 15:52:11 +00:00
|
|
|
that.updateElement();
|
2012-03-18 15:11:16 +00:00
|
|
|
pandora.$ui.mainMenu.checkItem('findMenu_find_' + previousFindKey);
|
2011-11-10 22:48:32 +00:00
|
|
|
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
2011-05-25 19:42:45 +00:00
|
|
|
} else {
|
2012-03-18 14:59:00 +00:00
|
|
|
pandora.$ui.mainMenu.checkItem('findMenu_find_' + data.value);
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.findInput.options({
|
2011-08-24 08:25:08 +00:00
|
|
|
autocomplete: autocompleteFunction(),
|
|
|
|
placeholder: ''
|
2011-12-18 09:44:31 +00:00
|
|
|
}).focusInput(true);
|
2012-03-18 15:11:16 +00:00
|
|
|
previousFindKey = data.value;
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
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,
|
2011-11-02 18:22:49 +00:00
|
|
|
autocompleteSelectMaxWidth: 256,
|
2011-05-25 19:42:45 +00:00
|
|
|
autocompleteSelectSubmit: true,
|
|
|
|
clear: true,
|
|
|
|
id: 'input',
|
2013-05-09 10:13:58 +00:00
|
|
|
placeholder: findKey == 'advanced' ? Ox._('Edit Query...') : '',
|
2011-05-25 19:42:45 +00:00
|
|
|
value: findValue,
|
|
|
|
width: 192
|
|
|
|
})
|
|
|
|
.bindEvent({
|
2012-02-19 16:29:34 +00:00
|
|
|
clear: function() {
|
|
|
|
hasPressedClear = true;
|
|
|
|
},
|
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') {
|
2012-02-19 16:29:34 +00:00
|
|
|
if (hasPressedClear) {
|
|
|
|
pandora.UI.set({find: pandora.site.user.ui.find});
|
2012-05-28 15:52:11 +00:00
|
|
|
that.updateElement();
|
2012-02-19 16:29:34 +00:00
|
|
|
hasPressedClear = false;
|
|
|
|
}
|
2011-11-04 12:13:04 +00:00
|
|
|
pandora.$ui.findInput.blurInput();
|
2011-11-10 22:48:32 +00:00
|
|
|
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
|
2011-08-24 06:19:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
submit: function(data) {
|
2011-09-28 00:10:26 +00:00
|
|
|
var findInList = pandora.user.ui._list
|
2011-08-24 06:19:34 +00:00
|
|
|
&& pandora.$ui.findListSelect.value() == 'list',
|
|
|
|
key = pandora.$ui.findSelect.value(),
|
2012-05-24 08:22:56 +00:00
|
|
|
conditions = [].concat(
|
2011-10-30 16:49:29 +00:00
|
|
|
findInList ? [{
|
2011-08-24 06:19:34 +00:00
|
|
|
key: 'list',
|
2011-09-28 00:10:26 +00:00
|
|
|
value: pandora.user.ui._list,
|
2011-09-23 10:44:54 +00:00
|
|
|
operator: '=='
|
2011-10-30 16:49:29 +00:00
|
|
|
}] : [],
|
|
|
|
data.value ? [{
|
|
|
|
key: key,
|
|
|
|
value: data.value,
|
|
|
|
operator: '='
|
|
|
|
}] : []
|
|
|
|
);
|
2013-07-14 15:36:49 +00:00
|
|
|
pandora.UI.set({find: {conditions: conditions, operator: '&'}});
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
]),
|
|
|
|
id: 'findElement'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
float: 'right',
|
|
|
|
margin: '4px'
|
|
|
|
});
|
|
|
|
function autocompleteFunction() {
|
2013-07-22 12:59:42 +00:00
|
|
|
var key = !that
|
|
|
|
? pandora.user.ui._findState.key
|
|
|
|
: that.value()[pandora.user.ui._list ? 1 : 0],
|
|
|
|
findKey = Ox.getObjectById(pandora.site.findKeys, key);
|
2013-07-23 08:20:05 +00:00
|
|
|
return findKey && findKey.autocomplete ? function(value, callback) {
|
2011-11-04 15:54:42 +00:00
|
|
|
value === '' && Ox.Log('', 'Warning: autocomplete function should never be called with empty value');
|
2013-07-22 12:59:42 +00:00
|
|
|
pandora.api.autocomplete({
|
|
|
|
key: key,
|
|
|
|
query: {
|
|
|
|
conditions: pandora.user.ui._list
|
|
|
|
&& pandora.$ui.findListSelect.value() == 'list'
|
|
|
|
? [{key: 'list', value: pandora.user.ui._list, operator: '=='}] : [],
|
|
|
|
operator: '&'
|
|
|
|
},
|
|
|
|
range: [0, 20],
|
|
|
|
sort: findKey.autocompleteSort,
|
|
|
|
value: value
|
|
|
|
}, function(result) {
|
2013-07-22 20:50:20 +00:00
|
|
|
callback(result.data.items.map(function(item) {
|
|
|
|
return Ox.decodeHTMLEntities(item);
|
|
|
|
}));
|
2013-07-22 12:59:42 +00:00
|
|
|
});
|
2011-05-25 19:42:45 +00:00
|
|
|
} : null;
|
|
|
|
}
|
2012-05-28 15:52:11 +00:00
|
|
|
that.updateElement = function() {
|
2011-11-11 11:08:23 +00:00
|
|
|
var findState = pandora.user.ui._findState;
|
|
|
|
pandora.$ui.findSelect.value(findState.key);
|
|
|
|
pandora.$ui.findInput.options(
|
2013-07-22 12:59:42 +00:00
|
|
|
findState.key == 'advanced' ? {
|
|
|
|
placeholder: Ox._('Edit Query...'),
|
|
|
|
value: ''
|
|
|
|
} : {
|
2011-11-11 12:28:20 +00:00
|
|
|
autocomplete: autocompleteFunction(),
|
|
|
|
placeholder: '',
|
|
|
|
value: findState.value
|
|
|
|
}
|
2011-11-11 11:08:23 +00:00
|
|
|
);
|
|
|
|
};
|
2011-05-25 19:42:45 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|