cablegates/static/js/pandora/ui/browser.js

92 lines
3.3 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-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) {
pandora.$ui.groups = pandora.ui.groups();
2011-06-19 17:49:25 +00:00
that = Ox.SplitPanel({
2011-05-25 19:42:45 +00:00
elements: [
{
2011-06-06 15:48:11 +00:00
element: pandora.$ui.groups[0],
size: pandora.user.queryGroups[0].size
2011-05-25 19:42:45 +00:00
},
{
2011-06-06 15:48:11 +00:00
element: pandora.$ui.groupsInnerPanel = pandora.ui.groupsInnerPanel()
2011-05-25 19:42:45 +00:00
},
{
2011-06-06 15:48:11 +00:00
element: pandora.$ui.groups[4],
size: pandora.user.queryGroups[4].size
2011-05-25 19:42:45 +00:00
},
],
id: 'browser',
orientation: 'horizontal'
})
.bindEvent({
resize: function(event, data) {
2011-06-06 15:48:11 +00:00
pandora.user.ui.groupsSize = data;
$.each(pandora.$ui.groups, function(i, list) {
2011-05-25 19:42:45 +00:00
list.size();
});
},
resizeend: function(event, data){
pandora.UI.set({groupsSize: data});
},
toggle: function(event, data) {
pandora.UI.set({showGroups: !data.collapsed});
2011-06-06 15:48:11 +00:00
data.collapsed && pandora.$ui.list.gainFocus();
2011-05-25 19:42:45 +00:00
}
});
} else {
2011-06-19 17:49:25 +00:00
var that = Ox.IconList({
2011-05-25 19:42:45 +00:00
centered: true,
id: 'list',
item: function(data, sort, size) {
var ratio = data.poster.width / data.poster.height;
size = size || 64;
return {
height: ratio <= 1 ? size : size / ratio,
id: data['id'],
info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key],
title: data.title + (data.director ? ' (' + data.director + ')' : ''),
url: data.poster.url.replace(/jpg/, size + '.jpg'),
width: ratio >= 1 ? size : size * ratio
};
},
items: function(data, callback) {
//Ox.print('data, pandora.Query.toObject', data, pandora.Query.toObject())
pandora.api.find($.extend(data, {
query: pandora.Query.toObject()
}), callback);
},
keys: ['director', 'id', 'poster', 'title', 'year'],
max: 1,
min: 1,
orientation: 'horizontal',
2011-06-06 15:48:11 +00:00
selected: [pandora.user.ui.item],
2011-05-25 19:42:45 +00:00
size: 64,
2011-06-06 15:48:11 +00:00
sort: pandora.user.ui.lists[pandora.user.ui.list].sort,
2011-05-25 19:42:45 +00:00
unique: 'id'
})
.bindEvent({
open: function(event, data) {
that.scrollToSelection();
},
select: function(event, data) {
pandora.URL.set(data.ids[0]);
},
toggle: function(event, data) {
pandora.UI.set({showMovies: !data.collapsed});
if (data.collapsed) {
2011-06-06 15:48:11 +00:00
if (pandora.user.ui.itemView == 'timeline') {
pandora.$ui.editor.gainFocus();
2011-05-25 19:42:45 +00:00
}
}
}
});
}
that.update = function() {
2011-06-06 15:48:11 +00:00
pandora.$ui.contentPanel.replaceElement(0, pandora.$ui.browser = pandora.ui.browser());
2011-05-25 19:42:45 +00:00
}
return that;
};