From 953cb93745c25d888950a6674c7455835246dc9a Mon Sep 17 00:00:00 2001 From: j Date: Tue, 21 Jul 2020 14:23:08 +0200 Subject: [PATCH] load editable in batch dialog --- static/js/editDialog.js | 40 +++++++++++++++++++++++++------- static/js/editDocumentsDialog.js | 35 ++++++++++++++++++++++------ static/js/utils.js | 4 ++-- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/static/js/editDialog.js b/static/js/editDialog.js index f35747c0..458cb987 100644 --- a/static/js/editDialog.js +++ b/static/js/editDialog.js @@ -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({ diff --git a/static/js/editDocumentsDialog.js b/static/js/editDocumentsDialog.js index 620cc153..c5cdec12 100644 --- a/static/js/editDocumentsDialog.js +++ b/static/js/editDocumentsDialog.js @@ -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]; diff --git a/static/js/utils.js b/static/js/utils.js index d4d0f610..f5d9590f 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -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'); }) }