prepare for batch edit

This commit is contained in:
j 2018-11-04 22:40:09 +01:00
parent 09015cc5d9
commit d255ed6a03

View file

@ -1,10 +1,12 @@
'use strict'; 'use strict';
pandora.ui.infoView = function(data) { pandora.ui.infoView = function(data, isMixed) {
isMixed = isMixed || {};
var ui = pandora.user.ui, var ui = pandora.user.ui,
canEdit = pandora.site.capabilities.canEditMetadata[pandora.user.level] || data.editable, isMultiple = arguments.length == 2,
canRemove = pandora.site.capabilities.canRemoveItems[pandora.user.level] || data.editable, canEdit = pandora.hasCapability('canEditMetadata') || isMultiple || data.editable,
canRemove = pandora.hasCapability('canRemoveItems'),
css = { css = {
marginTop: '4px', marginTop: '4px',
textAlign: 'justify' textAlign: 'justify'
@ -12,10 +14,10 @@ pandora.ui.infoView = function(data) {
descriptions = [], descriptions = [],
html, html,
iconRatio = ui.icons == 'posters' ? data.posterRatio : 1, iconRatio = ui.icons == 'posters' ? data.posterRatio : 1,
iconSize = ui.infoIconSize, iconSize = isMultiple ? 0 : ui.infoIconSize,
iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio), iconWidth = isMultiple ? 0 : iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio),
iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio), iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio),
iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0, iconLeft = isMultiple ? 0 : iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8, borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8,
margin = 16, margin = 16,
nameKeys = pandora.site.itemKeys.filter(function(key) { nameKeys = pandora.site.itemKeys.filter(function(key) {
@ -61,7 +63,9 @@ pandora.ui.infoView = function(data) {
.bindEvent({ .bindEvent({
click: function(data_) { click: function(data_) {
if (data_.id == 'delete') { if (data_.id == 'delete') {
pandora.$ui.deleteItemDialog = pandora.ui.deleteItemDialog(data).open(); pandora.$ui.deleteItemsDialog = pandora.ui.deleteItemsDialog({
items: [data]
}).open();
} }
} }
}) })
@ -96,7 +100,7 @@ pandora.ui.infoView = function(data) {
that = Ox.SplitPanel({ that = Ox.SplitPanel({
elements: [ elements: [
{element: $bar, size: 16}, {element: $bar, size: isMultiple ? 0 : 16},
{element: $info} {element: $info}
], ],
orientation: 'vertical' orientation: 'vertical'
@ -106,66 +110,68 @@ pandora.ui.infoView = function(data) {
.css({ .css({
position: 'absolute' position: 'absolute'
}) })
.appendTo($info), .appendTo($info);
$icon = Ox.Element({ if (!isMultiple) {
element: '<img>' var $icon = Ox.Element({
}) element: '<img>'
.attr({ })
src: pandora.getMediaURL('/' + data.id + '/' + ( .attr({
ui.icons == 'posters' ? 'poster' : 'icon' src: pandora.getMediaURL('/' + data.id + '/' + (
) + '512.jpg?' + data.modified) ui.icons == 'posters' ? 'poster' : 'icon'
}) ) + '512.jpg?' + data.modified)
.css({ })
position: 'absolute', .css({
left: margin + iconLeft + 'px', position: 'absolute',
top: margin + 'px', left: margin + iconLeft + 'px',
width: iconWidth + 'px', top: margin + 'px',
height: iconHeight + 'px', width: iconWidth + 'px',
borderRadius: borderRadius + 'px', height: iconHeight + 'px',
cursor: 'pointer' borderRadius: borderRadius + 'px',
}) cursor: 'pointer'
.bindEvent({ })
singleclick: toggleIconSize .bindEvent({
}) singleclick: toggleIconSize
.appendTo($left), })
.appendTo($left),
$reflection = $('<div>') $reflection = $('<div>')
.addClass('OxReflection') .addClass('OxReflection')
.css({ .css({
position: 'absolute', position: 'absolute',
left: margin + 'px', left: margin + 'px',
top: margin + iconHeight + 'px', top: margin + iconHeight + 'px',
width: iconSize + 'px', width: iconSize + 'px',
height: Math.round(iconSize / 2) + 'px', height: Math.round(iconSize / 2) + 'px',
overflow: 'hidden' overflow: 'hidden'
}) })
.appendTo($left), .appendTo($left),
$reflectionIcon = $('<img>') $reflectionIcon = $('<img>')
.attr({ .attr({
src: pandora.getMediaURL('/' + data.id + '/' + ( src: pandora.getMediaURL('/' + data.id + '/' + (
ui.icons == 'posters' ? 'poster' : 'icon' ui.icons == 'posters' ? 'poster' : 'icon'
) + '512.jpg?' + data.modified) ) + '512.jpg?' + data.modified)
}) })
.css({ .css({
position: 'absolute', position: 'absolute',
left: iconLeft + 'px', left: iconLeft + 'px',
width: iconWidth + 'px', width: iconWidth + 'px',
height: iconHeight + 'px', height: iconHeight + 'px',
borderRadius: borderRadius + 'px' borderRadius: borderRadius + 'px'
}) })
.appendTo($reflection), .appendTo($reflection),
$reflectionGradient = $('<div>') $reflectionGradient = $('<div>')
.css({ .css({
position: 'absolute', position: 'absolute',
width: iconSize + 'px', width: iconSize + 'px',
height: Math.round(iconSize / 2) + 'px' height: Math.round(iconSize / 2) + 'px'
}) })
.appendTo($reflection), .appendTo($reflection);
}
$data = $('<div>') var $data = $('<div>')
.addClass('OxTextPage') .addClass('OxTextPage')
.css({ .css({
position: 'absolute', position: 'absolute',
@ -257,7 +263,7 @@ pandora.ui.infoView = function(data) {
editable: canEdit, editable: canEdit,
format: imageCSS, format: imageCSS,
maxHeight: Infinity, maxHeight: Infinity,
placeholder: formatLight(Ox._('No Summary')), placeholder: formatLight(Ox._( isMixed.summary ? 'Mixed Summary' : 'No Summary')),
tooltip: canEdit ? pandora.getEditTooltip() : '', tooltip: canEdit ? pandora.getEditTooltip() : '',
type: 'textarea', type: 'textarea',
value: data.summary || '' value: data.summary || ''
@ -344,48 +350,50 @@ pandora.ui.infoView = function(data) {
// Duration, Aspect Ratio -------------------------------------------------- // Duration, Aspect Ratio --------------------------------------------------
['duration', 'aspectratio'].forEach(function(key) { if (!isMultiple) {
var itemKey = Ox.getObjectById(pandora.site.itemKeys, key), ['duration', 'aspectratio'].forEach(function(key) {
value = data[key] || 0; var itemKey = Ox.getObjectById(pandora.site.itemKeys, key),
value = data[key] || 0;
$('<div>')
.css({marginBottom: '4px'})
.append(formatKey(itemKey.title, 'statistics'))
.append(
Ox.Theme.formatColor(null, 'gradient')
.css({textAlign: 'right'})
.html(
Ox['format' + Ox.toTitleCase(itemKey.format.type)]
.apply(null, [value].concat(itemKey.format.args))
)
)
.appendTo($statistics);
});
// Hue, Saturation, Lightness, Volume --------------------------------------
['hue', 'saturation', 'lightness', 'volume'].forEach(function(key) {
$('<div>')
.css({marginBottom: '4px'})
.append(formatKey(key, 'statistics'))
.append(
Ox.Theme.formatColor(
data[key] || 0, key == 'volume' ? 'lightness' : key
).css({textAlign: 'right'})
)
.appendTo($statistics);
});
// Cuts per Minute ---------------------------------------------------------
$('<div>') $('<div>')
.css({marginBottom: '4px'}) .css({marginBottom: '4px'})
.append(formatKey(itemKey.title, 'statistics')) .append(formatKey('cuts per minute', 'statistics'))
.append( .append(
Ox.Theme.formatColor(null, 'gradient') Ox.Theme.formatColor(null, 'gradient')
.css({textAlign: 'right'}) .css({textAlign: 'right'})
.html( .html(Ox.formatNumber(data['cutsperminute'] || 0, 3))
Ox['format' + Ox.toTitleCase(itemKey.format.type)]
.apply(null, [value].concat(itemKey.format.args))
)
) )
.appendTo($statistics); .appendTo($statistics);
}); }
// Hue, Saturation, Lightness, Volume --------------------------------------
['hue', 'saturation', 'lightness', 'volume'].forEach(function(key) {
$('<div>')
.css({marginBottom: '4px'})
.append(formatKey(key, 'statistics'))
.append(
Ox.Theme.formatColor(
data[key] || 0, key == 'volume' ? 'lightness' : key
).css({textAlign: 'right'})
)
.appendTo($statistics);
});
// Cuts per Minute ---------------------------------------------------------
$('<div>')
.css({marginBottom: '4px'})
.append(formatKey('cuts per minute', 'statistics'))
.append(
Ox.Theme.formatColor(null, 'gradient')
.css({textAlign: 'right'})
.html(Ox.formatNumber(data['cutsperminute'] || 0, 3))
)
.appendTo($statistics);
// Rights Level ------------------------------------------------------------ // Rights Level ------------------------------------------------------------
@ -498,7 +506,7 @@ pandora.ui.infoView = function(data) {
function editMetadata(key, value) { function editMetadata(key, value) {
if (value != data[key]) { if (value != data[key]) {
var edit = {id: data.id}; var edit = {id: isMultiple ? ui.listSelection : data.id};
if (key == 'title') { if (key == 'title') {
edit[key] = value; edit[key] = value;
} else if (listKeys.indexOf(key) >= 0) { } else if (listKeys.indexOf(key) >= 0) {
@ -507,32 +515,35 @@ pandora.ui.infoView = function(data) {
edit[key] = value ? value : null; edit[key] = value ? value : null;
} }
pandora.api.edit(edit, function(result) { pandora.api.edit(edit, function(result) {
var src; if (!isMultiple) {
data[key] = result.data[key]; var src;
descriptions[key] && descriptions[key].options({ data[key] = result.data[key];
value: result.data[key + 'description'] descriptions[key] && descriptions[key].options({
}); value: result.data[key + 'description']
Ox.Request.clearCache(); // fixme: too much? can change filter/list etc
if (result.data.id != data.id) {
pandora.UI.set({item: result.data.id});
pandora.$ui.browser.value(data.id, 'id', result.data.id);
}
pandora.updateItemContext();
pandora.$ui.browser.value(result.data.id, key, result.data[key]);
if (Ox.contains(posterKeys, key) && ui.icons == 'posters') {
src = pandora.getMediaURL('/' + data.id + '/poster512.jpg?' + Ox.uid());
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
}
pandora.$ui.itemTitle
.options({
title: '<b>' + result.data.title
+ (Ox.len(result.data.director)
? ' (' + result.data.director.join(', ') + ')'
: '')
+ (result.data.year ? ' ' + result.data.year : '') + '</b>'
}); });
//pandora.$ui.contentPanel.replaceElement(0, pandora.$ui.browser = pandora.ui.browser()); Ox.Request.clearCache(); // fixme: too much? can change filter/list etc
if (result.data.id != data.id) {
pandora.UI.set({item: result.data.id});
pandora.$ui.browser.value(data.id, 'id', result.data.id);
}
pandora.updateItemContext();
pandora.$ui.browser.value(result.data.id, key, result.data[key]);
if (Ox.contains(posterKeys, key) && ui.icons == 'posters') {
src = pandora.getMediaURL('/' + data.id + '/poster512.jpg?' + Ox.uid());
$icon.attr({src: src});
$reflectionIcon.attr({src: src});
}
pandora.$ui.itemTitle
.options({
title: '<b>' + result.data.title
+ (Ox.len(result.data.director)
? ' (' + result.data.director.join(', ') + ')'
: '')
+ (result.data.year ? ' ' + result.data.year : '') + '</b>'
});
//pandora.$ui.contentPanel.replaceElement(0, pandora.$ui.browser = pandora.ui.browser());
}
that.triggerEvent('change', Ox.extend({}, key, value));
}); });
} }
} }
@ -719,7 +730,7 @@ pandora.ui.infoView = function(data) {
format: function(value) { format: function(value) {
return formatValue(key, value); return formatValue(key, value);
}, },
placeholder: formatLight(Ox._('unknown')), placeholder: formatLight(Ox._( isMixed[key] ? 'mixed' : 'unknown')),
tooltip: canEdit ? pandora.getEditTooltip() : '', tooltip: canEdit ? pandora.getEditTooltip() : '',
value: getValue(key, data[key]) value: getValue(key, data[key])
}) })
@ -742,7 +753,7 @@ pandora.ui.infoView = function(data) {
if (canEdit) { if (canEdit) {
$rightsLevelSelect = Ox.Select({ $rightsLevelSelect = Ox.Select({
items: pandora.site.rightsLevels.map(function(rightsLevel, i) { items: pandora.site.rightsLevels.map(function(rightsLevel, i) {
return {id: i, title: Ox._(rightsLevel.name)}; return {id: i, title: rightsLevel.name};
}), }),
width: 128, width: 128,
value: data.rightslevel value: data.rightslevel
@ -761,8 +772,12 @@ pandora.ui.infoView = function(data) {
.css({background: $rightsLevelElement.css('background')}) .css({background: $rightsLevelElement.css('background')})
.data({OxColor: $rightsLevelElement.data('OxColor')}) .data({OxColor: $rightsLevelElement.data('OxColor')})
renderCapabilities(rightsLevel); renderCapabilities(rightsLevel);
pandora.api.edit({id: data.id, rightslevel: rightsLevel}, function(result) { var edit = {
// ... id: isMultiple ? ui.listSelection : data.id,
rightslevel: rightsLevel
};
pandora.api.edit(edit, function(result) {
that.triggerEvent('change', Ox.extend({}, 'rightslevel', rightsLevel));
}); });
} }
}) })