2013-03-01 06:08:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2013-03-01 06:40:24 +00:00
|
|
|
pandora.ui.sortElement = function(isNavigationView) {
|
2013-03-01 06:08:51 +00:00
|
|
|
|
2014-01-07 07:52:22 +00:00
|
|
|
var ui = pandora.user.ui,
|
|
|
|
isClipView = pandora.isClipView(),
|
2013-03-01 11:19:55 +00:00
|
|
|
isEmbed = pandora.isEmbedURL(),
|
2013-03-01 06:08:51 +00:00
|
|
|
items = (
|
|
|
|
isClipView ? pandora.site.clipKeys.map(function(key) {
|
|
|
|
return Ox.extend(Ox.clone(key), {
|
2014-01-07 07:52:22 +00:00
|
|
|
title: Ox._((!ui.item ? 'Sort by Clip {0}' : 'Sort by {0}'), [Ox._(key.title)])
|
2013-03-01 06:08:51 +00:00
|
|
|
});
|
|
|
|
}) : []
|
|
|
|
).concat(
|
2014-01-07 07:52:22 +00:00
|
|
|
!ui.item ? pandora.site.sortKeys.map(function(key) {
|
2013-03-01 06:08:51 +00:00
|
|
|
return Ox.extend(Ox.clone(key), {
|
2013-05-09 10:13:58 +00:00
|
|
|
title: Ox._('Sort by {0}', [Ox._(key.title)])
|
2013-03-01 06:08:51 +00:00
|
|
|
});
|
|
|
|
}) : []
|
|
|
|
),
|
2014-01-07 07:52:22 +00:00
|
|
|
sortKey = !ui.item ? 'listSort' : 'itemSort',
|
2013-03-01 06:08:51 +00:00
|
|
|
|
|
|
|
$sortSelect = Ox.Select({
|
|
|
|
items: items,
|
2014-01-07 07:52:22 +00:00
|
|
|
value: ui[sortKey][0].key,
|
2014-09-26 12:12:25 +00:00
|
|
|
width: !isEmbed && isNavigationView && ui.clipColumns == 1 ? 120 + Ox.UI.SCROLLBAR_SIZE : 144
|
2013-03-01 06:08:51 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
change: function(data) {
|
|
|
|
var key = data.value;
|
|
|
|
pandora.UI.set(sortKey, [{
|
|
|
|
key: key,
|
|
|
|
operator: pandora.getSortOperator(key)
|
|
|
|
}]);
|
2013-03-01 07:27:34 +00:00
|
|
|
}
|
2013-03-01 06:08:51 +00:00
|
|
|
}),
|
|
|
|
|
2013-03-01 06:58:19 +00:00
|
|
|
$orderButton = Ox.Button({
|
|
|
|
overlap: 'left',
|
|
|
|
title: getButtonTitle(),
|
|
|
|
tooltip: getButtonTooltip(),
|
2013-03-01 06:08:51 +00:00
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
pandora.UI.set(sortKey, [{
|
2014-01-07 07:52:22 +00:00
|
|
|
key: ui[sortKey][0].key,
|
|
|
|
operator: ui[sortKey][0].operator == '+' ? '-' : '+'
|
2013-03-01 06:08:51 +00:00
|
|
|
}]);
|
2013-03-01 07:27:34 +00:00
|
|
|
}
|
2013-03-01 06:08:51 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
that = Ox.FormElementGroup({
|
2013-03-01 06:58:19 +00:00
|
|
|
elements: [$sortSelect, $orderButton],
|
|
|
|
float: 'right'
|
2013-03-01 06:08:51 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
float: isNavigationView ? 'right' : 'left',
|
|
|
|
margin: isNavigationView ? '4px 4px 0 0' : '4px 0 0 4px'
|
2013-03-01 07:27:34 +00:00
|
|
|
})
|
|
|
|
.bindEvent('pandora_' + sortKey.toLowerCase(), updateElement);
|
2013-03-01 06:08:51 +00:00
|
|
|
|
|
|
|
function getButtonTitle() {
|
2014-01-07 07:52:22 +00:00
|
|
|
return ui[sortKey][0].operator == '+' ? 'up' : 'down';
|
2013-03-01 06:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getButtonTooltip() {
|
2014-01-07 07:52:22 +00:00
|
|
|
return Ox._(ui[sortKey][0].operator == '+' ? 'Ascending' : 'Descending');
|
2013-03-01 06:08:51 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 07:27:34 +00:00
|
|
|
function updateElement() {
|
2014-01-07 07:52:22 +00:00
|
|
|
$sortSelect.value(ui[sortKey][0].key);
|
2013-03-01 06:08:51 +00:00
|
|
|
$orderButton.options({
|
2013-03-01 06:58:19 +00:00
|
|
|
title: getButtonTitle(),
|
|
|
|
tooltip: getButtonTooltip()
|
2013-03-01 06:08:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-06 08:51:17 +00:00
|
|
|
that.resizeElement = function(size) {
|
|
|
|
$sortSelect.options({width: size});
|
|
|
|
};
|
|
|
|
|
2013-03-01 06:08:51 +00:00
|
|
|
return that;
|
|
|
|
|
2013-05-09 10:13:58 +00:00
|
|
|
};
|