Drop empty creators in ZU.itemToServerJSON() and fix debug comments

This commit is contained in:
Simon Kornblith 2012-01-09 13:22:59 -05:00
parent d93826af1b
commit 0a5ec165fb

View File

@ -1082,7 +1082,7 @@ Zotero.Utilities = {
var typeID = Zotero.ItemTypes.getID(item.itemType); var typeID = Zotero.ItemTypes.getID(item.itemType);
if(!typeID) { if(!typeID) {
Zotero.debug("Translate: Invalid itemType "+item.itemType+"; saving as webpage"); Zotero.debug("itemToServerJSON: Invalid itemType "+item.itemType+"; using webpage");
item.itemType = "webpage"; item.itemType = "webpage";
typeID = Zotero.ItemTypes.getID(item.itemType); typeID = Zotero.ItemTypes.getID(item.itemType);
} }
@ -1103,6 +1103,11 @@ Zotero.Utilities = {
for(var j=0; j<n; j++) { for(var j=0; j<n; j++) {
var creator = val[j]; var creator = val[j];
if(!creator.firstName && !creator.lastName) {
Zotero.debug("itemToServerJSON: Silently dropping empty creator");
continue;
}
// Single-field mode // Single-field mode
if (!creator.firstName || (creator.fieldMode && creator.fieldMode == 1)) { if (!creator.firstName || (creator.fieldMode && creator.fieldMode == 1)) {
var newCreator = { var newCreator = {
@ -1122,7 +1127,7 @@ Zotero.Utilities = {
if(Zotero.CreatorTypes.getID(creator.creatorType)) { if(Zotero.CreatorTypes.getID(creator.creatorType)) {
newCreator.creatorType = creator.creatorType; newCreator.creatorType = creator.creatorType;
} else { } else {
Zotero.debug("Translate: Invalid creator type "+creator.creatorType+"; falling back to author"); Zotero.debug("itemToServerJSON: Invalid creator type "+creator.creatorType+"; falling back to author");
} }
} }
if(!newCreator.creatorType) newCreator.creatorType = "author"; if(!newCreator.creatorType) newCreator.creatorType = "author";
@ -1141,7 +1146,7 @@ Zotero.Utilities = {
} else if(tag.name) { } else if(tag.name) {
tag = tag.name; tag = tag.name;
} else { } else {
Zotero.debug("Translate: Discarded invalid tag"); Zotero.debug("itemToServerJSON: Discarded invalid tag");
continue; continue;
} }
} }
@ -1155,7 +1160,7 @@ Zotero.Utilities = {
var note = val[j]; var note = val[j];
if(typeof note === "object") { if(typeof note === "object") {
if(!note.note) { if(!note.note) {
Zotero.debug("Translate: Discarded invalid note"); Zotero.debug("itemToServerJSON: Discarded invalid note");
continue; continue;
} }
note = note.note; note = note.note;
@ -1182,10 +1187,10 @@ Zotero.Utilities = {
if(Zotero.ItemFields.isValidForType(fieldID, typeID)) { if(Zotero.ItemFields.isValidForType(fieldID, typeID)) {
newItem[field] = val; newItem[field] = val;
} else { } else {
Zotero.debug("Translate: Discarded field "+field+": field not valid for type "+item.itemType, 3); Zotero.debug("itemToServerJSON: Discarded field "+field+": field not valid for type "+item.itemType, 3);
} }
} else { } else {
Zotero.debug("Translate: Discarded unknown field "+field, 3); Zotero.debug("itemToServerJSON: Discarded unknown field "+field, 3);
} }
} }