pandora/static/js/sortMenu.js

54 lines
1.8 KiB
JavaScript
Raw Normal View History

2011-10-30 21:21:26 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-11-05 17:04:10 +00:00
'use strict';
2011-10-30 21:21:26 +00:00
pandora.ui.sortMenu = function() {
2011-12-20 07:20:23 +00:00
// FIXME: unused
2011-12-20 07:20:23 +00:00
var that = Ox.MenuButton({
2012-05-24 08:22:56 +00:00
items: [].concat(
2011-10-30 21:21:26 +00:00
pandora.site.clipKeys.map(function(key) {
return Ox.extend(Ox.clone(key), {
checked: key.id == pandora.user.ui.itemSort[0].key,
id: key.id,
2013-05-09 10:13:58 +00:00
title: Ox._('Sort by {0}', [key.title])
2011-10-30 21:21:26 +00:00
});
}),
[
{},
2013-05-09 10:13:58 +00:00
{id: 'ascending', title: Ox._('Ascending'), checked: pandora.user.ui.itemSort[0].operator == '+'},
{id: 'descending', title: Ox._('Descending'), checked: pandora.user.ui.itemSort[0].operator == '-'}
2011-10-30 21:21:26 +00:00
]
),
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Sort clips'),
2011-10-30 21:21:26 +00:00
type: 'image'
})
.css({float: 'left', margin: '2px'})
.bindEvent({
click: function(data) {
if (data.checked) {
if (['ascending', 'descending'].indexOf(data.id) > -1) {
2013-07-14 15:36:49 +00:00
pandora.UI.set({itemSort: [{
2011-10-30 21:21:26 +00:00
key: pandora.user.ui.itemSort[0].key,
operator: data.id == 'ascending' ? '+' : '-'
2013-07-14 15:36:49 +00:00
}]});
2011-10-30 21:21:26 +00:00
} else {
2013-07-14 15:36:49 +00:00
pandora.UI.set({itemSort: [{
2011-10-30 21:21:26 +00:00
key: data.id,
operator: pandora.getSortOperator(data.id)
2013-07-14 15:36:49 +00:00
}]});
2011-10-30 21:21:26 +00:00
}
}
},
pandora_itemsort: function() {
pandora.$ui.sortMenu.replaceWith(
pandora.$ui.sortMenu = pandora.ui.sortMenu()
);
}
});
return that;
2013-05-09 10:13:58 +00:00
};