diff --git a/static/js/editDialog.js b/static/js/editDialog.js index f35747c09..458cb9877 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 620cc1530..c5cdec12a 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 d4d0f610a..f5d9590fb 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'); }) }