From b77a29933cde895396fd903adbc3c12af4ed0286 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 24 Oct 2011 21:30:45 +0000 Subject: [PATCH] allow for editing metadata --- static/js/pandora/infoView.js | 133 ++++++++++++++++++++++++++-------- 1 file changed, 102 insertions(+), 31 deletions(-) diff --git a/static/js/pandora/infoView.js b/static/js/pandora/infoView.js index 46758168e..b1f160068 100644 --- a/static/js/pandora/infoView.js +++ b/static/js/pandora/infoView.js @@ -134,10 +134,7 @@ pandora.ui.infoView = function(data) { $browserImages = []; - var match = /(\(S\d{2}(E\d{2})?\))/.exec(data.title); - if (match) { - data.title = data.title.replace(match[0], formatLight(match[0])); - } + // Title ------------------------------------------------------------------- $('
') .css({ @@ -146,11 +143,11 @@ pandora.ui.infoView = function(data) { .append( Ox.Editable({ editable: isEditable, + format: function(value) { + return formatTitle(value); + }, tooltip: isEditable ? 'Doubleclick to edit' : '', - value: data.title + ( - data.originalTitle && data.originalTitle != data.title - ? ' ' + formatLight('(' + data.originalTitle + ')') : '' - ) + value: formatTitle(data.title) }) .css({ display: 'inline-block', @@ -159,33 +156,51 @@ pandora.ui.infoView = function(data) { MozUserSelect: 'text', WebkitUserSelect: 'text' }) + .bindEvent({ + submit: function(event) { + editMetadata('title', event.value); + } + }) .appendTo($text) ) .appendTo($text); - $('
') - .css({ - marginTop: '2px' - }) - .append( - Ox.Editable({ - clickLink: clickLink, - editable: isEditable, - format: function(value) { - return formatValue((value || 'Unknown Director').split(', '), 'name'); - }, - tooltip: isEditable ? 'Doubleclick to edit' : '', - value: data.director ? data.director.join(', ') : 'Unknown Director' - }) - .css({ - display: 'inline-block', - fontWeight: 'bold', - fontSize: '13px', - MozUserSelect: 'text', - WebkitUserSelect: 'text' - }) - ) - .appendTo($text); + // Director ---------------------------------------------------------------- + + if (data.director || isEditable) { + $('
') + .css({ + marginTop: '2px' + }) + .append( + Ox.Editable({ + clickLink: clickLink, + editable: isEditable, + format: function(value) { + return value + ? formatValue(value.split(', '), 'name') + : formatLight('Unknown Director'); + }, + tooltip: isEditable ? 'Doubleclick to edit' : '', + value: data.director ? data.director.join(', ') : 'Unknown Director' + }) + .css({ + display: 'inline-block', + fontWeight: 'bold', + fontSize: '13px', + MozUserSelect: 'text', + WebkitUserSelect: 'text' + }) + .bindEvent({ + submit: function(event) { + editMetadata('director', event.value); + } + }) + ) + .appendTo($text); + } + + // Country, Year, Language, Runtime ---------------------------------------- if (isEditable) { var $div = $('
') @@ -209,6 +224,11 @@ pandora.ui.infoView = function(data) { : data[key] || '' }) .css({float: 'left'}) + .bindEvent({ + submit: function(event) { + editMetadata(key, event.value); + } + }) .appendTo($div); key == 'country' && $('
').css({float: 'left'}).html('; ').appendTo($div); }); @@ -227,6 +247,8 @@ pandora.ui.infoView = function(data) { $('
').css(css).html(html.join('; ')).appendTo($text); } + // Alternative Titles ------------------------------------------------------ + data.alternativeTitles && $('
') .css(css) .html( @@ -435,6 +457,30 @@ pandora.ui.infoView = function(data) { return false; } + function editMetadata(key, value) { + 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: '2px', fontWeight: 'bold'}).html(Ox.toTitleCase(key)) @@ -445,6 +491,17 @@ pandora.ui.infoView = function(data) { 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 ? @@ -496,6 +553,20 @@ pandora.ui.infoView = function(data) { } } + 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 renderCapabilities(rightsLevel) { var capabilities = Ox.merge( canEdit ? [{name: 'canSeeItem', symbol: 'Find'}] : [],