pandora/static/js/pandora/infoView.js

887 lines
33 KiB
JavaScript
Raw Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
2011-08-05 18:26:27 +00:00
pandora.ui.infoView = function(data) {
// fixme: given that currently, the info view doesn't scroll into view nicely
// when collapsing the movies browser, the info view should become a split panel
2011-10-02 15:37:58 +00:00
var ui = pandora.user.ui,
canEdit = pandora.site.capabilities.canEditMetadata[pandora.user.level],
2011-10-02 15:37:58 +00:00
css = {
2011-08-06 03:19:14 +00:00
marginTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
},
2011-10-02 15:37:58 +00:00
iconRatio = ui.icons == 'posters'
? (ui.showSitePosters ? 5/8 : data.posterRatio) : 1,
2011-10-02 15:37:58 +00:00
iconSize = ui.infoIconSize,
2011-08-07 22:15:08 +00:00
iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio),
iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio),
iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8,
isEditable = canEdit && data.id.substr(0, 2) == '0x',
2011-10-02 15:37:58 +00:00
listWidth = 144 + Ox.UI.SCROLLBAR_SIZE,
margin = 16,
statisticsWidth = 128,
2011-08-06 13:34:56 +00:00
uid = Ox.uid(),
2011-10-02 15:37:58 +00:00
that = Ox.Element(),
2011-08-05 18:26:27 +00:00
$list,
2011-10-02 15:37:58 +00:00
2011-08-05 18:26:27 +00:00
$info = $('<div>')
.css({
position: 'absolute',
left: canEdit && !ui.showIconBrowser ? -listWidth + 'px' : 0,
2011-08-05 18:26:27 +00:00
top: 0,
right: 0,
})
.appendTo(that.$element),
2011-10-02 15:37:58 +00:00
2011-08-05 18:26:27 +00:00
$data = Ox.Container()
.css({
position: 'absolute',
left: (canEdit ? listWidth : 0) + 'px',
2011-08-05 18:26:27 +00:00
top: 0,
right: 0,
height: pandora.$ui.contentPanel.size(1) + 'px'
})
.appendTo($info),
2011-10-02 15:37:58 +00:00
$icon = Ox.Element({
element: '<img>',
tooltip: canEdit ? (
!ui.showIconBrowser
? 'Doubleclick to edit icon'
: 'Doubleclick to hide icons'
) : ''
})
2011-08-05 18:26:27 +00:00
.attr({
2011-08-07 22:15:08 +00:00
src: '/' + data.id + '/' + (
2011-10-02 15:37:58 +00:00
ui.icons == 'posters'
? (ui.showSitePosters ? 'siteposter' : 'poster') : 'icon'
2011-08-07 22:15:08 +00:00
) + '512.jpg?' + uid
2011-08-05 18:26:27 +00:00
})
.css({
position: 'absolute',
2011-08-07 22:15:08 +00:00
left: margin + iconLeft + 'px',
2011-08-05 18:26:27 +00:00
top: margin + 'px',
2011-08-07 22:15:08 +00:00
width: iconWidth + 'px',
height: iconHeight + 'px',
borderRadius: borderRadius + 'px',
2011-08-06 01:34:07 +00:00
cursor: 'pointer'
})
.bindEvent({
2011-08-07 22:15:08 +00:00
singleclick: toggleIconSize
2011-08-05 18:26:27 +00:00
})
.appendTo($data.$element),
2011-10-02 15:37:58 +00:00
2011-08-05 18:26:27 +00:00
$reflection = $('<div>')
2011-08-07 16:30:26 +00:00
.addClass('OxReflection')
2011-08-05 18:26:27 +00:00
.css({
position: 'absolute',
left: margin + 'px',
2011-08-07 22:15:08 +00:00
top: margin + iconHeight + 'px',
width: iconSize + 'px',
height: iconSize / 2 + 'px',
2011-08-05 18:26:27 +00:00
overflow: 'hidden'
})
.appendTo($data.$element),
2011-10-02 15:37:58 +00:00
2011-08-07 22:15:08 +00:00
$reflectionIcon = $('<img>')
2011-08-05 18:26:27 +00:00
.attr({
2011-08-07 22:15:08 +00:00
src: '/' + data.id + '/' + (
2012-01-20 18:10:25 +00:00
ui.icons == 'posters'
? (ui.showSitePosters ? 'siteposter' : 'poster') : 'icon'
2011-08-07 22:15:08 +00:00
) + '512.jpg?' + uid
2011-08-05 18:26:27 +00:00
})
.css({
position: 'absolute',
2011-08-07 22:15:08 +00:00
left: iconLeft + 'px',
bottom: 0,
2011-08-07 22:15:08 +00:00
width: iconWidth + 'px',
height: iconHeight + 'px',
borderRadius: borderRadius + 'px'
2011-08-05 18:26:27 +00:00
})
.appendTo($reflection),
2011-10-02 15:37:58 +00:00
2011-08-05 18:26:27 +00:00
$reflectionGradient = $('<div>')
.css({
position: 'absolute',
2011-08-07 22:15:08 +00:00
width: iconSize + 'px',
height: iconSize / 2 + 'px'
2011-08-05 18:26:27 +00:00
})
.appendTo($reflection),
2011-10-02 15:37:58 +00:00
$text = Ox.Element({
tooltip: canEdit && !isEditable ? 'Doubleclick to reload metadata' : ''
})
2011-08-05 18:26:27 +00:00
.css({
position: 'absolute',
2011-08-07 22:15:08 +00:00
left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
2011-08-05 18:26:27 +00:00
top: margin + 'px',
right: margin + statisticsWidth + margin + 'px',
2011-08-05 18:26:27 +00:00
})
.bindEvent(canEdit && !isEditable ? {
doubleclick: reloadMetadata
} : {})
2011-08-06 13:34:56 +00:00
.appendTo($data.$element),
2011-10-02 15:37:58 +00:00
$statistics = $('<div>')
.css({
position: 'absolute',
width: statisticsWidth + 'px',
top: margin + 'px',
right: margin + 'px'
})
.appendTo($data.$element),
2011-11-05 17:26:03 +00:00
$capabilities,
2011-08-06 13:34:56 +00:00
$browserImages = [];
2011-08-06 03:19:14 +00:00
2012-01-20 18:10:25 +00:00
pandora.createLinks($text); // FIXME: this is wrong for editables that already have clickLink
2011-10-27 18:47:52 +00:00
2011-10-24 21:30:45 +00:00
// Title -------------------------------------------------------------------
2011-08-06 03:19:14 +00:00
$('<div>')
.css({
marginTop: '-2px'
2011-08-06 03:19:14 +00:00
})
.append(
Ox.Editable({
editable: isEditable,
2011-10-24 21:30:45 +00:00
format: function(value) {
return formatTitle(value);
},
tooltip: isEditable ? 'Doubleclick to edit' : '',
value: data.title
})
.css({
display: 'inline-block',
2011-11-03 17:11:10 +00:00
marginBottom: '-3px',
fontWeight: 'bold',
fontSize: '13px',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.bindEvent({
2011-10-24 21:30:45 +00:00
submit: function(event) {
editMetadata('title', event.value);
}
})
.appendTo($text)
2011-08-06 03:19:14 +00:00
)
.appendTo($text);
2011-10-24 21:30:45 +00:00
// Director ----------------------------------------------------------------
if (data.director || isEditable) {
$('<div>')
.css({
marginTop: '2px'
})
.append(
Ox.Editable({
2011-10-27 18:47:52 +00:00
clickLink: pandora.clickLink,
2011-10-24 21:30:45 +00:00
editable: isEditable,
format: function(value) {
2011-11-04 12:13:04 +00:00
return formatValue(value.split(', '), 'name');
2011-10-24 21:30:45 +00:00
},
2011-11-03 17:11:10 +00:00
placeholder: formatLight('Unknown Director'),
tooltip: isEditable ? 'Doubleclick to edit' : '',
2011-10-24 21:30:45 +00:00
value: data.director ? data.director.join(', ') : 'Unknown Director'
})
.css({
display: 'inline-block',
2011-11-03 17:11:10 +00:00
marginBottom: '-3px',
2011-10-24 21:30:45 +00:00
fontWeight: 'bold',
fontSize: '13px',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.bindEvent({
2011-10-24 21:30:45 +00:00
submit: function(event) {
editMetadata('director', event.value);
}
})
2011-10-24 21:30:45 +00:00
)
.appendTo($text);
}
// Country, Year, Language, Runtime ----------------------------------------
2011-08-06 01:04:09 +00:00
if (isEditable) {
2011-08-06 01:04:09 +00:00
var $div = $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-06 01:04:09 +00:00
.appendTo($text);
2012-01-20 18:10:25 +00:00
['country', 'year'].forEach(function(key, i) {
i && $('<div>').css({float: 'left'}).html(';&nbsp;').appendTo($div);
$('<div>')
.css({float: 'left'})
.html(formatKey(key).replace('</span>', '&nbsp;</span>'))
.appendTo($div);
Ox.Editable({
2011-10-27 18:47:52 +00:00
clickLink: pandora.clickLink,
format: function(value) {
2011-11-03 17:11:10 +00:00
return formatValue(value.split(', '), key)
},
2011-11-03 17:11:10 +00:00
placeholder: formatLight('unknown'),
tooltip: 'Doubleclick to edit',
value: key == 'country'
? (data[key] ? data[key].join(', ') : [''])
: data[key] || ''
})
.css({float: 'left'})
2011-10-24 21:30:45 +00:00
.bindEvent({
submit: function(event) {
editMetadata(key, event.value);
}
})
.appendTo($div);
});
} else if (data.country || data.year || data.language || data.runtime) {
2011-08-06 01:04:09 +00:00
var html = [];
['country', 'year', 'language', 'runtime'].forEach(function(key) {
if (data[key]) {
2011-08-06 01:04:09 +00:00
html.push(
2012-02-03 14:44:11 +00:00
formatKey(key) + (
key != 'runtime' ? formatValue(data[key], key)
: data[key] < 60 ? Math.round(data[key]) + ' sec'
: Math.round(data[key] / 60) + ' min'
)
)
2011-08-06 01:04:09 +00:00
}
});
$('<div>').css(css).html(html.join('; ')).appendTo($text);
2011-08-06 01:04:09 +00:00
}
2011-10-24 21:30:45 +00:00
// Alternative Titles ------------------------------------------------------
data.alternativeTitles && $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.html(
formatKey('Alternative Title' + (data.alternativeTitles.length == 1 ? '' : 's'))
+ data.alternativeTitles.map(function(value) {
2011-08-06 03:19:14 +00:00
return value[0] + (value[1] ? ' '
+ formatLight('(' + value[1] + ')') : '');
2011-08-05 18:26:27 +00:00
}).join(', ')
)
.appendTo($text);
2011-08-06 01:04:09 +00:00
2011-10-16 12:29:04 +00:00
// fixme: episodeDirector seems to be always missing
if (data.episodeDirector || data.writer || data.producer || data.cinematographer || data.editor) {
2011-08-06 01:04:09 +00:00
$div = $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-06 01:04:09 +00:00
.appendTo($text);
html = [];
2011-10-16 12:53:12 +00:00
['episodeDirector', 'writer', 'producer', 'cinematographer', 'editor'].forEach(function(key) {
2011-08-06 01:04:09 +00:00
data[key] && html.push(
2011-10-16 12:29:04 +00:00
formatKey(key == 'episodeDirector' ? 'director' : key) + formatValue(data[key], 'name')
2011-08-06 01:04:09 +00:00
);
});
$div.html(html.join('; '));
}
data.cast && $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-06 01:04:09 +00:00
.html(
formatKey('cast') + data.cast.map(function(value) {
value.character = value.character.replace('(uncredited)', '').trim();
2011-08-06 03:19:14 +00:00
return formatValue(value.actor, 'name')
+ (value.character ? ' '
+ formatLight('(' + formatValue(value.character) + ')')
: '');
2011-08-06 01:04:09 +00:00
}).join(', ')
)
2011-08-05 18:26:27 +00:00
.appendTo($text);
2011-08-06 01:04:09 +00:00
if (data.genre || data.keyword) {
$div = $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.appendTo($text);
2011-08-06 01:04:09 +00:00
html = [];
2011-10-31 16:45:55 +00:00
['genre', 'keyword'].forEach(function(key) {
2011-08-06 01:04:09 +00:00
data[key] && html.push(
2011-10-31 16:45:55 +00:00
formatKey(key == 'keyword' ? 'keywords' : key)
2011-08-06 01:04:09 +00:00
+ formatValue(data[key], key)
);
});
$div.html(html.join('; '));
}
2011-08-05 18:26:27 +00:00
data.summary && $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.html(
formatKey('summary') + data.summary
)
.appendTo($text);
data.trivia && data.trivia.forEach(function(value) {
$('<div>')
.css({
display: 'table-row'
})
.append(
$('<div>')
.css({
display: 'table-cell',
width: '12px',
2011-08-06 01:04:09 +00:00
paddingTop: '4px'
2011-08-05 18:26:27 +00:00
})
.html('<span style="font-weight: bold">&bull;</span>')
)
.append(
$('<div>')
.css({
display: 'table-cell',
paddingTop: '4px',
textAlign: 'justify',
MozUserSelect: 'text',
WebkitUserSelect: 'text'
})
.html(value)
)
.append(
$('<div>').css({clear: 'both'})
)
.appendTo($text);
});
data.filmingLocations && $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.html(
formatKey('Filming Locations') + data.filmingLocations.map(function(location) {
2011-10-01 13:51:18 +00:00
return '<a href="/map/@' + location + '">' + location + '</a>'
}).join(', ')
2011-08-05 18:26:27 +00:00
)
.appendTo($text);
data.releasedate && $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.html(
formatKey('Release Date') + Ox.formatDate(data.releasedate, '%A, %B %e, %Y')
2011-08-05 18:26:27 +00:00
)
.appendTo($text);
if (data.budget || data.gross || data.profit) {
$div = $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.appendTo($text);
2011-08-06 01:04:09 +00:00
html = [];
2011-08-05 18:26:27 +00:00
['budget', 'gross', 'profit'].forEach(function(key) {
2011-08-06 01:04:09 +00:00
data[key] && html.push(
formatKey(key) + Ox.formatCurrency(data[key], '$')
);
2011-08-05 18:26:27 +00:00
});
2011-08-06 01:04:09 +00:00
$div.html(html.join('; '));
2011-08-05 18:26:27 +00:00
}
if (data.rating || data.votes) {
$div = $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.appendTo($text);
2011-08-06 01:04:09 +00:00
html = [];
2011-08-05 18:26:27 +00:00
['rating', 'votes'].forEach(function(key) {
2011-08-06 01:04:09 +00:00
data[key] && html.push(
formatKey(key) + Ox.formatNumber(data[key], key == 'rating' ? 0 : 2) + '%'
2011-08-06 01:04:09 +00:00
);
2011-08-05 18:26:27 +00:00
});
2011-08-06 01:04:09 +00:00
$div.html(html.join('; '));
2011-08-05 18:26:27 +00:00
}
if (data.connections) {
$div = $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-05 18:26:27 +00:00
.appendTo($text);
2011-08-06 01:04:09 +00:00
html = [];
[
'Edited from', 'Edited into',
'Features', 'Featured in',
'Follows', 'Followed by',
'References', 'Referenced in',
'Remake of', 'Remade as',
'Spin off from', 'Spin off',
'Spoofs', 'Spoofed in'
].forEach(function(key) {
data.connections[key] && html.push(
2011-10-01 13:51:18 +00:00
formatKey(key) + data.connections[key].map(function(connection) {
return connection.item
? '<a href="/' + connection.item + '">' + connection.title + '</a>'
: connection.title;
}).join(', ')
2011-08-06 01:04:09 +00:00
);
2011-08-05 18:26:27 +00:00
});
2011-08-06 01:04:09 +00:00
$div.html(html.join('; '));
2011-08-05 18:26:27 +00:00
}
2011-08-06 01:04:09 +00:00
['reviews', 'links'].forEach(function(key) {
data[key] && $('<div>')
2011-08-06 03:19:14 +00:00
.css(css)
2011-08-06 01:04:09 +00:00
.html(
formatKey(key) + data[key].map(function(value) {
return '<a href="' + value.url + '">' + value.source + '</a>'
2011-08-06 01:04:09 +00:00
}).join(', ')
)
.appendTo($text);
});
2011-10-29 17:46:46 +00:00
2011-10-25 13:59:27 +00:00
$('<div>').css({height: '16px'}).appendTo($text);
2011-08-05 18:26:27 +00:00
2011-10-25 13:59:27 +00:00
// Hue, Saturation, Lightness, Volume --------------------------------------
2011-10-24 10:04:41 +00:00
2011-10-23 09:13:57 +00:00
['hue', 'saturation', 'lightness', 'volume'].forEach(function(key) {
2011-10-02 15:37:58 +00:00
$('<div>')
2011-10-23 09:13:57 +00:00
.css({marginBottom: '4px'})
.append(formatKey(key, true))
.append(
Ox.Theme.formatColor(
data[key] || 0, key == 'volume' ? 'lightness' : key
).css({textAlign: 'right'})
)
2011-10-23 09:13:57 +00:00
.appendTo($statistics);
2011-10-02 15:37:58 +00:00
});
2011-10-22 21:03:28 +00:00
2011-10-25 13:59:27 +00:00
// Rights Level ------------------------------------------------------------
2011-10-24 10:04:41 +00:00
var $rightsLevel = $('<div>');
2011-10-22 21:03:28 +00:00
$('<div>')
.css({marginBottom: '4px'})
.append(formatKey('Rights Level', true))
2011-10-23 09:13:57 +00:00
.append($rightsLevel)
2011-10-22 21:03:28 +00:00
.appendTo($statistics);
2011-10-24 10:04:41 +00:00
renderRightsLevel();
2011-08-06 01:34:07 +00:00
2011-10-25 13:59:27 +00:00
// Notes -------------------------------------------------------------------
if (canEdit) {
$('<div>')
.css({marginBottom: '4px'})
.append(formatKey('Notes', true))
.append(
Ox.Editable({
height: 128,
placeholder: formatLight('No notes'),
tooltip: 'Doubleclick to edit',
type: 'textarea',
value: data.notes,
width: 128
})
.bindEvent({
submit: function(event) {
pandora.api.edit({
id: data.id,
notes: event.value
}, function(result) {
// ...
});
}
})
)
.appendTo($statistics);
2011-10-29 17:46:46 +00:00
2011-10-25 13:59:27 +00:00
}
$('<div>').css({height: '16px'}).appendTo($statistics);
if (canEdit) {
2011-08-07 22:15:08 +00:00
$icon.bindEvent({
2011-08-06 01:34:07 +00:00
doubleclick: function() {
2011-10-02 15:37:58 +00:00
pandora.UI.set('showIconBrowser', !ui.showIconBrowser);
$info.animate({
left: ui.showIconBrowser ? 0 : -listWidth + 'px'
}, 250);
$icon.options({
tooltip: !pandora.user.ui.showIconBrowser
? 'Doubleclick to edit icon'
: 'Doubleclick to hide icons'
});
2011-08-05 18:26:27 +00:00
}
});
2011-08-07 22:15:08 +00:00
renderList();
2011-08-05 18:26:27 +00:00
}
2011-10-24 21:30:45 +00:00
function editMetadata(key, value) {
if (value != data[key]) {
var edit = {id: data.id};
if (key == 'title') {
Ox.extend(edit, parseTitle(value));
} else if(['director', 'country'].indexOf(key) > -1) {
edit[key] = value ? value.split(', ') : [];
} else {
edit[key] = value;
2011-10-24 21:30:45 +00:00
}
pandora.api.edit(edit, function(result) {
if (result.data.id != data.id) {
Ox.Request.clearCache(); // fixme: too much
pandora.UI.set({item: result.data.id});
pandora.$ui.browser.value(data.id, 'id', result.data.id);
}
// FIXME: value function should accept {k: v, ...}
pandora.$ui.browser.value(result.data.id, 'title', result.data.title);
pandora.$ui.browser.value(result.data.id, 'director', result.data.director);
pandora.$ui.browser.value(result.data.id, 'country', result.data.country);
pandora.$ui.browser.value(result.data.id, 'year', result.data.year);
//pandora.$ui.contentPanel.replaceElement(0, pandora.$ui.browser = pandora.ui.browser());
});
}
2011-10-24 21:30:45 +00:00
}
2011-10-02 15:37:58 +00:00
function formatKey(key, isStatistics) {
return isStatistics
2011-10-26 14:52:23 +00:00
? $('<div>').css({marginBottom: '4px', fontWeight: 'bold'}).html(Ox.toTitleCase(key))
2011-10-02 15:37:58 +00:00
: '<span style="font-weight: bold">' + Ox.toTitleCase(key) + ':</span> ';
2011-08-05 18:26:27 +00:00
}
2011-08-06 03:19:14 +00:00
function formatLight(str) {
return '<span style="color: rgb(128, 128, 128)">' + str + '</span>';
}
2011-10-24 21:30:45 +00:00
function formatTitle(title) {
var match = /(\(S\d{2}E\d{2}\))/.exec(title);
if (match) {
title = title.replace(match[0], formatLight(match[0]));
}
return title + (
data.originalTitle && data.originalTitle != title
? ' ' + formatLight('(' + data.originalTitle + ')') : ''
);
}
2011-08-05 18:26:27 +00:00
function formatValue(value, key) {
return (Ox.isArray(value) ? value : [value]).map(function(value) {
2011-08-07 16:30:26 +00:00
return key ?
'<a href="/' + key + '=' + value + '">' + value + '</a>'
2011-08-07 16:30:26 +00:00
: value;
2011-08-05 18:26:27 +00:00
}).join(', ');
}
2011-10-26 14:52:23 +00:00
function getRightsLevelElement(rightsLevel) {
return Ox.Theme.formatColorLevel(
rightsLevel,
pandora.site.rightsLevels.map(function(rightsLevel) {
return rightsLevel.name;
})
);
2011-10-24 10:04:41 +00:00
}
2011-10-24 21:30:45 +00:00
function parseTitle(title) {
var data = {title: title},
match = /(\(S(\d{2})E(\d{2})\))/.exec(title),
split;
if (match) {
data.season = parseInt(match[2], 10);
data.episode = parseInt(match[3], 10);
split = title.split(match[1]);
data.seriesTitle = split[0].trim();
data.episodeTitle = split[1].trim();
}
return data;
}
function reloadMetadata() {
var item = ui.item;
// fixme: maybe there's a better method name for this?
pandora.api.updateExternalData({
id: ui.item
}, function(result) {
//reloading metadata might change results too(i.e. genre)
Ox.Request.clearCache();
if (ui.item == item && ui.itemView == 'info') {
pandora.$ui.contentPanel.replaceElement(
1, pandora.$ui.item = pandora.ui.item()
);
}
});
}
2011-10-24 10:04:41 +00:00
function renderCapabilities(rightsLevel) {
var capabilities = Ox.merge(
canEdit ? [{name: 'canSeeItem', symbol: 'Find'}] : [],
2011-10-24 10:04:41 +00:00
[
{name: 'canPlayClips', symbol: 'PlayInToOut'},
{name: 'canPlayVideo', symbol: 'Play'},
{name: 'canDownloadVideo', symbol: 'Download'}
]
),
userLevels = canEdit ? pandora.site.userLevels : [pandora.user.level];
$capabilities.empty();
2011-10-26 14:52:23 +00:00
userLevels.forEach(function(userLevel, i) {
var $element,
$line = $('<div>')
.css({
height: '16px',
marginBottom: '4px'
})
.appendTo($capabilities);
2011-10-25 13:59:27 +00:00
if (canEdit) {
2011-10-26 14:52:23 +00:00
$element = Ox.Theme.formatColorLevel(i, userLevels.map(function(userLevel) {
return Ox.toTitleCase(userLevel);
}), [0, 240]);
2011-10-25 13:59:27 +00:00
Ox.Label({
textAlign: 'center',
title: Ox.toTitleCase(userLevel),
2011-10-26 14:52:23 +00:00
width: 60
2011-10-25 13:59:27 +00:00
})
2011-10-26 14:52:23 +00:00
.addClass('OxColor OxColorGradient')
.css({
float: 'left',
height: '12px',
paddingTop: '2px',
background: $element.css('background'),
fontSize: '8px',
color: $element.css('color')
})
.data({OxColor: $element.data('OxColor')})
2011-10-25 13:59:27 +00:00
.appendTo($line);
}
2011-10-24 10:04:41 +00:00
capabilities.forEach(function(capability) {
2011-10-26 14:52:23 +00:00
var hasCapability = pandora.site.capabilities[capability.name][userLevel] >= rightsLevel,
$element = Ox.Theme.formatColorLevel(hasCapability, ['', '']);
2011-10-24 10:04:41 +00:00
Ox.Button({
tooltip: (canEdit ? Ox.toTitleCase(userLevel) : 'You') + ' '
+ (hasCapability ? 'can' : 'can\'t') + ' '
+ Ox.map(Ox.toSlashes(capability.name).split('/'), function(word, i) {
return i == 0 ? null : word.toLowerCase();
}).join(' ')
.replace('see item', 'see the item')
.replace('play video', 'play the full video')
.replace('download video', 'download the video'),
2011-10-24 10:04:41 +00:00
title: capability.symbol,
type: 'image'
})
2011-10-26 14:52:23 +00:00
.addClass('OxColor OxColorGradient')
.css({background: $element.css('background')})
2011-10-25 13:59:27 +00:00
.css('margin' + (canEdit ? 'Left' : 'Right'), '4px')
2011-10-26 14:52:23 +00:00
.data({OxColor: $element.data('OxColor')})
2011-10-24 10:04:41 +00:00
.appendTo($line);
});
2011-10-25 13:59:27 +00:00
if (!canEdit) {
Ox.Button({
title: 'Help',
tooltip: 'About Rights',
type: 'image'
})
.css({marginLeft: '52px'})
.bindEvent({
click: function() {
2011-11-11 16:53:05 +00:00
pandora.UI.set({page: 'rights'});
2011-10-25 13:59:27 +00:00
}
})
.appendTo($line);
}
2011-10-24 10:04:41 +00:00
});
}
2011-08-07 22:15:08 +00:00
function renderList() {
pandora.api.get({
id: data.id,
2011-10-02 15:37:58 +00:00
keys: [ui.icons == 'posters' ? 'posters' : 'frames']
2012-04-18 15:06:23 +00:00
}, 0, function(result) {
2011-10-02 15:37:58 +00:00
var images = result.data[ui.icons == 'posters' ? 'posters' : 'frames'],
2011-08-07 22:15:08 +00:00
selectedImage = images.filter(function(image) {
return image.selected;
})[0];
$list = Ox.IconList({
2011-10-28 23:27:44 +00:00
defaultRatio: ui.icons == 'posters' ? 5/8 : data.stream.aspectratio,
fixedRatio: ui.icons == 'posters' ? false : data.stream.aspectratio,
2011-08-07 22:15:08 +00:00
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',
2011-10-02 15:37:58 +00:00
title: ui.icons == 'posters' ? data.source : Ox.formatDuration(data.position),
url: data.url.replace('http://', '//'),
2011-08-07 22:15:08 +00:00
width: ratio >= 1 ? size : size * ratio
}
},
items: images,
2011-10-02 15:37:58 +00:00
keys: ui.icons == 'posters'
2011-08-07 22:15:08 +00:00
? ['index', 'source', 'width', 'height', 'url']
: ['index', 'position', 'width', 'height', 'url'],
max: 1,
min: 1,
2011-10-08 17:22:56 +00:00
orientation: 'both',
// fixme: should never be undefined
selected: selectedImage ? [selectedImage['index']] : [],
2011-08-07 22:15:08 +00:00
size: 128,
sort: [{key: 'index', operator: '+'}],
unique: 'index'
})
.css({
display: 'block',
position: 'absolute',
left: 0,
top: 0,
width: listWidth + 'px',
height: pandora.$ui.contentPanel.size(1) + 'px'
})
.bindEvent({
select: function(event) {
var index = event.ids[0];
selectedImage = images.filter(function(image) {
return image.index == index;
})[0];
var imageRatio = selectedImage.width / selectedImage.height,
src = selectedImage.url.replace('http://', '//');
2011-08-07 22:15:08 +00:00
if ($browserImages.length == 0) {
$browserImages = pandora.$ui.browser.find('img[src*="/' + data.id + '/"]');
}
if (ui.icons == 'posters' && !ui.showSitePosters) {
2011-08-07 22:15:08 +00:00
$browserImages.each(function() {
var $this = $(this),
size = Math.max($this.width(), $this.height());
$this.attr({src: src});
2011-10-02 15:37:58 +00:00
ui.icons == 'posters' && $this.css(imageRatio < 1 ? {
2011-08-07 22:15:08 +00:00
width: Math.round(size * imageRatio) + 'px',
height: size + 'px'
} : {
width: size + 'px',
height: Math.round(size / imageRatio) + 'px'
});
});
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
iconRatio = imageRatio;
iconSize = iconSize == 256 ? 512 : 256;
toggleIconSize();
}
2011-10-02 15:37:58 +00:00
pandora.api[ui.icons == 'posters' ? 'setPoster' : 'setPosterFrame'](Ox.extend({
2011-08-07 22:15:08 +00:00
id: data.id
2011-10-02 15:37:58 +00:00
}, ui.icons == 'posters' ? {
2011-08-07 22:15:08 +00:00
source: selectedImage.source
} : {
// fixme: api slightly inconsistent, this shouldn't be "position"
position: selectedImage.index
2011-08-07 22:15:08 +00:00
}), function() {
2011-08-21 08:17:10 +00:00
// fixme: update the info (video preview) frame as well
2011-08-07 22:15:08 +00:00
var src;
2011-10-02 15:37:58 +00:00
if (ui.icons == 'frames') {
2011-08-07 22:15:08 +00:00
src = '/' + data.id + '/icon512.jpg?' + Ox.uid()
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
}
$browserImages.each(function() {
$(this).attr({src: '/' + data.id + '/' + (
2011-10-02 15:37:58 +00:00
ui.icons == 'posters' ? 'poster' : 'icon'
) + '128.jpg?' + Ox.uid()});
2011-08-07 22:15:08 +00:00
});
});
}
})
.appendTo($info);
2012-04-18 15:06:23 +00:00
$list.size();
2011-08-07 22:15:08 +00:00
});
}
2011-10-24 10:04:41 +00:00
function renderRightsLevel() {
2011-11-05 17:26:03 +00:00
var $rightsLevelElement = getRightsLevelElement(data.rightslevel),
2011-10-26 14:52:23 +00:00
$rightsLevelSelect;
2011-10-24 10:04:41 +00:00
$rightsLevel.empty();
if (canEdit) {
$rightsLevelSelect = Ox.Select({
items: pandora.site.rightsLevels.map(function(rightsLevel, i) {
2011-12-22 17:37:13 +00:00
return {id: i, title: rightsLevel.name};
2011-10-24 10:04:41 +00:00
}),
2011-12-22 17:37:13 +00:00
width: 128,
value: data.rightslevel
2011-10-24 10:04:41 +00:00
})
2011-10-26 14:52:23 +00:00
.addClass('OxColor OxColorGradient')
.css({
marginBottom: '4px',
background: $rightsLevelElement.css('background')
})
.data({OxColor: $rightsLevelElement.data('OxColor')})
2011-10-24 10:04:41 +00:00
.bindEvent({
change: function(event) {
2011-12-27 06:54:49 +00:00
var rightsLevel = event.value;
2011-10-26 14:52:23 +00:00
$rightsLevelElement = getRightsLevelElement(rightsLevel);
$rightsLevelSelect
.css({background: $rightsLevelElement.css('background')})
.data({OxColor: $rightsLevelElement.data('OxColor')})
2011-10-24 10:04:41 +00:00
renderCapabilities(rightsLevel);
2011-10-25 13:59:27 +00:00
pandora.api.edit({id: data.id, rightslevel: rightsLevel}, function(result) {
2011-10-24 10:04:41 +00:00
// ...
});
}
})
.appendTo($rightsLevel);
2011-10-25 13:59:27 +00:00
} else {
2011-11-05 17:21:49 +00:00
$rightsLevelElement
2011-10-26 14:52:23 +00:00
.css({
2011-10-25 13:59:27 +00:00
marginBottom: '4px'
2011-10-26 14:52:23 +00:00
})
2011-10-25 13:59:27 +00:00
.appendTo($rightsLevel);
2011-10-24 10:04:41 +00:00
}
$capabilities = $('<div>').appendTo($rightsLevel);
2011-10-25 13:59:27 +00:00
renderCapabilities(data.rightslevel);
2011-10-24 10:04:41 +00:00
}
2011-08-07 22:15:08 +00:00
function toggleIconSize() {
iconSize = iconSize == 256 ? 512 : 256;
iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio);
iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio);
iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
2011-10-02 15:37:58 +00:00
borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8;
2011-08-07 22:15:08 +00:00
$icon.animate({
left: margin + iconLeft + 'px',
width: iconWidth + 'px',
height: iconHeight + 'px',
2011-10-29 17:46:46 +00:00
borderRadius: borderRadius + 'px'
2011-08-06 01:34:07 +00:00
}, 250);
$reflection.animate({
2011-08-07 22:15:08 +00:00
top: margin + iconHeight + 'px',
width: iconSize + 'px',
height: iconSize / 2 + 'px'
2011-08-06 01:34:07 +00:00
}, 250);
2011-08-07 22:15:08 +00:00
$reflectionIcon.animate({
left: iconLeft + 'px',
width: iconWidth + 'px',
height: iconHeight + 'px',
borderRadius: borderRadius + 'px'
2011-08-06 01:34:07 +00:00
}, 250);
$reflectionGradient.animate({
2011-08-07 22:15:08 +00:00
width: iconSize + 'px',
height: iconSize / 2 + 'px'
2011-08-06 01:34:07 +00:00
}, 250);
$text.animate({
2011-08-07 22:15:08 +00:00
left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
2011-08-06 01:34:07 +00:00
}, 250);
2011-08-07 22:15:08 +00:00
pandora.UI.set({infoIconSize: iconSize});
2011-08-06 01:34:07 +00:00
}
2011-08-07 22:15:08 +00:00
that.reload = function() {
var src = src = '/' + data.id + '/' + (
2011-10-02 15:37:58 +00:00
ui.icons == 'posters'
? (ui.showSitePosters ? 'siteposter' : 'poster') : 'icon'
2011-08-07 22:15:08 +00:00
) + '512.jpg?' + Ox.uid()
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
iconSize = iconSize == 256 ? 512 : 256;
2011-10-02 15:37:58 +00:00
iconRatio = ui.icons == 'posters'
? (ui.showSitePosters ? 5/8 : data.posterRatio) : 1;
2011-08-07 22:15:08 +00:00
toggleIconSize();
pandora.user.level == 'admin' && $list.replaceWith($list = renderList());
2011-08-07 22:15:08 +00:00
};
2011-08-05 18:26:27 +00:00
that.resize = function() {
var height = pandora.$ui.contentPanel.size(1);
$list && $list.css({height: height + 'px'});
$data.css({height: height + 'px'});
};
that.bindEvent({
pandora_icons: that.reload,
pandora_showsiteposters: function() {
2011-10-02 15:37:58 +00:00
ui.icons == 'posters' && that.reload();
2011-09-27 14:14:40 +00:00
}
});
2011-08-05 18:26:27 +00:00
return that;
2011-08-20 09:07:45 +00:00
}