2011-06-06 12:23:59 +00:00
|
|
|
pandora.ui.postersDialog = function(id) {
|
|
|
|
|
|
|
|
var height = Math.round(window.innerHeight * 0.9),
|
|
|
|
width = Math.round(window.innerWidth * 0.5),
|
|
|
|
listWidth = 144 + Ox.UI.SCROLLBAR_SIZE,
|
|
|
|
previewWidth = width - listWidth,
|
|
|
|
previewHeight = height - 48,
|
|
|
|
previewRatio = previewWidth / previewHeight,
|
|
|
|
$preview = Ox.Element(),
|
|
|
|
$panel = Ox.SplitPanel({
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
element: Ox.Element(),
|
|
|
|
size: listWidth
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: $preview
|
|
|
|
}
|
|
|
|
],
|
|
|
|
orientation: 'horizontal'
|
|
|
|
}),
|
|
|
|
that = Ox.Dialog({
|
|
|
|
buttons: [
|
|
|
|
Ox.Button({
|
|
|
|
id: 'done',
|
|
|
|
title: 'Done'
|
|
|
|
}).bindEvent({
|
|
|
|
click: function() {
|
|
|
|
that.close();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
content: $panel,
|
|
|
|
height: height,
|
|
|
|
padding: 0,
|
|
|
|
title: 'Manage Posters',
|
|
|
|
width: width
|
|
|
|
});
|
|
|
|
|
|
|
|
pandora.api.get({
|
|
|
|
id: id,
|
|
|
|
keys: ['posters']
|
|
|
|
}, function(result) {
|
|
|
|
var posters = result.data.posters,
|
|
|
|
selected = [posters.filter(function(poster) {
|
|
|
|
return poster.selected;
|
|
|
|
})[0]['source']],
|
|
|
|
$list = Ox.IconList({
|
|
|
|
item: function(data, sort, size) {
|
|
|
|
var ratio = data.width / data.height;
|
|
|
|
size = size || 128;
|
|
|
|
return {
|
|
|
|
height: ratio <= 1 ? size : size / ratio,
|
|
|
|
id: data['id'],
|
|
|
|
info: data.width + ' x ' + data.height + ' px',
|
|
|
|
title: data.source,
|
|
|
|
url: data.url,
|
|
|
|
width: ratio >= 1 ? size : size * ratio
|
|
|
|
}
|
|
|
|
},
|
|
|
|
items: posters,
|
2011-08-01 15:51:34 +00:00
|
|
|
keys: ['precedence', 'source', 'width', 'height', 'url'],
|
2011-06-06 12:23:59 +00:00
|
|
|
max: 1,
|
|
|
|
min: 1,
|
|
|
|
orientation: 'vertical',
|
|
|
|
selected: selected,
|
|
|
|
size: 128,
|
2011-08-01 15:51:34 +00:00
|
|
|
sort: [{key: 'precedence', operator: '+'}],
|
2011-06-06 12:23:59 +00:00
|
|
|
unique: 'source'
|
|
|
|
})
|
|
|
|
.css({background: 'rgb(16, 16, 16)'})
|
|
|
|
.bindEvent({
|
|
|
|
select: function(event) {
|
|
|
|
var source = event.ids[0],
|
|
|
|
poster = posters.filter(function(poster) {
|
|
|
|
return poster.source == source;
|
|
|
|
})[0],
|
|
|
|
posterRatio = poster.width / poster.height,
|
|
|
|
posterWidth = posterRatio > previewRatio ? previewWidth : previewHeight * posterRatio,
|
|
|
|
posterHeight = posterRatio < previewRatio ? previewHeight : previewWidth / posterRatio;
|
|
|
|
$preview.html(
|
|
|
|
$('<img>')
|
|
|
|
.attr({
|
|
|
|
src: poster.url
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
width: posterWidth + 'px',
|
|
|
|
height: posterHeight + 'px',
|
|
|
|
margin: 'auto'
|
|
|
|
})
|
|
|
|
);
|
2011-08-01 16:14:51 +00:00
|
|
|
pandora.api.setPoster({
|
2011-08-01 16:55:18 +00:00
|
|
|
id: id,
|
2011-08-01 16:14:51 +00:00
|
|
|
source: source
|
|
|
|
});
|
2011-06-06 12:23:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$panel.replaceElement(0, $list);
|
|
|
|
});
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
2011-08-04 14:49:16 +00:00
|
|
|
};
|