From c81961a9bea629b4badbaf859ef3759e6be75d2a Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 16 Dec 2018 21:26:16 -0500 Subject: [PATCH] Move Z.Items.getFirstCreatorFromItemJSON() to Z.Utilities.Internal Needed for COinS export in translation-server --- chrome/content/zotero/xpcom/data/items.js | 26 +++--------------- chrome/content/zotero/xpcom/openurl.js | 2 +- .../zotero/xpcom/utilities_internal.js | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 5afa6a9f9f..217f08f373 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -1136,30 +1136,10 @@ Zotero.Items = function() { - /** - * Given API JSON for an item, return the best single first creator, regardless of creator order - * - * Note that this is just a single creator, not the firstCreator field return from the - * Zotero.Item::firstCreator property or this.getFirstCreatorFromData() - * - * @return {Object|false} - Creator in API JSON format, or false - */ this.getFirstCreatorFromJSON = function (json) { - var primaryCreatorType = Zotero.CreatorTypes.getName( - Zotero.CreatorTypes.getPrimaryIDForType( - Zotero.ItemTypes.getID(json.itemType) - ) - ); - let firstCreator = json.creators.find(creator => { - return creator.creatorType == primaryCreatorType || creator.creatorType == 'author'; - }); - if (!firstCreator) { - firstCreator = json.creators.find(creator => creator.creatorType == 'editor'); - } - if (!firstCreator) { - return false; - } - return firstCreator; + Zotero.warn("Zotero.Items.getFirstCreatorFromJSON() is deprecated " + + "-- use Zotero.Utilities.Internal.getFirstCreatorFromItemJSON()"; + return Zotero.Utilities.Internal.getFirstCreatorFromItemJSON(json); }; diff --git a/chrome/content/zotero/xpcom/openurl.js b/chrome/content/zotero/xpcom/openurl.js index a5c206f086..a96175ebba 100644 --- a/chrome/content/zotero/xpcom/openurl.js +++ b/chrome/content/zotero/xpcom/openurl.js @@ -205,7 +205,7 @@ Zotero.OpenURL = new function() { if(item.creators && item.creators.length) { // encode first author as first and last - let firstCreator = Zotero.Items.getFirstCreatorFromJSON(item); + let firstCreator = Zotero.Utilities.Internal.getFirstCreatorFromItemJSON(item); if(item.itemType == "patent") { _mapTag(firstCreator.firstName, "invfirst"); _mapTag(firstCreator.lastName, "invlast"); diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index fff3cd4aea..e6d2137205 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -871,6 +871,33 @@ Zotero.Utilities.Internal = { }, + /** + * Given API JSON for an item, return the best single first creator, regardless of creator order + * + * Note that this is just a single creator, not the firstCreator field return from the + * Zotero.Item::firstCreator property or Zotero.Items.getFirstCreatorFromData() + * + * @return {Object|false} - Creator in API JSON format, or false + */ + getFirstCreatorFromInternalJSON: function (json) { + var primaryCreatorType = Zotero.CreatorTypes.getName( + Zotero.CreatorTypes.getPrimaryIDForType( + Zotero.ItemTypes.getID(json.itemType) + ) + ); + let firstCreator = json.creators.find(creator => { + return creator.creatorType == primaryCreatorType || creator.creatorType == 'author'; + }); + if (!firstCreator) { + firstCreator = json.creators.find(creator => creator.creatorType == 'editor'); + } + if (!firstCreator) { + return false; + } + return firstCreator; + }, + + /** * Find valid fields in Extra field text *