merge batch editing support

This commit is contained in:
j 2019-11-15 15:10:35 +01:00
parent b9b5f00618
commit b95774c309

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,11 @@ 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) {
@ -97,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'
@ -107,9 +110,10 @@ pandora.ui.infoView = function(data) {
.css({ .css({
position: 'absolute' position: 'absolute'
}) })
.appendTo($info), .appendTo($info);
$icon = Ox.Element({ if (!isMultiple) {
var $icon = Ox.Element({
element: '<img>', element: '<img>',
tooltip: 'Switch to ' + Ox.getObjectById( tooltip: 'Switch to ' + Ox.getObjectById(
pandora.site.itemViews, pandora.site.itemViews,
@ -172,7 +176,8 @@ pandora.ui.infoView = function(data) {
}) })
.appendTo($reflection), .appendTo($reflection),
$data = $('<div>') }
var $data = $('<div>')
.addClass('OxTextPage') .addClass('OxTextPage')
.css({ .css({
position: 'absolute', position: 'absolute',
@ -180,7 +185,7 @@ pandora.ui.infoView = function(data) {
top: margin + iconHeight + margin + 'px', top: margin + iconHeight + margin + 'px',
width: iconSize + 'px', width: iconSize + 'px',
}) })
.appendTo($left), .appendTo($left)
$text = Ox.Element() $text = Ox.Element()
.addClass('OxTextPage') .addClass('OxTextPage')
@ -336,7 +341,7 @@ pandora.ui.infoView = function(data) {
); );
}, },
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 || ''
@ -367,7 +372,7 @@ pandora.ui.infoView = function(data) {
.appendTo($text); .appendTo($text);
// Duration, Aspect Ratio -------------------------------------------------- // Duration, Aspect Ratio --------------------------------------------------
if (!isMultiple) {
['duration', 'aspectratio'].forEach(function(key) { ['duration', 'aspectratio'].forEach(function(key) {
var itemKey = Ox.getObjectById(pandora.site.itemKeys, key), var itemKey = Ox.getObjectById(pandora.site.itemKeys, key),
value = data[key] || 0; value = data[key] || 0;
@ -410,6 +415,7 @@ pandora.ui.infoView = function(data) {
.html(Ox.formatNumber(data['cutsperminute'] || 0, 3)) .html(Ox.formatNumber(data['cutsperminute'] || 0, 3))
) )
.appendTo($statistics); .appendTo($statistics);
}
// Rights Level ------------------------------------------------------------ // Rights Level ------------------------------------------------------------
@ -479,7 +485,7 @@ pandora.ui.infoView = function(data) {
.append( .append(
Ox.EditableContent({ Ox.EditableContent({
height: 128, height: 128,
placeholder: formatLight(Ox._('No notes')), placeholder: formatLight(Ox._(isMixed ? 'Mixed notes' : 'No notes')),
tooltip: pandora.getEditTooltip(), tooltip: pandora.getEditTooltip(),
type: 'textarea', type: 'textarea',
value: data.notes || '', value: data.notes || '',
@ -498,7 +504,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,6 +513,7 @@ 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) {
if (!isMultiple) {
data[key] = result.data[key]; data[key] = result.data[key];
descriptions[key] && descriptions[key].options({ descriptions[key] && descriptions[key].options({
value: result.data[key + 'description'] value: result.data[key + 'description']
@ -527,6 +534,7 @@ pandora.ui.infoView = function(data) {
+ (result.data.year ? ' ' + result.data.year : '') + '</b>' + (result.data.year ? ' ' + result.data.year : '') + '</b>'
}); });
//pandora.$ui.contentPanel.replaceElement(0, pandora.$ui.browser = pandora.ui.browser()); //pandora.$ui.contentPanel.replaceElement(0, pandora.$ui.browser = pandora.ui.browser());
}
}); });
} }
} }
@ -687,7 +695,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])
}) })
@ -729,8 +737,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));
}); });
} }
}) })