Move Z.Items.getFirstCreatorFromItemJSON() to Z.Utilities.Internal

Needed for COinS export in translation-server
This commit is contained in:
Dan Stillman 2018-12-16 21:26:16 -05:00
parent f4bf918f35
commit c81961a9be
3 changed files with 31 additions and 24 deletions

View file

@ -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);
};

View file

@ -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");

View file

@ -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
*