diff --git a/chrome/content/zotero/xpcom/connector/cachedTypes.js b/chrome/content/zotero/xpcom/connector/cachedTypes.js index bf3ebd442..28469f469 100644 --- a/chrome/content/zotero/xpcom/connector/cachedTypes.js +++ b/chrome/content/zotero/xpcom/connector/cachedTypes.js @@ -44,10 +44,128 @@ Zotero.Connector_Types = new function() { this[schemaType] = Zotero.Utilities.deepCopy(Zotero.Connector_Types.schema[schemaType]); for(var id in Zotero.Connector_Types.schema[schemaType]) { var entry = this[schemaType][id]; - entry.id = parseInt(id); - this[schemaType][entry.name] = entry; + entry.unshift(parseInt(id, 10)); + this[schemaType][entry[1]/* name */] = entry; } } + + var itemTypes = Zotero.Connector_Types["itemTypes"]; + var creatorTypes = Zotero.Connector_Types["creatorTypes"]; + var fields = Zotero.Connector_Types["fields"]; + + Zotero.CachedTypes = function() { + var thisType = Zotero.Connector_Types[this.schemaType]; + + this.getID = function(idOrName) { + var type = thisType[idOrName]; + return (type ? type[0]/* id */ : false); + }; + + this.getName = function(idOrName) { + var type = thisType[idOrName]; + return (type ? type[1]/* name */ : false); + }; + + this.getLocalizedString = function(idOrName) { + var type = thisType[idOrName]; + return (type ? type[2]/* localizedString */ : false); + }; + } + + Zotero.ItemTypes = new function() { + this.schemaType = "itemTypes"; + Zotero.CachedTypes.call(this); + + this.getImageSrc = function(idOrName) { + var itemType = Zotero.Connector_Types["itemTypes"][idOrName]; + if(!itemType) return false; + var icon = itemType[6]/* icon */; + + if(Zotero.isBookmarklet) { + return ZOTERO_CONFIG.BOOKMARKLET_URL+"icons/"+icon; + } else if(Zotero.isFx) { + return "chrome://zotero/skin/"+icon; + } else if(Zotero.isChrome) { + return chrome.extension.getURL("images/"+icon); + } else if(Zotero.isSafari) { + return safari.extension.baseURI+"images/itemTypes/"+icon; + } + }; + } + + Zotero.CreatorTypes = new function() { + this.schemaType = "creatorTypes"; + Zotero.CachedTypes.call(this); + + this.getTypesForItemType = function(idOrName) { + var itemType = itemTypes[idOrName]; + if(!itemType) return false; + + var itemCreatorTypes = itemType[3]/* creatorTypes */, + n = itemCreatorTypes.length, + outputTypes = new Array(n); + + for(var i=0; i