pandora/static/js/documentBrowser.js

158 lines
6 KiB
JavaScript
Raw Normal View History

2016-10-04 22:00:03 +00:00
'use strict';
2018-06-19 06:33:26 +00:00
2016-10-04 22:00:03 +00:00
pandora.ui.documentBrowser = function() {
var that;
if (!pandora.user.ui.document) {
2019-06-07 15:30:09 +00:00
pandora.user.ui.filterSizes = pandora.getFilterSizes();
pandora.$ui.documentFilters = pandora.ui.documentFilters();
that = Ox.SplitPanel({
elements: [
{
element: pandora.$ui.documentFilters[0],
size: pandora.user.ui.filterSizes[0]
},
{
element: pandora.$ui.documentFiltersInnerPanel = pandora.ui.documentFiltersInnerPanel()
},
{
element: pandora.$ui.documentFilters[4],
size: pandora.user.ui.filterSizes[4]
},
],
id: 'browser',
orientation: 'horizontal'
})
.bindEvent({
resize: function(data) {
pandora.$ui.documentFilters.forEach(function(list) {
list.size();
});
if (pandora.user.ui.listView == 'map') {
pandora.$ui.map.resizeMap();
} else if (pandora.user.ui.listView == 'calendar') {
pandora.$ui.calendar.resizeCalendar();
} else if (pandora.user.ui.listView == 'video') {
pandora.$ui.list.size();
}
},
resizeend: function(data) {
pandora.UI.set({documentFiltersSize: data.size});
},
toggle: function(data) {
data.collapsed && pandora.$ui.list.gainFocus();
pandora.UI.set({showDocumentFilters: !data.collapsed});
if (!data.collapsed) {
pandora.$ui.documentFilters.forEach(function($documentFilter) {
var selected = $documentFilter.options('_selected');
if (selected) {
$documentFilter.bindEventOnce({
load: function() {
$documentFilter.options({
_selected: false,
selected: selected
});
}
}).reloadList();
}
});
pandora.$ui.documentFilters.updateMenus();
}
if (pandora.user.ui.listView == 'map') {
pandora.$ui.map.resizeMap();
} else if (pandora.user.ui.listView == 'calendar') {
pandora.$ui.calendar.resizeCalendar();
} else if (pandora.user.ui.listView == 'video') {
pandora.$ui.list.size();
}
}
});
2016-10-04 22:00:03 +00:00
} else {
var that = Ox.IconList({
borderRadius: 0,
centered: true,
2017-01-25 16:41:06 +00:00
defaultRatio: pandora.site.posters.ratio,
2016-10-04 22:00:03 +00:00
draggable: true,
id: 'list',
item: function(data, sort, size) {
size = size || 64;
var sortKey = sort[0].key,
infoKey = sortKey == 'title' ? 'extension' : sortKey,
key = Ox.getObjectById(pandora.site.documentKeys, infoKey),
info = pandora.formatDocumentKey(key, data),
size = size || 128;
return {
height: Math.round(data.ratio > 1 ? size / data.ratio : size),
id: data.id,
info: info,
title: data.title,
url: pandora.getMediaURL('/documents/' + data.id + '/256p.jpg?' + data.modified),
width: Math.round(data.ratio > 1 ? size : size * data.ratio)
};
},
items: function(data, callback) {
pandora.api.findDocuments(Ox.extend(data, {
query: pandora.user.ui.findDocuments
}), callback);
return Ox.clone(data, true);
},
keys: ['description', 'dimensions', 'extension', 'id', 'title', 'ratio', 'size', 'user', 'entities', 'modified'],
max: 1,
min: 1,
orientation: 'horizontal',
pageLength: 32,
selected: [pandora.user.ui.document],
size: 64,
sort: getSort(),
unique: 'id'
})
.addClass('OxMedia')
.bindEvent({
copy: function() {
2017-03-02 11:14:10 +00:00
pandora.clipboard.copy(pandora.user.ui.document, 'document');
2016-10-04 22:00:03 +00:00
},
copyadd: function() {
2017-03-02 11:14:10 +00:00
pandora.clipboard.add(pandora.user.ui.document, 'document');
2016-10-04 22:00:03 +00:00
},
gainfocus: function() {
pandora.$ui.mainMenu.replaceItemMenu();
},
open: function() {
that.scrollToSelection();
},
openpreview: function() {
2017-03-02 11:14:10 +00:00
// ..
2016-10-04 22:00:03 +00:00
},
select: function(data) {
data.ids.length && pandora.UI.set({
'document': data.ids[0]
});
},
toggle: function(data) {
pandora.UI.set({showBrowser: !data.collapsed});
2017-01-25 20:46:22 +00:00
},
pandora_document: function(data) {
that.options({selected: [data.value]});
2016-10-04 22:00:03 +00:00
}
})
.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();
}
}
});
that.css({overflowY: 'hidden'}); // this fixes a bug in firefox
pandora.enableDragAndDrop(that, false);
}
function getSort() {
return pandora.user.ui.collectionSort;
}
return that;
};