From 1774962de92df30805b05b6babf8d236e6f2f4fc Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 4 Jul 2011 09:08:49 +0000 Subject: [PATCH] - Refactor Zotero.Translate save process. There are now itemSaving and itemDone handlers. The itemSaving handler is called as soon as the translator returns an item, but before it's saved to the database. The itemDone handler is called when the item is saved. This allows us to show a grayed-out item icon in the connector while the item is saving to server, and then un-gray it when it is saved to the server. - Move Zotero.randomString() to Zotero.Utilities - Fix import of collections (broken by recent commits) --- chrome/content/zotero/fileInterface.js | 2 +- .../zotero/xpcom/connector/translate_item.js | 55 ++++---- .../content/zotero/xpcom/server_connector.js | 20 ++- .../zotero/xpcom/translation/translate.js | 73 ++++++++-- .../xpcom/translation/translate_item.js | 129 +++++++++--------- chrome/content/zotero/xpcom/utilities.js | 18 +++ chrome/content/zotero/xpcom/zotero.js | 13 +- 7 files changed, 189 insertions(+), 121 deletions(-) diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index ae2975f975..d92d15c1fa 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -330,7 +330,7 @@ var Zotero_File_Interface = new function() { */ function _importDone(obj, worked) { // add items to import collection - _importCollection.addItems(obj.newItems); + _importCollection.addItems([item.id for each(item in obj.newItems)]); Zotero.DB.commitTransaction(); diff --git a/chrome/content/zotero/xpcom/connector/translate_item.js b/chrome/content/zotero/xpcom/connector/translate_item.js index c3ad2a9b71..3842d8e148 100644 --- a/chrome/content/zotero/xpcom/connector/translate_item.js +++ b/chrome/content/zotero/xpcom/connector/translate_item.js @@ -26,7 +26,6 @@ Zotero.Translate.ItemSaver = function(libraryID, attachmentMode, forceTagType) { this.newItems = []; - this._itemsToSaveToServer = []; this._timeoutID = null; } @@ -35,37 +34,46 @@ Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD = 1; Zotero.Translate.ItemSaver.ATTACHMENT_MODE_FILE = 2; Zotero.Translate.ItemSaver.prototype = { - "saveItem":function(item) { + /** + * Saves items to Standalone or the server + */ + "saveItems":function(items, callback) { // don't save documents as documents, since we can't pass them around - for(var i in item.attachments) { - if(item.attachments[i].document) { - item.attachments[i].url = item.attachments[i].document.location.href; - delete item.attachments[i].document; + var nItems = items.length; + for(var i=0; i= 2) { * Generate a random string of length 'len' (defaults to 8) **/ function randomString(len, chars) { - if (!chars) { - chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; - } - if (!len) { - len = 8; - } - var randomstring = ''; - for (var i=0; i