Add Book -> Book Section and Book Section -> Book to context menu (#2754)
This commit is contained in:
parent
4f52eb9be3
commit
333cf8cc2a
4 changed files with 65 additions and 0 deletions
|
@ -2198,6 +2198,12 @@
|
||||||
this._focusNextField(1);
|
this._focusNextField(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focusField(fieldName) {
|
||||||
|
let field = this.shadowRoot.querySelector(`[fieldname="${fieldName}"][ztabindex]`);
|
||||||
|
if (!field) return false;
|
||||||
|
return this._focusNextField(field.getAttribute('ztabindex'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Advance the field focus forward or backward
|
* Advance the field focus forward or backward
|
||||||
*
|
*
|
||||||
|
|
|
@ -1801,6 +1801,55 @@ var ZoteroPane = new function()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
this.duplicateAndConvertSelectedItem = async function () {
|
||||||
|
if (this.getSelectedItems().length != 1
|
||||||
|
|| !['book', 'bookSection'].includes(this.getSelectedItems()[0].itemType)) {
|
||||||
|
throw new Error('duplicateAndConvertSelectedItem requires a single book or bookSection to be selected');
|
||||||
|
}
|
||||||
|
|
||||||
|
let authorCreatorType = Zotero.CreatorTypes.getID('author');
|
||||||
|
let bookAuthorCreatorType = Zotero.CreatorTypes.getID('bookAuthor');
|
||||||
|
|
||||||
|
let original = this.getSelectedItems()[0];
|
||||||
|
let duplicate = await this.duplicateSelectedItem();
|
||||||
|
if (!duplicate) return null;
|
||||||
|
|
||||||
|
if (duplicate.itemType == 'book') {
|
||||||
|
duplicate.setType(Zotero.ItemTypes.getID('bookSection'));
|
||||||
|
for (let i = 0; i < duplicate.numCreators(); i++) {
|
||||||
|
let creator = duplicate.getCreator(i);
|
||||||
|
if (creator.creatorTypeID == authorCreatorType) {
|
||||||
|
creator.creatorTypeID = bookAuthorCreatorType;
|
||||||
|
}
|
||||||
|
duplicate.setCreator(i, creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
duplicate.setField('title', false); // So bookTitle becomes title
|
||||||
|
duplicate.setType(Zotero.ItemTypes.getID('book'));
|
||||||
|
// Get creators from the original item because setType() will have changed the types
|
||||||
|
let creators = original.getCreators()
|
||||||
|
// Remove authors of the individual book section
|
||||||
|
.filter(creator => creator.creatorTypeID !== authorCreatorType);
|
||||||
|
for (let creator of creators) {
|
||||||
|
if (creator.creatorTypeID == bookAuthorCreatorType) {
|
||||||
|
creator.creatorTypeID = authorCreatorType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
duplicate.setCreators(creators);
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate.addRelatedItem(original);
|
||||||
|
original.addRelatedItem(duplicate);
|
||||||
|
|
||||||
|
await original.saveTx({ skipDateModifiedUpdate: true });
|
||||||
|
await duplicate.saveTx();
|
||||||
|
|
||||||
|
document.getElementById('zotero-editpane-item-box').focusField('title');
|
||||||
|
return duplicate;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether every selected item can be deleted from the current
|
* Return whether every selected item can be deleted from the current
|
||||||
* collection context (library, trash, collection, etc.).
|
* collection context (library, trash, collection, etc.).
|
||||||
|
@ -3084,6 +3133,7 @@ var ZoteroPane = new function()
|
||||||
'toggleRead',
|
'toggleRead',
|
||||||
'addToCollection',
|
'addToCollection',
|
||||||
'removeItems',
|
'removeItems',
|
||||||
|
'duplicateAndConvert',
|
||||||
'duplicateItem',
|
'duplicateItem',
|
||||||
'restoreToLibrary',
|
'restoreToLibrary',
|
||||||
'moveToTrash',
|
'moveToTrash',
|
||||||
|
@ -3363,6 +3413,12 @@ var ZoteroPane = new function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!collectionTreeRow.isPublications()) {
|
else if (!collectionTreeRow.isPublications()) {
|
||||||
|
if (item.itemType == 'book' || item.itemType == 'bookSection') {
|
||||||
|
menu.childNodes[m.duplicateAndConvert].setAttribute('label', Zotero.getString('pane.items.menu.duplicateAndConvert.'
|
||||||
|
+ (item.itemType == 'book' ? 'toBookSection' : 'toBook')));
|
||||||
|
show.add(m.duplicateAndConvert);
|
||||||
|
}
|
||||||
|
|
||||||
show.add(m.duplicateItem);
|
show.add(m.duplicateItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -971,6 +971,7 @@
|
||||||
</menupopup>
|
</menupopup>
|
||||||
</menu>
|
</menu>
|
||||||
<menuitem class="menuitem-iconic zotero-menuitem-remove-items" oncommand="ZoteroPane_Local.deleteSelectedItems();"/>
|
<menuitem class="menuitem-iconic zotero-menuitem-remove-items" oncommand="ZoteroPane_Local.deleteSelectedItems();"/>
|
||||||
|
<menuitem class="menuitem-iconic zotero-menuitem-duplicate-and-convert" oncommand="ZoteroPane_Local.duplicateAndConvertSelectedItem();"/>
|
||||||
<menuitem class="menuitem-iconic zotero-menuitem-duplicate-item" label="&zotero.items.menu.duplicateItem;" oncommand="ZoteroPane_Local.duplicateSelectedItem().done();"/>
|
<menuitem class="menuitem-iconic zotero-menuitem-duplicate-item" label="&zotero.items.menu.duplicateItem;" oncommand="ZoteroPane_Local.duplicateSelectedItem().done();"/>
|
||||||
<menuitem class="menuitem-iconic zotero-menuitem-restore-to-library" label="&zotero.items.menu.restoreToLibrary;" oncommand="ZoteroPane_Local.restoreSelectedItems();"/>
|
<menuitem class="menuitem-iconic zotero-menuitem-restore-to-library" label="&zotero.items.menu.restoreToLibrary;" oncommand="ZoteroPane_Local.restoreSelectedItems();"/>
|
||||||
<menuitem class="menuitem-iconic zotero-menuitem-move-to-trash" oncommand="ZoteroPane_Local.deleteSelectedItems(true, true);"/>
|
<menuitem class="menuitem-iconic zotero-menuitem-move-to-trash" oncommand="ZoteroPane_Local.deleteSelectedItems(true, true);"/>
|
||||||
|
|
|
@ -359,6 +359,8 @@ pane.items.menu.createParent = Create Parent Item…
|
||||||
pane.items.menu.createParent.multiple = Create Parent Items
|
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.menu.duplicateAndConvert.toBookSection = Create Book Section
|
||||||
|
pane.items.menu.duplicateAndConvert.toBook = Create Book from Book Section
|
||||||
pane.items.showItemInLibrary = Show Item in Library
|
pane.items.showItemInLibrary = Show Item in Library
|
||||||
|
|
||||||
pane.items.letter.oneParticipant = Letter to %S
|
pane.items.letter.oneParticipant = Letter to %S
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue