load editable in batch dialog

This commit is contained in:
j 2020-07-21 14:23:08 +02:00
parent 19da7ca26d
commit 953cb93745
3 changed files with 61 additions and 18 deletions

View File

@ -4,14 +4,12 @@ pandora.ui.editDialog = function() {
var ui = pandora.user.ui,
hasChanged = false,
ids = ui.listSelection.filter(function(id) {
return pandora.$ui.list.value(id, 'editable');
}),
keys = pandora.site.itemKeys.filter(function(key) {
ids = ui.listSelection,
keys = ['editable'].concat(pandora.site.itemKeys.filter(function(key) {
return key.id != '*'
}).map(function(key) {
return key.id
}),
})),
listKeys = pandora.site.itemKeys.filter(function(key) {
return Ox.isArray(key.type);
}).map(function(key){
@ -90,22 +88,46 @@ pandora.ui.editDialog = function() {
}, function(result) {
var data = {},
isMixed = {},
items = result.data.items;
keys.forEach(function(key) {
updateTitle = false,
items = result.data.items.filter(function(item) {
if (!item.editable) {
updateTitle = true
}
return item.editable;
});
if (updateTitle) {
that.options({
title: Ox._('Edit Metadata for {0}', [
Ox.formatNumber(items.length) + ' ' + Ox._(
items.length == 1 ? pandora.site.itemName.singular : pandora.site.itemName.plural
)
])
})
// no editable items
if (!items.length) {
that.close()
return
}
}
keys.filter(function(key) {
return key != 'editable'
}).forEach(function(key) {
var isArray = Ox.contains(listKeys, key),
values = items.map(function(item) {
return item[key];
});
if (isArray) {
values = values.map(function(value) {
return (value || []).join(separator);
value = value || []
return value.join ? value.join(separator) : value;
});
}
if (Ox.unique(values).length > 1) {
isMixed[key] = true;
}
data[key] = isMixed[key] ? null
: isArray ? values[0].split(separator)
: isArray && values.length ? values[0].split(separator)
: values[0];
});
that.options({

View File

@ -3,14 +3,12 @@
pandora.ui.editDocumentsDialog = function() {
var ui = pandora.user.ui,
hasChanged = false,
ids = ui.collectionSelection.filter(function(id) {
return pandora.$ui.list.value(id, 'editable');
}),
keys = pandora.site.documentKeys.filter(function(key) {
ids = ui.collectionSelection,
keys = ['editable'].concat(pandora.site.documentKeys.filter(function(key) {
return key.id != '*'
}).map(function(key) {
return key.id
}),
})),
listKeys = pandora.site.documentKeys.filter(function(key) {
return Ox.isArray(key.type);
}).map(function(key){
@ -89,8 +87,31 @@ pandora.ui.editDocumentsDialog = function() {
}, function(result) {
var data = {},
isMixed = {},
items = result.data.items;
keys.forEach(function(key) {
updateTitle = false,
items = result.data.items.filter(function(item) {
if (!item.editable) {
updateTitle = true
}
return item.editable;
});
if (updateTitle) {
that.options({
title: Ox._('Edit Metadata for {0}', [
Ox.formatNumber(items.length) + ' ' + Ox._(
items.length == 1 ? 'Document' : 'Documents'
)
])
})
// no editable items
if (!items.length) {
that.close()
return
}
}
keys.filter(function(key) {
return key != 'editable'
}).forEach(function(key) {
var isArray = Ox.contains(listKeys, key),
values = items.map(function(item) {
return item[key];

View File

@ -725,11 +725,11 @@ pandora.uploadDroppedFiles = function(files) {
pandora.enableBatchEdit = function(section) {
var ui = pandora.user.ui;
if (section == 'documents') {
return !ui.document && ui.collectionSelection.length > 1 && ui.collectionSelection.every(function(item) {
return !ui.document && ui.collectionSelection.length > 1 && ui.collectionSelection.some(function(item) {
return pandora.$ui.list && pandora.$ui.list.value(item, 'editable');
})
} else {
return !ui.item && ui.listSelection.length > 1 && ui.listSelection.every(function(item) {
return !ui.item && ui.listSelection.length > 1 && ui.listSelection.some(function(item) {
return pandora.$ui.list && pandora.$ui.list.value(item, 'editable');
})
}