From f22dd81a7c903cabb295f097f59baa4f7109347f Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 15 Feb 2012 19:35:53 +0000 Subject: [PATCH] fix a bug where duration would be missing from the info page for non-admins; move user/created/modified to the right column --- pandora/item/views.py | 3 +- static/js/pandora/infoView.padma.js | 112 ++++++++++++---------------- 2 files changed, 51 insertions(+), 64 deletions(-) diff --git a/pandora/item/views.py b/pandora/item/views.py index 7b3a632b..0a92b429 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -439,7 +439,8 @@ def edit(request): item.level = data['rightslevel'] del data['rightslevel'] if 'user' in data: - if request.user.get_profile().get_level() in ('admin', 'staff'): + if request.user.get_profile().get_level() in ('admin', 'staff') and \ + models.User.objects.filter(username=data['user']).exists(): item.user = models.User.objects.get(username=data['user']) del data['user'] r = item.edit(data) diff --git a/static/js/pandora/infoView.padma.js b/static/js/pandora/infoView.padma.js index d5b4b4d2..8220da9d 100644 --- a/static/js/pandora/infoView.padma.js +++ b/static/js/pandora/infoView.padma.js @@ -244,6 +244,7 @@ pandora.ui.infoView = function(data) { .appendTo($div); Ox.Editable({ clickLink: pandora.clickLink, + editable: key != 'duration', format: function(value) { return key != 'duration' ? formatValue(value.split(', '), key) : value < 60 ? Math.round(value) + ' sec' @@ -264,13 +265,16 @@ pandora.ui.infoView = function(data) { .appendTo($div); }); $('
').appendTo($center); - } else if (data.location || data.date || data.language) { + } else { html = []; - ['location', 'date', 'language'].forEach(function(key) { + ['location', 'date', 'language', 'duration'].forEach(function(key) { if (data[key]) { html.push( - formatKey(key) - + formatValue(data[key], key) + formatKey(key) + ( + key != 'duration' ? formatValue(data[key], key) + : data[key] < 60 ? Math.round(data[key]) + ' sec' + : Math.round(data[key] / 60) + ' min' + ) ); } }); @@ -382,7 +386,8 @@ pandora.ui.infoView = function(data) { $('
').css(css).html(data.description).appendTo($center); } - // License --------------------------------------------------------------- + // License ----------------------------------------------------------------- + $div = $('
').css(css).css({marginTop: '16px'}).appendTo($center); if (canEdit) { $('
') @@ -407,46 +412,6 @@ pandora.ui.infoView = function(data) { ); } - // User, Created & Modified ------------------------------------------------ - - $div = $('
').css(css).css({marginTop: '16px'}).appendTo($center); - html = []; - if (['admin', 'staff'].indexOf(pandora.user.level) > -1) { - $('
') - .css({float: 'left'}) - .html(formatKey('user').replace('', ' ')) - .appendTo($div); - Ox.Editable({ - placeholder: formatLight('No User'), - tooltip: 'Doubleclick to edit', - value: data.user - }) - .bindEvent({ - submit: function(event) { - editMetadata('user', event.value); - } - }) - .appendTo($div); - $div.append('; '); - ['created', 'modified'].forEach(function(key) { - data[key] && html.push( - formatKey(key == 'modified' ? 'Last Modified' : key) - + (key == 'user' ? data.user : Ox.formatDate(data[key], '%F %T')) - ); - }); - $div.append(html.join('; ')); - } else { - ['user', 'created', 'modified'].forEach(function(key) { - data[key] && html.push( - formatKey(key == 'modified' ? 'Last Modified' : key) - + (key == 'user' ? data.user : Ox.formatDate(data[key], '%F %T')) - ); - }); - $div.html(html.join('; ')); - } - - $('
').css({height: '16px'}).appendTo($center); - // Hue, Saturation, Lightness, Volume -------------------------------------- ['hue', 'saturation', 'lightness', 'volume'].forEach(function(key) { @@ -461,6 +426,44 @@ pandora.ui.infoView = function(data) { .appendTo($right); }); + // User and Groups --------------------------------------------------------- + + ['user', 'groups'].forEach(function(key) { + $('
') + .css({marginBottom: '4px'}) + .append(formatKey(key, true)) + .append( + $('
') + .css({margin: '2px 0 0 -1px'}) // fixme: weird + .append( + Ox.Editable({ + placeholder: key == 'groups' ? formatLight('No Groups') : '', + editable: canEdit, + tooltip: canEdit ? 'Doubleclick to edit' : '', + value: key == 'user' ? data[key] : data[key].join(', ') + }) + .bindEvent({ + submit: function(event) { + editMetadata(key, event.value); + } + }) + ) + ) + .appendTo($right); + }); + + // Created and Modified ---------------------------------------------------- + + ['created', 'modified'].forEach(function(key) { + $('
') + .css({marginBottom: '4px'}) + .append(formatKey(key, true)) + .append( + $('
').html(Ox.formatDate(data[key], '%F %T')) + ) + .appendTo($right); + }); + // Rights Level ------------------------------------------------------------ if (canEdit) { @@ -473,27 +476,10 @@ pandora.ui.infoView = function(data) { renderRightsLevel(); } - // Groups, Notes --------------------------------------------------------- + // Notes -------------------------------------------------------------------- if (canEdit) { - $('
') - .css({marginBottom: '4px'}) - .append(formatKey('Groups', true)) - .append( - Ox.Editable({ - placeholder: formatLight('No Groups'), - tooltip: 'Doubleclick to edit', - value: data.groups.join(', '), - }) - .bindEvent({ - submit: function(event) { - editMetadata('groups', event.value); - } - }) - ) - .appendTo($right); - $('
') .css({marginBottom: '4px'}) .append(formatKey('Notes', true))