Merge pull request #1936 from fletcherhaz/multiple-parents

Add back in ability to create multiple empty parent items
This commit is contained in:
Dan Stillman 2020-12-23 23:19:37 -05:00 committed by GitHub
commit f8b15766a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 36 deletions

View file

@ -2820,13 +2820,25 @@ var ZoteroPane = new function()
&& items.some(item => item.isRegularItem())) { && items.some(item => item.isRegularItem())) {
show.push(m.findPDF, m.sep3); show.push(m.findPDF, m.sep3);
} }
let canCreateParent = true;
for (let i = 0; i < items.length; i++) {
let item = items[i];
if (!item.isTopLevelItem() || !item.isAttachment() || item.isFeedItem) {
canCreateParent = false;
break;
}
}
if (canCreateParent) {
show.push(m.createParent);
}
if (canRename) { if (canRename) {
show.push(m.renameAttachments); show.push(m.renameAttachments);
} }
// Add in attachment separator // Add in attachment separator
if (canRecognize || canUnrecognize || canRename || canIndex) { if (canCreateParent || canRecognize || canUnrecognize || canRename || canIndex) {
show.push(m.sep5); show.push(m.sep5);
} }
@ -2837,6 +2849,7 @@ var ZoteroPane = new function()
if (item.isFileAttachment()) { if (item.isFileAttachment()) {
disable.push( disable.push(
m.moveToTrash, m.moveToTrash,
m.createParent,
m.renameAttachments m.renameAttachments
); );
break; break;
@ -2985,7 +2998,7 @@ var ZoteroPane = new function()
menu.childNodes[m.exportItems].setAttribute('label', Zotero.getString('pane.items.menu.export' + multiple)); menu.childNodes[m.exportItems].setAttribute('label', Zotero.getString('pane.items.menu.export' + multiple));
menu.childNodes[m.createBib].setAttribute('label', Zotero.getString('pane.items.menu.createBib' + multiple)); menu.childNodes[m.createBib].setAttribute('label', Zotero.getString('pane.items.menu.createBib' + multiple));
menu.childNodes[m.loadReport].setAttribute('label', Zotero.getString('pane.items.menu.generateReport' + multiple)); menu.childNodes[m.loadReport].setAttribute('label', Zotero.getString('pane.items.menu.generateReport' + multiple));
menu.childNodes[m.createParent].setAttribute('label', Zotero.getString('pane.items.menu.createParent')); menu.childNodes[m.createParent].setAttribute('label', Zotero.getString('pane.items.menu.createParent' + multiple));
menu.childNodes[m.recognizePDF].setAttribute('label', Zotero.getString('pane.items.menu.recognizePDF' + multiple)); menu.childNodes[m.recognizePDF].setAttribute('label', Zotero.getString('pane.items.menu.recognizePDF' + multiple));
menu.childNodes[m.renameAttachments].setAttribute('label', Zotero.getString('pane.items.menu.renameAttachments' + multiple)); menu.childNodes[m.renameAttachments].setAttribute('label', Zotero.getString('pane.items.menu.renameAttachments' + multiple));
menu.childNodes[m.reindexItem].setAttribute('label', Zotero.getString('pane.items.menu.reindexItem' + multiple)); menu.childNodes[m.reindexItem].setAttribute('label', Zotero.getString('pane.items.menu.reindexItem' + multiple));
@ -4510,47 +4523,67 @@ var ZoteroPane = new function()
return; return;
} }
let item = this.getSelectedItems()[0]; let items = this.getSelectedItems();
if (!item.isAttachment() || !item.isTopLevelItem()) {
throw new Error('Item ' + itemID + ' is not a top-level attachment');
}
let io = { dataIn: { item }, dataOut: null }; if (items.length > 1) {
window.openDialog('chrome://zotero/content/createParentDialog.xul', '', 'chrome,modal,centerscreen', io); for (let i = 0; i < items.length; i++) {
if (!io.dataOut) { let item = items[i];
return false; if (!item.isTopLevelItem() || item.isRegularItem()) {
} throw new Error('Item ' + item.id + ' is not a top-level attachment');
}
// If we made a parent, attach the child await this.createEmptyParent(item);
if (io.dataOut.parent) { }
await Zotero.DB.executeTransaction(function* () {
item.parentID = io.dataOut.parent.id;
yield item.save();
});
} }
// If they clicked manual entry then make a dummy parent
else { else {
await Zotero.DB.executeTransaction(function* () { // Ask for an identifier if there is only one item
// TODO: remove once there are no top-level web attachments let item = items[0];
if (item.isWebAttachment()) { if (!item.isAttachment() || !item.isTopLevelItem()) {
var parent = new Zotero.Item('webpage'); throw new Error('Item ' + item.id + ' is not a top-level attachment');
} }
else {
var parent = new Zotero.Item('document'); let io = { dataIn: { item }, dataOut: null };
} window.openDialog('chrome://zotero/content/createParentDialog.xul', '', 'chrome,modal,centerscreen', io);
parent.libraryID = item.libraryID; if (!io.dataOut) {
parent.setField('title', item.getField('title')); return false;
if (item.isWebAttachment()) { }
parent.setField('accessDate', item.getField('accessDate'));
parent.setField('url', item.getField('url')); // If we made a parent, attach the child
} if (io.dataOut.parent) {
var itemID = yield parent.save(); await Zotero.DB.executeTransaction(async function () {
item.parentID = itemID; item.parentID = io.dataOut.parent.id;
yield item.save(); await item.save();
}); });
}
// If they clicked manual entry then make a dummy parent
else {
this.createEmptyParent(item);
}
} }
}; };
this.createEmptyParent = async function (item) {
await Zotero.DB.executeTransaction(async function () {
// TODO: remove once there are no top-level web attachments
if (item.isWebAttachment()) {
var parent = new Zotero.Item('webpage');
}
else {
var parent = new Zotero.Item('document');
}
parent.libraryID = item.libraryID;
parent.setField('title', item.getField('title'));
if (item.isWebAttachment()) {
parent.setField('accessDate', item.getField('accessDate'));
parent.setField('url', item.getField('url'));
}
let itemID = await parent.save();
item.parentID = itemID;
await item.save();
});
};
this.renameSelectedAttachmentsFromParents = Zotero.Promise.coroutine(function* () { this.renameSelectedAttachmentsFromParents = Zotero.Promise.coroutine(function* () {
// TEMP: fix // TEMP: fix

View file

@ -322,6 +322,7 @@ pane.items.menu.reindexItem.multiple = Reindex Items
pane.items.menu.recognizePDF = Retrieve Metadata for PDF pane.items.menu.recognizePDF = Retrieve Metadata for PDF
pane.items.menu.recognizePDF.multiple = Retrieve Metadata for PDFs pane.items.menu.recognizePDF.multiple = Retrieve Metadata for PDFs
pane.items.menu.createParent = Create Parent Item… pane.items.menu.createParent = Create Parent Item…
pane.items.menu.createParent.multiple = Create Parent Items
pane.items.menu.renameAttachments = Rename File from Parent Metadata pane.items.menu.renameAttachments = Rename File from Parent Metadata
pane.items.menu.renameAttachments.multiple = Rename Files from Parent Metadata pane.items.menu.renameAttachments.multiple = Rename Files from Parent Metadata
pane.items.showItemInLibrary = Show Item in Library pane.items.showItemInLibrary = Show Item in Library