pandora/static/js/browser.js

218 lines
8.9 KiB
JavaScript
Raw Permalink Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
2018-06-19 06:33:26 +00:00
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
});
}
2019-06-07 15:30:09 +00:00
}).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 = pandora.getMediaURL('/' + 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'] || data['date'] || '';
} else {
2011-10-26 14:52:23 +00:00
// fixme: this is duplicated many times
format = pandora.getSortKeyData(sortKey).format;
if (Ox.isUndefined(data[sortKey]) || Ox.isNull(data[sortKey])) {
info = '';
} else if (format) {
2011-10-26 14:52:23 +00:00
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: pandora.getItemTitle(data),
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: ['id', 'modified', 'posterRatio'].concat(pandora.site.itemTitleKeys),
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() {
pandora.clipboard.copy(pandora.user.ui.item, 'item');
2013-07-15 09:58:43 +00:00
},
copyadd: function() {
pandora.clipboard.add(pandora.user.ui.item, 'item');
2013-07-15 09:58:43 +00:00
},
gainfocus: function() {
pandora.$ui.mainMenu.replaceItemMenu();
},
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()) {
2013-08-07 08:55:48 +00:00
pandora.$ui[pandora.user.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
}
}
// FIXME: Why are these not handled in the 'resize' handler
// of the other SplitPanel element?
if (pandora.user.ui.itemView == 'documents') {
pandora.$ui.documentsList.size();
} else 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() {
2014-01-15 11:25:52 +00:00
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.focusedElement() || (
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;
};