From 2f2c8645cc772beec0de727bbc699797a941092d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 27 May 2008 06:30:31 +0000 Subject: [PATCH] Convert between primary creator types when switching item types instead of reverting to "Contributor" if the current creator type isn't valid. --- chrome/content/zotero/xpcom/data_access.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index b37b5a037..ab690a1e7 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -248,9 +248,21 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) { for (var i in creators){ if (!Zotero.CreatorTypes.isValidForItemType(creators[i].creatorTypeID, itemTypeID)) { + // Convert existing primary creator type to new item type's + // primary creator type, or contributor (creatorTypeID 2) + // if none or not currently primary + var oldPrimary = Zotero.CreatorTypes.getPrimaryIDForType(this.getType()); + Zotero.debug('old primary was ' + oldPrimary); + Zotero.debug('old type was ' + creators[i].creatorTypeID); + if (oldPrimary == creators[i].creatorTypeID) { + var newPrimary = Zotero.CreatorTypes.getPrimaryIDForType(itemTypeID); + Zotero.debug('new primary is ' + newPrimary); + } + var target = newPrimary ? newPrimary : 2; + // Reset to contributor (creatorTypeID 2), which exists in all this.setCreator(i, creators[i].firstName, - creators[i].lastName, 2, creators[i].fieldMode); + creators[i].lastName, target, creators[i].fieldMode); } } }