Merge pull request #1936 from fletcherhaz/multiple-parents
Add back in ability to create multiple empty parent items
This commit is contained in:
commit
f8b15766a6
2 changed files with 70 additions and 36 deletions
|
@ -2821,12 +2821,24 @@ var ZoteroPane = new function()
|
|||
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) {
|
||||
show.push(m.renameAttachments);
|
||||
}
|
||||
|
||||
// Add in attachment separator
|
||||
if (canRecognize || canUnrecognize || canRename || canIndex) {
|
||||
if (canCreateParent || canRecognize || canUnrecognize || canRename || canIndex) {
|
||||
show.push(m.sep5);
|
||||
}
|
||||
|
||||
|
@ -2837,6 +2849,7 @@ var ZoteroPane = new function()
|
|||
if (item.isFileAttachment()) {
|
||||
disable.push(
|
||||
m.moveToTrash,
|
||||
m.createParent,
|
||||
m.renameAttachments
|
||||
);
|
||||
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.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.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.renameAttachments].setAttribute('label', Zotero.getString('pane.items.menu.renameAttachments' + multiple));
|
||||
menu.childNodes[m.reindexItem].setAttribute('label', Zotero.getString('pane.items.menu.reindexItem' + multiple));
|
||||
|
@ -4510,9 +4523,23 @@ var ZoteroPane = new function()
|
|||
return;
|
||||
}
|
||||
|
||||
let item = this.getSelectedItems()[0];
|
||||
let items = this.getSelectedItems();
|
||||
|
||||
if (items.length > 1) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
let item = items[i];
|
||||
if (!item.isTopLevelItem() || item.isRegularItem()) {
|
||||
throw new Error('Item ' + item.id + ' is not a top-level attachment');
|
||||
}
|
||||
|
||||
await this.createEmptyParent(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Ask for an identifier if there is only one item
|
||||
let item = items[0];
|
||||
if (!item.isAttachment() || !item.isTopLevelItem()) {
|
||||
throw new Error('Item ' + itemID + ' is not a top-level attachment');
|
||||
throw new Error('Item ' + item.id + ' is not a top-level attachment');
|
||||
}
|
||||
|
||||
let io = { dataIn: { item }, dataOut: null };
|
||||
|
@ -4523,14 +4550,21 @@ var ZoteroPane = new function()
|
|||
|
||||
// If we made a parent, attach the child
|
||||
if (io.dataOut.parent) {
|
||||
await Zotero.DB.executeTransaction(function* () {
|
||||
await Zotero.DB.executeTransaction(async function () {
|
||||
item.parentID = io.dataOut.parent.id;
|
||||
yield item.save();
|
||||
await item.save();
|
||||
});
|
||||
}
|
||||
// If they clicked manual entry then make a dummy parent
|
||||
else {
|
||||
await Zotero.DB.executeTransaction(function* () {
|
||||
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');
|
||||
|
@ -4544,11 +4578,10 @@ var ZoteroPane = new function()
|
|||
parent.setField('accessDate', item.getField('accessDate'));
|
||||
parent.setField('url', item.getField('url'));
|
||||
}
|
||||
var itemID = yield parent.save();
|
||||
let itemID = await parent.save();
|
||||
item.parentID = itemID;
|
||||
yield item.save();
|
||||
await item.save();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -322,6 +322,7 @@ pane.items.menu.reindexItem.multiple = Reindex Items
|
|||
pane.items.menu.recognizePDF = Retrieve Metadata for PDF
|
||||
pane.items.menu.recognizePDF.multiple = Retrieve Metadata for PDFs
|
||||
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.multiple = Rename Files from Parent Metadata
|
||||
pane.items.showItemInLibrary = Show Item in Library
|
||||
|
|
Loading…
Reference in a new issue