poster preview, use posters from instance

This commit is contained in:
j 2010-09-10 12:41:08 +02:00
parent afa4e9c584
commit 4b09b8fd98
3 changed files with 18 additions and 21 deletions

View file

@ -148,7 +148,9 @@ class Movie(models.Model):
if self.poster: if self.poster:
self.poster_height = self.poster.height self.poster_height = self.poster.height
self.poster_width = self.poster.width self.poster_width = self.poster.width
else:
self.poster_height = 128
self.poster_width = 80
super(Movie, self).save(*args, **kwargs) super(Movie, self).save(*args, **kwargs)
self.updateFind() self.updateFind()
self.updateSort() self.updateSort()

View file

@ -9,6 +9,7 @@ urlpatterns = patterns("backend.views",
(r'^(?P<id>.*)/(?P<profile>.*.webm)$', 'video'), (r'^(?P<id>.*)/(?P<profile>.*.webm)$', 'video'),
(r'^(?P<id>.*)/(?P<profile>.*.mp4)$', 'video'), (r'^(?P<id>.*)/(?P<profile>.*.mp4)$', 'video'),
(r'^(?P<id>.*)/poster\.(?P<size>\d+)\.jpg$', 'poster'), (r'^(?P<id>.*)/poster\.(?P<size>\d+)\.jpg$', 'poster'),
(r'^(?P<id>.*)/poster\.(?P<size>large)\.jpg$', 'poster'),
(r'^(?P<id>.*)/poster\.jpg$', 'poster'), (r'^(?P<id>.*)/poster\.jpg$', 'poster'),
(r'^(?P<id>.*)/timelines/(?P<timeline>.+)\.(?P<size>\d+)\.(?P<position>\d+)\.png$', 'timeline'), (r'^(?P<id>.*)/timelines/(?P<timeline>.+)\.(?P<size>\d+)\.(?P<position>\d+)\.png$', 'timeline'),
(r'^(?P<id>.*)/data/(?P<data>.+)\.json$', 'data'), (r'^(?P<id>.*)/data/(?P<data>.+)\.json$', 'data'),

View file

@ -516,13 +516,20 @@ app.constructList = function(view) {
id: 'list', id: 'list',
item: function(data, sort, size) { item: function(data, sort, size) {
size = size || 128; size = size || 128;
if(data.poster.height>data.poster.width) {
var height = size,
width = height * data.poster.width / data.poster.height;
} else {
var width = size,
height = width * data.poster.height / data.poster.width;
}
return { return {
height: data.poster.height || 128, // fixme: remove later height: height,
id: data['id'], id: data['id'],
info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key], info: data[['title', 'director'].indexOf(sort[0].key) > -1 ? 'year' : sort[0].key],
title: data.title + (data.director ? ' (' + data.director + ')' : ''), title: data.title + (data.director ? ' (' + data.director + ')' : ''),
url: data.poster.url.replace(/jpg$/, size + '.jpg'), url: data.poster.url.replace(/jpg$/, size + '.jpg'),
width: data.poster.width || 80 // fixme: remove later width: width
}; };
}, },
keys: keys, keys: keys,
@ -559,7 +566,7 @@ app.constructList = function(view) {
}, },
openpreview: function(event, data) { openpreview: function(event, data) {
app.request('find', { app.request('find', {
keys: ['director', 'id', 'posterHeight', 'posterWidth', 'posterURL', 'title'], keys: ['director', 'id', 'poster', 'title'],
query: { query: {
conditions: $.map(data.ids, function(id, i) { conditions: $.map(data.ids, function(id, i) {
return { return {
@ -575,27 +582,14 @@ app.constructList = function(view) {
title = item.title + (item.director ? ' (' + item.director + ')' : ''), title = item.title + (item.director ? ' (' + item.director + ')' : ''),
documentHeight = app.$document.height(), documentHeight = app.$document.height(),
dialogHeight = documentHeight - 40, dialogHeight = documentHeight - 40,
dialogWidth = parseInt((dialogHeight - 48) * 0.75), dialogWidth = parseInt((dialogHeight - 48) * item.poster.width/item.poster.height),
$image = $('<img>') $image = $('<img>')
.attr({ .attr({
src: 'http://0xdb.org/' + item.id + '/poster.large.jpg' src: item.poster.url.replace(/jpg/, 'large.jpg')
}) })
.css({ .css({
height: (dialogHeight - 48) + 'px', height: (dialogHeight - 48 -3) + 'px',
width: dialogWidth + 'px' width: (dialogWidth - 3*item.poster.width/item.poster.height) + 'px'
})
.load(function() {
var image = $image[0],
imageHeight = Math.min(image.height, documentHeight - 88),
imageWidth = parseInt(image.width * imageHeight / image.height);
app.$ui.previewDialog.options({
height: imageHeight + 48,
width: imageWidth
});
$image.css({
height: imageHeight + 'px',
width: imageWidth + 'px'
});
}); });
if ('previewDialog' in app.$ui) { if ('previewDialog' in app.$ui) {
app.$ui.previewDialog.options({ app.$ui.previewDialog.options({