pandora/static/js/browser.js

209 lines
8.5 KiB
JavaScript
Raw Normal View History

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.browser = function() {
var that;
2011-06-06 15:48:11 +00:00
if (!pandora.user.ui.item) {
2011-11-06 08:28:10 +00:00
pandora.user.ui.filterSizes = pandora.getFilterSizes();
pandora.$ui.filters = pandora.ui.filters();
2011-06-19 17:49:25 +00:00
that = Ox.SplitPanel({
2011-05-25 19:42:45 +00:00
elements: [
{
2011-11-06 08:28:10 +00:00
element: pandora.$ui.filters[0],
size: pandora.user.ui.filterSizes[0]
2011-05-25 19:42:45 +00:00
},
{
2011-11-06 08:28:10 +00:00
element: pandora.$ui.filtersInnerPanel = pandora.ui.filtersInnerPanel()
2011-05-25 19:42:45 +00:00
},
{
2011-11-06 08:28:10 +00:00
element: pandora.$ui.filters[4],
size: pandora.user.ui.filterSizes[4]
2011-05-25 19:42:45 +00:00
},
],
id: 'browser',
orientation: 'horizontal'
})
.bindEvent({
2011-09-17 17:40:15 +00:00
resize: function(data) {
2011-11-06 08:28:10 +00:00
pandora.$ui.filters.forEach(function(list) {
2011-05-25 19:42:45 +00:00
list.size();
});
if (pandora.user.ui.listView == 'map') {
pandora.$ui.map.resizeMap();
} else if (pandora.user.ui.listView == 'calendar') {
2011-10-08 19:09:25 +00:00
pandora.$ui.calendar.resizeCalendar();
} else if (pandora.user.ui.listView == 'video') {
pandora.$ui.list.size();
2011-10-01 13:51:18 +00:00
}
2011-05-25 19:42:45 +00:00
},
2011-09-17 17:40:15 +00:00
resizeend: function(data) {
2011-11-06 08:28:10 +00:00
pandora.UI.set({filtersSize: data.size});
2011-05-25 19:42:45 +00:00
},
2011-09-17 17:40:15 +00:00
toggle: function(data) {
2011-06-06 15:48:11 +00:00
data.collapsed && pandora.$ui.list.gainFocus();
2011-11-06 08:28:10 +00:00
pandora.UI.set({showFilters: !data.collapsed});
if (!data.collapsed) {
pandora.$ui.filters.forEach(function($filter) {
var selected = $filter.options('_selected');
if (selected) {
$filter.bindEventOnce({
load: function() {
$filter.options({
_selected: false,
selected: selected
});
}
}).reloadList();
}
});
pandora.$ui.filters.updateMenus();
}
if (pandora.user.ui.listView == 'map') {
pandora.$ui.map.resizeMap();
} else if (pandora.user.ui.listView == 'calendar') {
2011-10-08 19:09:25 +00:00
pandora.$ui.calendar.resizeCalendar();
} else if (pandora.user.ui.listView == 'video') {
pandora.$ui.list.size();
}
2011-05-25 19:42:45 +00:00
}
});
} else {
2011-06-19 17:49:25 +00:00
var that = Ox.IconList({
borderRadius: pandora.user.ui.icons == 'posters' ? 0 : 8,
2011-05-25 19:42:45 +00:00
centered: true,
defaultRatio: pandora.user.ui.icons == 'posters' ? pandora.site.posters.ratio : 1,
draggable: true,
2011-05-25 19:42:45 +00:00
id: 'list',
item: function(data, sort, size) {
size = size || 64;
var ui = pandora.user.ui,
ratio = ui.icons == 'posters'
? (ui.showSitePosters ? pandora.site.posters.ratio : data.posterRatio) : 1,
url = '/' + data.id + '/' + (
ui.icons == 'posters'
? (ui.showSitePosters ? 'siteposter' : 'poster') : 'icon'
) + '128.jpg?' + data.modified,
format, info, sortKey = sort[0].key;
if (['title', 'director', 'random'].indexOf(sortKey) > -1) {
info = data['year'];
} else {
2011-10-26 14:52:23 +00:00
// fixme: this is duplicated many times
format = pandora.getSortKeyData(sortKey).format;
2011-10-26 14:52:23 +00:00
if (format) {
info = (
/^color/.test(format.type.toLowerCase()) ? Ox.Theme : Ox
)['format' + Ox.toTitleCase(format.type)].apply(
2012-05-24 08:22:56 +00:00
this, [data[sortKey]].concat(format.args || [])
2011-10-26 14:52:23 +00:00
);
2013-03-03 12:38:41 +00:00
if (sortKey == 'rightslevel') {
info.css({width: size * 0.75 + 'px'});
2013-03-03 12:38:41 +00:00
}
2011-10-26 14:52:23 +00:00
} else {
info = data[sortKey];
}
}
return {
height: ratio <= 1 ? size : size / ratio,
id: data.id,
info: info,
title: data.title + (data.director.length ? ' (' + data.director.join(', ') + ')' : ''),
url: url,
2011-05-25 19:42:45 +00:00
width: ratio >= 1 ? size : size * ratio
};
},
items: function(data, callback) {
2011-08-24 08:25:08 +00:00
pandora.api.find(Ox.extend(data, {
query: pandora.user.ui.find
2011-05-25 19:42:45 +00:00
}), callback);
},
keys: ['director', 'id', 'modified', 'posterRatio', 'title', 'year'],
2011-05-25 19:42:45 +00:00
max: 1,
min: 1,
orientation: 'horizontal',
pageLength: 32,
2011-06-06 15:48:11 +00:00
selected: [pandora.user.ui.item],
2011-05-25 19:42:45 +00:00
size: 64,
sort: getSort(),
2011-05-25 19:42:45 +00:00
unique: 'id'
})
.addClass('OxMedia')
2011-05-25 19:42:45 +00:00
.bindEvent({
2013-07-15 09:58:43 +00:00
copy: function() {
Ox.Clipboard.copy(pandora.user.ui.item, 'item');
},
copyadd: function() {
Ox.Clipboard.add(pandora.user.ui.item, 'item');
},
2011-09-17 17:40:15 +00:00
open: function() {
2011-05-25 19:42:45 +00:00
that.scrollToSelection();
},
openpreview: function() {
2013-08-02 15:08:16 +00:00
if (pandora.isVideoView()) {
pandora.$ui[itemView].gainFocus().triggerEvent('key_space');
}
},
2011-09-17 17:40:15 +00:00
select: function(data) {
data.ids.length && pandora.UI.set({
2011-10-29 17:46:46 +00:00
'item': data.ids[0]
});
2011-05-25 19:42:45 +00:00
},
2011-09-17 17:40:15 +00:00
toggle: function(data) {
pandora.UI.set({showBrowser: !data.collapsed});
2011-05-25 19:42:45 +00:00
if (data.collapsed) {
// fixme: can we do this for timeline and player too?
if (pandora.user.ui.itemView == 'editor') {
pandora.$ui.editor && pandora.$ui.editor.gainFocus();
2011-05-25 19:42:45 +00:00
}
}
if (pandora.user.ui.itemView == 'timeline') {
pandora.$ui.timeline.options({
height: pandora.$ui.contentPanel.size(1)
});
} else if (pandora.user.ui.itemView == 'map') {
2011-10-04 02:45:29 +00:00
pandora.$ui.map.resizeMap();
} else if (pandora.user.ui.itemView == 'calendar') {
2011-10-08 19:09:25 +00:00
pandora.$ui.calendar.resizeCalendar();
}
},
pandora_icons: function(data) {
that.options({
borderRadius: data.value == 'posters' ? 0 : 8,
defaultRatio: data.value == 'posters' ? pandora.site.posters.ratio : 1
}).reloadList();
},
2011-09-28 17:32:03 +00:00
pandora_item: function(data) {
that.options({selected: [data.value]});
if (['accessed', 'timesaccessed'].indexOf(pandora.user.ui.listSort[0].key) > -1) {
Ox.Request.clearCache('find');
that.reloadList();
}
2011-09-28 17:32:03 +00:00
},
pandora_listsort: function() {
that.options({sort: getSort()})
},
pandora_showsiteposters: function() {
2011-09-28 00:10:26 +00:00
pandora.user.ui.icons == 'posters' && that.reloadList(true);
}
})
.bindEventOnce({
load: function() {
// gain focus if we're on page load or if we've just switched
// to an item and the not-yet-garbage-collected list still has
// focus
if (Ox.Focus.focused() === null || (
pandora.$ui.list && pandora.$ui.list.hasFocus()
)) {
that.gainFocus();
}
}
});
2011-11-11 16:53:05 +00:00
that.css({overflowY: 'hidden'}); // this fixes a bug in firefox
pandora.enableDragAndDrop(that, false);
2011-05-25 19:42:45 +00:00
}
function getSort() {
return ['text', 'position'].indexOf(pandora.user.ui.listSort[0].key) > -1
? pandora.site.user.ui.listSort: pandora.user.ui.listSort
}
2011-05-25 19:42:45 +00:00
return that;
};