commit e5268ba2f2cdbc99ddc69450fc8e3449098067cf
parent ad04e96ad43f59991653846952b5da203b480ba1
Author: Simon Kornblith <simon@simonster.com>
Date: Thu, 30 Jun 2011 03:36:00 +0000
Normalize tags on save
Diffstat:
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/connector/translate_item.js b/chrome/content/zotero/xpcom/connector/translate_item.js
@@ -81,8 +81,21 @@ Zotero.Translate.ItemSaver.prototype = {
// TODO normalize
newItem[field] = val;
} else if(field === "tags") {
- // TODO normalize
- newItem[field] = val;
+ var newTags = [];
+ for(var j in val) {
+ var tag = val[j];
+ if(typeof tag === "object") {
+ if(tag.tag) {
+ tag = tag.tag;
+ } else if(tag.name) {
+ tag = tag.name;
+ } else {
+ continue;
+ }
+ }
+ newTags.push({tag:tag.toString(), type:1})
+ }
+ newItem.tags = newTags;
} else if(field === "notes") {
// TODO normalize
newItem[field] = val;
@@ -116,12 +129,13 @@ Zotero.Translate.ItemSaver.prototype = {
}
var url = 'users/%%USERID%%/items?key=%%APIKEY%%';
- var payload = JSON.stringify({"items":newItems});
+ var payload = JSON.stringify({"items":newItems}, null, "\t")
this._itemsToSaveToServer = [];
Zotero.OAuth.doAuthenticatedPost(url, payload, function(status, message) {
if(!status) {
Zotero.Messaging.sendMessage("saveDialog_error", status);
+ Zotero.debug("Translate: Save to server payload:\n\n"+payload);
throw new Error("Translate: Save to server failed: "+message);
} else {
Zotero.debug("Translate: Save to server complete");