pandora/static/js/pandora/sortElement.js

82 lines
2.6 KiB
JavaScript
Raw Normal View History

// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
2013-03-01 06:40:24 +00:00
pandora.ui.sortElement = function(isNavigationView) {
var isClipView = pandora.isClipView(),
2013-03-01 11:19:55 +00:00
isEmbed = pandora.isEmbedURL(),
items = (
isClipView ? pandora.site.clipKeys.map(function(key) {
return Ox.extend(Ox.clone(key), {
title: 'Sort by ' + (!pandora.user.ui.item ? 'Clip ' : '') + key.title
});
}) : []
).concat(
!pandora.user.ui.item ? pandora.site.sortKeys.map(function(key) {
return Ox.extend(Ox.clone(key), {
title: 'Sort by ' + key.title
});
}) : []
),
sortKey = !pandora.user.ui.item ? 'listSort' : 'itemSort',
$sortSelect = Ox.Select({
items: items,
value: pandora.user.ui[sortKey][0].key,
2013-03-01 11:19:55 +00:00
width: !isEmbed && isNavigationView ? 120 + Ox.UI.SCROLLBAR_SIZE : 144
})
.bindEvent({
change: function(data) {
var key = data.value;
pandora.UI.set(sortKey, [{
key: key,
operator: pandora.getSortOperator(key)
}]);
}
}),
2013-03-01 06:58:19 +00:00
$orderButton = Ox.Button({
overlap: 'left',
title: getButtonTitle(),
tooltip: getButtonTooltip(),
type: 'image'
})
.bindEvent({
click: function() {
pandora.UI.set(sortKey, [{
key: pandora.user.ui[sortKey][0].key,
operator: pandora.user.ui[sortKey][0].operator == '+' ? '-' : '+'
}]);
}
}),
that = Ox.FormElementGroup({
2013-03-01 06:58:19 +00:00
elements: [$sortSelect, $orderButton],
float: 'right'
})
.css({
float: isNavigationView ? 'right' : 'left',
margin: isNavigationView ? '4px 4px 0 0' : '4px 0 0 4px'
})
.bindEvent('pandora_' + sortKey.toLowerCase(), updateElement);
function getButtonTitle() {
return pandora.user.ui[sortKey][0].operator == '+' ? 'up' : 'down';
}
function getButtonTooltip() {
return pandora.user.ui[sortKey][0].operator == '+' ? 'Ascending' : 'Descending';
}
function updateElement() {
$sortSelect.value(pandora.user.ui[sortKey][0].key);
$orderButton.options({
2013-03-01 06:58:19 +00:00
title: getButtonTitle(),
tooltip: getButtonTooltip()
});
}
return that;
};