').css({height: '16px'}).appendTo($statistics);
+
+ function editMetadata(key, value) {
+ if (value != data[key]) {
+ var edit = {id: data.id};
+ if (key == 'title') {
+ Ox.extend(edit, parseTitle(value));
+ } else if (key == 'director' || key == 'country') {
+ edit[key] = value.split(', ');
+ } else {
+ edit[key] = value;
+ }
+ 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());
+ });
+ }
+ }
+
+ function formatKey(key, isStatistics) {
+ return isStatistics
+ ? $('
').css({marginBottom: '4px', fontWeight: 'bold'}).html(Ox.toTitleCase(key))
+ : '
' + Ox.toTitleCase(key) + ': ';
+ }
+
+ function formatLight(str) {
+ return '
' + str + '';
+ }
+
+ 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 + ')') : ''
+ );
+ }
+
+ function formatValue(value, key) {
+ return (Ox.isArray(value) ? value : [value]).map(function(value) {
+ return key ?
+ '
' + value + ''
+ : value;
+ }).join(', ');
+ }
+
+ function getRightsLevelElement(rightsLevel) {
+ return Ox.Theme.formatColorLevel(
+ rightsLevel,
+ pandora.site.rightsLevels.map(function(rightsLevel) {
+ return rightsLevel.name;
+ })
+ );
+ }
+
+ 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) {
+ Ox.Request.clearCache(item);
+ if (ui.item == item && ui.itemView == 'info') {
+ pandora.$ui.contentPanel.replaceElement(
+ 1, pandora.$ui.item = pandora.ui.item()
+ );
+ }
+ });
+ }
+
+ function renderCapabilities(rightsLevel) {
+ var capabilities = Ox.merge(
+ canEdit ? [{name: 'canSeeItem', symbol: 'Find'}] : [],
+ [
+ {name: 'canPlayClips', symbol: 'PlayInToOut'},
+ {name: 'canPlayVideo', symbol: 'Play'},
+ {name: 'canDownloadVideo', symbol: 'Download'}
+ ]
+ ),
+ userLevels = canEdit ? pandora.site.userLevels : [pandora.user.level];
+ $capabilities.empty();
+ userLevels.forEach(function(userLevel, i) {
+ var $element,
+ $line = $('
')
+ .css({
+ height: '16px',
+ marginBottom: '4px'
+ })
+ .appendTo($capabilities);
+ if (canEdit) {
+ $element = Ox.Theme.formatColorLevel(i, userLevels.map(function(userLevel) {
+ return Ox.toTitleCase(userLevel);
+ }), [0, 240]);
+ Ox.Label({
+ textAlign: 'center',
+ title: Ox.toTitleCase(userLevel),
+ width: 60
+ })
+ .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')})
+ .appendTo($line);
+ }
+ capabilities.forEach(function(capability) {
+ var hasCapability = pandora.site.capabilities[capability.name][userLevel] >= rightsLevel,
+ $element = Ox.Theme.formatColorLevel(hasCapability, ['', '']);
+ 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(' '),
+ title: capability.symbol,
+ type: 'image'
+ })
+ .addClass('OxColor OxColorGradient')
+ .css({background: $element.css('background')})
+ .css('margin' + (canEdit ? 'Left' : 'Right'), '4px')
+ .data({OxColor: $element.data('OxColor')})
+ .appendTo($line);
+ });
+ if (!canEdit) {
+ Ox.Button({
+ title: 'Help',
+ tooltip: 'About Rights',
+ type: 'image'
+ })
+ .css({marginLeft: '52px'})
+ .bindEvent({
+ click: function() {
+ pandora.UI.set({page: 'rights'});
+ }
+ })
+ .appendTo($line);
+ }
+ });
+ }
+
+ function renderRightsLevel() {
+ var $rightsLevelElement = getRightsLevelElement(data.rightslevel),
+ $rightsLevelSelect;
+ $rightsLevel.empty();
+ if (canEdit) {
+ $rightsLevelSelect = Ox.Select({
+ items: pandora.site.rightsLevels.map(function(rightsLevel, i) {
+ return {id: i, title: rightsLevel.name, checked: i == data.rightslevel};
+ }),
+ width: 128
+ })
+ .addClass('OxColor OxColorGradient')
+ .css({
+ marginBottom: '4px',
+ background: $rightsLevelElement.css('background')
+ })
+ .data({OxColor: $rightsLevelElement.data('OxColor')})
+ .bindEvent({
+ change: function(event) {
+ var rightsLevel = event.value;
+ $rightsLevelElement = getRightsLevelElement(rightsLevel);
+ $rightsLevelSelect
+ .css({background: $rightsLevelElement.css('background')})
+ .data({OxColor: $rightsLevelElement.data('OxColor')})
+ renderCapabilities(rightsLevel);
+ pandora.api.edit({id: data.id, rightslevel: rightsLevel}, function(result) {
+ // ...
+ });
+ }
+ })
+ .appendTo($rightsLevel);
+ } else {
+ $rightsLevelElement
+ .css({
+ marginBottom: '4px'
+ })
+ .appendTo($rightsLevel);
+ }
+ $capabilities = $('
').appendTo($rightsLevel);
+ renderCapabilities(data.rightslevel);
+ }
+
+ 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,
+ borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8;
+ $icon.animate({
+ left: margin + iconLeft + 'px',
+ width: iconWidth + 'px',
+ height: iconHeight + 'px',
+ borderRadius: borderRadius + 'px'
+ }, 250);
+ $reflection.animate({
+ top: margin + iconHeight + 'px',
+ width: iconSize + 'px',
+ height: iconSize / 2 + 'px'
+ }, 250);
+ $reflectionIcon.animate({
+ left: iconLeft + 'px',
+ width: iconWidth + 'px',
+ height: iconHeight + 'px',
+ borderRadius: borderRadius + 'px'
+ }, 250);
+ $reflectionGradient.animate({
+ width: iconSize + 'px',
+ height: iconSize / 2 + 'px'
+ }, 250);
+ $text.animate({
+ left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
+ }, 250);
+ pandora.UI.set({infoIconSize: iconSize});
+ }
+
+ that.reload = function() {
+ var src = src = '/' + data.id + '/' + (
+ ui.icons == 'posters'
+ ? (ui.showSitePoster ? 'siteposter' : 'poster') : 'icon'
+ ) + '512.jpg?' + Ox.uid()
+ $icon.attr({src: src});
+ $reflectionIcon.attr({src: src});
+ iconSize = iconSize == 256 ? 512 : 256;
+ iconRatio = ui.icons == 'posters'
+ ? (ui.showSitePoster ? 5/8 : data.posterRatio) : 1;
+ toggleIconSize();
+ pandora.user.level == 'admin' && $list.replaceWith($list = renderList());
+ };
+
+ 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_showsiteposter: function() {
+ ui.icons == 'posters' && that.reload();
+ }
+ });
+
+ return that;
+
+}