From 221d1da34030992810e83021e394f3450f0f0894 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sat, 2 Jun 2012 16:58:14 -0400 Subject: [PATCH 1/8] Attachment progress notifications. These are already hooked up to the UI in the connector, but still need to be hooked up to the UI in Firefox. Addresses #3 --- chrome/content/zotero/browser.js | 8 +- chrome/content/zotero/xpcom/attachments.js | 15 ++-- .../zotero/xpcom/connector/translate_item.js | 72 +++++++++++++++- .../content/zotero/xpcom/server_connector.js | 71 +++++++++++++-- .../xpcom/translation/translate_item.js | 86 +++++++++++++++---- 5 files changed, 218 insertions(+), 34 deletions(-) diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index e02fcfe1a..c6673064d 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -551,9 +551,9 @@ var Zotero_Browser = new function() { function _constructLookupFunction(tab, success) { return function(e) { tab.page.translate.setTranslator(tab.page.translators[0]); - tab.page.translate.clearHandlers("done"); + tab.page.translate.clearHandlers("itemsDone"); tab.page.translate.clearHandlers("itemDone"); - tab.page.translate.setHandler("done", function(obj, status) { + tab.page.translate.setHandler("itemsDone", function(obj, status) { if(status) { success(e, obj); Zotero_Browser.progress.close(); @@ -730,10 +730,10 @@ Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID, trans // use first translator available this.page.translate.setTranslator(translator ? translator : this.page.translators[0]); - this.page.translate.clearHandlers("done"); + this.page.translate.clearHandlers("itemsDone"); this.page.translate.clearHandlers("itemDone"); - this.page.translate.setHandler("done", function(obj, item) { Zotero_Browser.finishScraping(obj, item) }); + this.page.translate.setHandler("itemsDone", function(obj, item) { Zotero_Browser.finishScraping(obj, item) }); this.page.translate.setHandler("itemDone", function(obj, dbItem, item) { Zotero_Browser.itemDone(obj, dbItem, item, collection) }); this.page.translate.translate(libraryID); diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 7722b889b..17ce185f8 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -220,6 +220,7 @@ Zotero.Attachments = new function(){ var urlRe = /^https?:\/\/[^\s]*$/; var matches = urlRe.exec(url); if (!matches) { + callback(false); throw ("Invalid URL '" + url + "' in Zotero.Attachments.importFromURL()"); } @@ -297,9 +298,11 @@ Zotero.Attachments = new function(){ if (mimeType == 'application/pdf' && Zotero.MIME.sniffForMIMEType(str) != 'application/pdf') { - Zotero.debug("Downloaded PDF did not have MIME type " - + "'application/pdf' in Attachments.importFromURL()", 2); + var errString = "Downloaded PDF did not have MIME type " + + "'application/pdf' in Attachments.importFromURL()"; + Zotero.debug(errString, 2); attachmentItem.erase(); + callback(false, new Error(errString)); return; } @@ -311,6 +314,8 @@ Zotero.Attachments = new function(){ Zotero.Notifier.trigger('add', 'item', itemID); Zotero.Notifier.trigger('modify', 'item', sourceItemID); + + if(callback) callback(attachmentItem); // We don't have any way of knowing that the file // is flushed to disk, so we just wait a second @@ -325,6 +330,7 @@ Zotero.Attachments = new function(){ catch (e) { // Clean up attachmentItem.erase(); + callback(false, e); throw (e); } @@ -346,8 +352,6 @@ Zotero.Attachments = new function(){ nsIURL.spec = url; wbp.saveURI(nsIURL, null, null, null, null, file); - if(callback) callback(attachmentItem); - return attachmentItem; } catch (e){ @@ -553,7 +557,7 @@ Zotero.Attachments = new function(){ Zotero.Fulltext.indexDocument(document, itemID); Zotero.Notifier.trigger('refresh', 'item', itemID); if (callback) { - callback(); + callback(attachmentItem); } }; } @@ -612,6 +616,7 @@ Zotero.Attachments = new function(){ // Clean up var item = Zotero.Items.get(itemID); item.erase(); + callback(false, e); throw (e); } diff --git a/chrome/content/zotero/xpcom/connector/translate_item.js b/chrome/content/zotero/xpcom/connector/translate_item.js index e0dbcd74a..6b86351c2 100644 --- a/chrome/content/zotero/xpcom/connector/translate_item.js +++ b/chrome/content/zotero/xpcom/connector/translate_item.js @@ -79,10 +79,23 @@ Zotero.Translate.ItemSaver.prototype = { payload.cookie = this._cookie; } - Zotero.Connector.callMethod("saveItems", payload, function(success, status) { - if(success !== false) { + Zotero.Connector.callMethod("saveItems", payload, function(data, status) { + if(data !== false) { Zotero.debug("Translate: Save via Standalone succeeded"); + var haveAttachments = false; + if(data.items) { + for(var i=0; i Date: Sat, 2 Jun 2012 17:05:23 -0400 Subject: [PATCH 2/8] Don't cause problems if no callback passed to Zotero.Attachments methods --- chrome/content/zotero/xpcom/attachments.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 17ce185f8..d29d29b23 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -220,7 +220,7 @@ Zotero.Attachments = new function(){ var urlRe = /^https?:\/\/[^\s]*$/; var matches = urlRe.exec(url); if (!matches) { - callback(false); + if(callback) callback(false); throw ("Invalid URL '" + url + "' in Zotero.Attachments.importFromURL()"); } @@ -302,7 +302,7 @@ Zotero.Attachments = new function(){ + "'application/pdf' in Attachments.importFromURL()"; Zotero.debug(errString, 2); attachmentItem.erase(); - callback(false, new Error(errString)); + if(callback) callback(false, new Error(errString)); return; } @@ -330,7 +330,7 @@ Zotero.Attachments = new function(){ catch (e) { // Clean up attachmentItem.erase(); - callback(false, e); + if(callback) callback(false, e); throw (e); } @@ -616,7 +616,7 @@ Zotero.Attachments = new function(){ // Clean up var item = Zotero.Items.get(itemID); item.erase(); - callback(false, e); + if(callback) callback(false, e); throw (e); } From a750203f4fa3a9ade79cc57dde9d96e7f147c899 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sat, 9 Jun 2012 14:01:02 -0400 Subject: [PATCH 3/8] Hook up attachment progress notifications in Firefox UI, and simplify a lot of old code. Closes #3 --- chrome/content/zotero/browser.js | 104 +++--- .../zotero/xpcom/connector/translate_item.js | 74 +---- chrome/content/zotero/xpcom/progressWindow.js | 296 +++++++++++------- .../content/zotero/xpcom/server_connector.js | 19 +- .../zotero/xpcom/translation/translate.js | 141 ++++----- .../xpcom/translation/translate_item.js | 2 - chrome/content/zotero/xpcom/utilities.js | 11 + chrome/skin/default/zotero/zotero.css | 4 +- 8 files changed, 332 insertions(+), 319 deletions(-) diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index c6673064d..6627012fb 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -50,8 +50,6 @@ var Zotero_Browser = new function() { this.tabClose = tabClose; this.resize = resize; this.updateStatus = updateStatus; - this.finishScraping = finishScraping; - this.itemDone = itemDone; this.tabbrowser = null; this.appcontent = null; @@ -447,51 +445,6 @@ var Zotero_Browser = new function() { } } - /* - * Callback to be executed when scraping is complete - */ - function finishScraping(obj, returnValue) { - if(!returnValue) { - Zotero_Browser.progress.show(); - Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError")); - // Include link to Known Translator Issues page - var url = "http://www.zotero.org/documentation/known_translator_issues"; - var linkText = '' - + Zotero.getString('ingester.scrapeErrorDescription.linkText') + ''; - Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText)); - Zotero_Browser.progress.startCloseTimer(8000); - } else { - Zotero_Browser.progress.startCloseTimer(); - } - Zotero_Browser.isScraping = false; - } - - - /* - * Callback to be executed when an item has been finished - */ - function itemDone(obj, dbItem, item, collection) { - var title = item.title; - var icon = Zotero.ItemTypes.getImageSrc(item.itemType); - Zotero_Browser.progress.show(); - Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scraping")); - Zotero_Browser.progress.addLines([title], [icon]); - - // add item to collection, if one was specified - if(collection) { - collection.addItem(dbItem.id); - } - - if(Zotero_Browser.isScraping) { - // initialize close timer between item saves in case translator doesn't call done - Zotero_Browser.progress.startCloseTimer(10000); // is this long enough? - } else { - // if we aren't supposed to be scraping now, the translator is broken; assume we're - // done - Zotero_Browser.progress.startCloseTimer(); - } - } - /** * Called when status bar icon is right-clicked */ @@ -551,9 +504,9 @@ var Zotero_Browser = new function() { function _constructLookupFunction(tab, success) { return function(e) { tab.page.translate.setTranslator(tab.page.translators[0]); - tab.page.translate.clearHandlers("itemsDone"); + tab.page.translate.clearHandlers("done"); tab.page.translate.clearHandlers("itemDone"); - tab.page.translate.setHandler("itemsDone", function(obj, status) { + tab.page.translate.setHandler("done", function(obj, status) { if(status) { success(e, obj); Zotero_Browser.progress.close(); @@ -716,6 +669,7 @@ Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) { Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID, translator) { if(this.page.translators && this.page.translators.length) { Zotero_Browser.progress.show(); + Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scraping")); Zotero_Browser.isScraping = true; if(collectionID) { @@ -730,11 +684,57 @@ Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID, trans // use first translator available this.page.translate.setTranslator(translator ? translator : this.page.translators[0]); - this.page.translate.clearHandlers("itemsDone"); + this.page.translate.clearHandlers("done"); this.page.translate.clearHandlers("itemDone"); - this.page.translate.setHandler("itemsDone", function(obj, item) { Zotero_Browser.finishScraping(obj, item) }); - this.page.translate.setHandler("itemDone", function(obj, dbItem, item) { Zotero_Browser.itemDone(obj, dbItem, item, collection) }); + this.page.translate.setHandler("done", function(obj, returnValue) { + if(!returnValue) { + Zotero_Browser.progress.show(); + Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError")); + // Include link to Known Translator Issues page + var url = "http://www.zotero.org/documentation/known_translator_issues"; + var linkText = '' + + Zotero.getString('ingester.scrapeErrorDescription.linkText') + ''; + Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText)); + Zotero_Browser.progress.startCloseTimer(8000); + } else { + Zotero_Browser.progress.startCloseTimer(); + } + Zotero_Browser.isScraping = false; + }); + + var attachmentsMap = new WeakMap(); + + this.page.translate.setHandler("itemDone", function(obj, dbItem, item) { + Zotero_Browser.progress.show(); + var itemProgress = new Zotero_Browser.progress.ItemProgress(Zotero.ItemTypes.getImageSrc(item.itemType), + item.title); + itemProgress.setProgress(100); + for(var i=0; i elements are turned into XUL links */ - function addDescription(text) { - if(_windowLoaded) { - var newHB = _progressWindow.document.createElement("hbox"); - newHB.setAttribute("class", "zotero-progress-item-hbox"); - var newDescription = _progressWindow.document.createElement("description"); - - var parts = Zotero.Utilities.parseMarkup(text); - for each(var part in parts) { - if (part.type == 'text') { - var elem = _progressWindow.document.createTextNode(part.text); + this.addDescription = _deferUntilWindowLoad(function addDescription(text) { + var newHB = _progressWindow.document.createElement("hbox"); + newHB.setAttribute("class", "zotero-progress-item-hbox"); + var newDescription = _progressWindow.document.createElement("description"); + + var parts = Zotero.Utilities.parseMarkup(text); + for each(var part in parts) { + if (part.type == 'text') { + var elem = _progressWindow.document.createTextNode(part.text); + } + else if (part.type == 'link') { + var elem = _progressWindow.document.createElement('label'); + elem.setAttribute('value', part.text); + elem.setAttribute('class', 'zotero-text-link'); + for (var i in part.attributes) { + elem.setAttribute(i, part.attributes[i]); } - else if (part.type == 'link') { - var elem = _progressWindow.document.createElement('label'); - elem.setAttribute('value', part.text); - elem.setAttribute('class', 'zotero-text-link'); - for (var i in part.attributes) { - elem.setAttribute(i, part.attributes[i]); - } - } - - newDescription.appendChild(elem); } - newHB.appendChild(newDescription); - _progressWindow.document.getElementById("zotero-progress-text-box").appendChild(newHB); - - _move(); - } else { - _loadDescription = text; + newDescription.appendChild(elem); } - } + + newHB.appendChild(newDescription); + _progressWindow.document.getElementById("zotero-progress-text-box").appendChild(newHB); + + _move(); + }); - - function startCloseTimer(ms, requireMouseOver) { + /** + * Sets a timer to close the progress window. If a previous close timer was set, + * clears it. + * @param {Integer} ms The number of milliseconds to wait before closing the progress + * window. + * @param {Boolean} [requireMouseOver] If true, wait until the mouse has touched the + * window before closing. + */ + this.startCloseTimer = function startCloseTimer(ms, requireMouseOver) { if (_windowLoaded || _windowLoading) { if (requireMouseOver && !_mouseWasOver) { return; @@ -261,10 +230,14 @@ Zotero.ProgressWindow = function(_window){ } _timeoutID = _progressWindow.setTimeout(_timeout, ms); + _closing = true; } } - function close() { + /** + * Immediately closes the progress window if it is open. + */ + this.close = function close() { _disableTimeout(); _windowLoaded = false; _windowLoading = false; @@ -275,23 +248,102 @@ Zotero.ProgressWindow = function(_window){ } catch(ex) {} } + /** + * Creates a new object representing a line in the progressWindow. This is the OO + * version of addLines() above. + */ + this.ItemProgress = _deferUntilWindowLoad(function(iconSrc, title, parentItemProgress) { + this._itemText = _progressWindow.document.createElement("description"); + this._itemText.appendChild(_progressWindow.document.createTextNode(title)); + this._itemText.setAttribute("class", "zotero-progress-item-label"); + this._itemText.setAttribute("crop", "end"); + + this._image = _progressWindow.document.createElement("hbox"); + this._image.setAttribute("class", "zotero-progress-item-icon"); + this._image.setAttribute("flex", 0); + this._image.style.width = "16px"; + this._image.style.backgroundRepeat = "no-repeat"; + this.setIcon(iconSrc); + + this._hbox = _progressWindow.document.createElement("hbox"); + this._hbox.setAttribute("class", "zotero-progress-item-hbox"); + if(parentItemProgress) { + this._hbox.style.marginLeft = "16px"; + this._hbox.zoteroIsChildItem; + } + this._hbox.style.opacity = "0.5"; + + this._hbox.appendChild(this._image); + this._hbox.appendChild(this._itemText); + + var container = _progressWindow.document.getElementById("zotero-progress-text-box"); + if(parentItemProgress) { + var nextItem = parentItemProgress._hbox.nextSibling; + while(nextItem && nextItem.zoteroIsChildItem) { + nextItem = nextItem.nextSibling; + } + container.insertBefore(this._hbox, nextItem); + } else { + container.appendChild(this._hbox); + } + + _move(); + }); + + /** + * Sets the current save progress for this item. + * @param {Integer} percent A percentage from 0 to 100. + */ + this.ItemProgress.prototype.setProgress = _deferUntilWindowLoad(function(percent) { + if(percent != 0 && percent != 100) { + // Indication of partial progress, so we will use the circular indicator + this._image.style.backgroundImage = "url('chrome://zotero/skin/progress_arcs.png')"; + this._image.style.backgroundPosition = "-"+(Math.round(percent/100*nArcs)*16)+"px 0"; + this._hbox.style.opacity = percent/200+.5; + this._hbox.style.filter = "alpha(opacity = "+(percent/2+50)+")"; + } else if(percent == 100) { + this._image.style.backgroundImage = "url('"+this._iconSrc+"')"; + this._image.style.backgroundPosition = ""; + this._hbox.style.opacity = "1"; + this._hbox.style.filter = ""; + } + }); + + /** + * Sets the icon for this item. + * @param {Integer} percent A percentage from 0 to 100. + */ + this.ItemProgress.prototype.setIcon = _deferUntilWindowLoad(function(iconSrc) { + this._image.style.backgroundImage = "url('"+iconSrc+"')"; + this._image.style.backgroundPosition = ""; + this._iconSrc = iconSrc; + }); + + /** + * Indicates that an error occurred saving this item. + */ + this.ItemProgress.prototype.setError = _deferUntilWindowLoad(function() { + this._image.style.backgroundImage = "url('chrome://zotero/skin/cross.png')"; + this._image.style.backgroundPosition = ""; + this._itemText.style.color = "red"; + this._hbox.style.opacity = "1"; + this._hbox.style.filter = ""; + }); + function _onWindowLoaded() { _windowLoading = false; _windowLoaded = true; _move(); - // do things we delayed because the window was loading - changeHeadline(_loadHeadline); - addLines(_loadLines, _loadIcons); - if (_loadDescription) { - addDescription(_loadDescription); - } - // reset parameters - _loadHeadline = ''; - _loadLines = []; - _loadIcons = []; - _loadDescription = null; + // do things we delayed because the window was loading + for(var i=0; i<_deferredUntilWindowLoad.length; i++) { + _deferredUntilWindowLoad[i].apply(_deferredUntilWindowLoadThis[i], + _deferredUntilWindowLoadArgs[i]); + } + _deferredUntilWindowLoad = []; + _deferredUntilWindowLoadThis = []; + _deferredUntilWindowLoadArgs = []; } function _move() { @@ -303,8 +355,8 @@ Zotero.ProgressWindow = function(_window){ } function _timeout() { - close(); // could check to see if we're really supposed to close yet - // (in case multiple scrapers are operating at once) + self.close(); // could check to see if we're really supposed to close yet + // (in case multiple scrapers are operating at once) _timeoutID = false; } @@ -319,7 +371,6 @@ Zotero.ProgressWindow = function(_window){ _timeoutID = false; } - /* * Disable the close timer when the mouse is over the window */ @@ -328,8 +379,7 @@ Zotero.ProgressWindow = function(_window){ _disableTimeout(); } - - /* + /** * Start the close timer when the mouse leaves the window * * Note that this onmouseout doesn't work correctly on popups in Fx2, @@ -345,11 +395,27 @@ Zotero.ProgressWindow = function(_window){ && (e.screenY >= top) && e.screenY <= (top + this.outerHeight)) { return; } - startCloseTimer(); + if(_closing) self.startCloseTimer(); } - function _onMouseUp(e) { - close(); + self.close(); + } + + /** + * Wraps a function to ensure it isn't called until the window is loaded + */ + function _deferUntilWindowLoad(fn) { + return function() { + if(_window.closed) return; + + if(_windowLoaded) { + fn.apply(this, Array.prototype.slice.call(arguments)); + } else { + _deferredUntilWindowLoad.push(fn); + _deferredUntilWindowLoadThis.push(this); + _deferredUntilWindowLoadArgs.push(Array.prototype.slice.call(arguments)); + } + } } } diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js index 385388ac9..ca413b405 100755 --- a/chrome/content/zotero/xpcom/server_connector.js +++ b/chrome/content/zotero/xpcom/server_connector.js @@ -32,17 +32,21 @@ Zotero.Server.Connector.AttachmentProgressManager = new function() { attachmentProgress = {}, i = 1; + /** + * Adds attachments to attachment progress manager + */ + this.add = function(attachments) { + for(var i=0; i Date: Sat, 9 Jun 2012 14:12:27 -0400 Subject: [PATCH 4/8] Fix import --- chrome/content/zotero/xpcom/translation/translate.js | 10 ++++++++-- .../content/zotero/xpcom/translation/translate_item.js | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index a6e9d12c7..5b35e974b 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1199,6 +1199,7 @@ Zotero.Translate.Base.prototype = { deferredProgress[i][1], deferredProgress[i][2]); } + me.newItems = me.newItems.concat(newItems); me._savingItems--; me._checkIfDone(); } else { @@ -1208,8 +1209,10 @@ Zotero.Translate.Base.prototype = { }, function(attachment, progress, error) { var attachmentIndex = me._savingAttachments.indexOf(attachment); - if((progress === false || progress === 100) && attachmentIndex !== -1) { - me._savingAttachments.splice(attachmentIndex, 1); + if(progress === false || progress === 100) { + if(attachmentIndex !== -1) { + me._savingAttachments.splice(attachmentIndex, 1); + } } else if(attachmentIndex === -1) { me._savingAttachments.push(attachment); } @@ -1231,6 +1234,9 @@ Zotero.Translate.Base.prototype = { * Checks if saving done, and if so, fires done event */ "_checkIfDone":function() { + Zotero.debug(this._savingItems); + Zotero.debug(this._savingAttachments.length); + Zotero.debug(this._currentState); if(!this._savingItems && !this._savingAttachments.length && !this._currentState) { this._runHandler("done", true); } diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 511be3597..5763a6da7 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -216,7 +216,7 @@ Zotero.Translate.ItemSaver.prototype = { return topLevelCollection; }, - "_saveAttachmentFile":function(attachment, parentID) { + "_saveAttachmentFile":function(attachment, parentID, attachmentCallback) { const urlRe = /(([A-Za-z]+):\/\/[^\s]*)/i; Zotero.debug("Translate: Adding attachment", 4); From 42f3875b0c965c1df18ea6b53677ea6fd4d0e2c1 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sat, 9 Jun 2012 14:58:29 -0400 Subject: [PATCH 5/8] Remove debug code --- chrome/content/zotero/xpcom/translation/translate.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 5b35e974b..d63ef19a6 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1234,9 +1234,6 @@ Zotero.Translate.Base.prototype = { * Checks if saving done, and if so, fires done event */ "_checkIfDone":function() { - Zotero.debug(this._savingItems); - Zotero.debug(this._savingAttachments.length); - Zotero.debug(this._currentState); if(!this._savingItems && !this._savingAttachments.length && !this._currentState) { this._runHandler("done", true); } From 48f7dd5b6e7adda944011f8f3815f48577d34656 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 10 Jun 2012 15:30:23 -0400 Subject: [PATCH 6/8] Add endpoint for getting selected collection Addresses #23, "Saving item..." notification should show the name of the library where item is imported --- .../content/zotero/xpcom/server_connector.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js index ca413b405..2e30f4d7f 100755 --- a/chrome/content/zotero/xpcom/server_connector.js +++ b/chrome/content/zotero/xpcom/server_connector.js @@ -519,6 +519,64 @@ Zotero.Server.Connector.GetTranslatorCode.prototype = { } } +/** + * Get selected collection + * + * Accepts: + * Nothing + * Returns: + * libraryID + * libraryName + * collectionID + * collectionName + */ +Zotero.Server.Connector.GetSelectedCollection = function() {}; +Zotero.Server.Endpoints["/connector/getSelectedCollection"] = Zotero.Server.Connector.GetSelectedCollection; +Zotero.Server.Connector.GetSelectedCollection.prototype = { + "supportedMethods":["POST"], + "supportedDataTypes":["application/json"], + + /** + * Returns a 200 response to say the server is alive + * @param {String} data POST data or GET query string + * @param {Function} sendResponseCallback function to send HTTP response + */ + "init":function(postData, sendResponseCallback) { + var zp = Zotero.getActiveZoteroPane(), + libraryID = null, + collection = null, + editable = true; + + try { + libraryID = zp.getSelectedLibraryID(); + editable = ZoteroPane.collectionsView.editable; + collection = zp.getSelectedCollection(); + } catch(e) {} + + var response = { + "editable":editable, + "libraryID":libraryID + }; + + if(libraryID) { + response.libraryName = Zotero.Libraries.getName(libraryID); + } else { + response.libraryName = Zotero.getString("pane.collections.library"); + } + + if(collection && collection.id) { + response.id = collection.id; + response.name = collection.name; + } else { + response.id = null; + response.name = response.libraryName; + } + + sendResponseCallback(200, "application/json", JSON.stringify(response)); + } +} + + /** * Test connection * From 3a6669c66fe1ca9ba7ca554134bbe27d4e3b8d93 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 10 Jun 2012 16:50:06 -0400 Subject: [PATCH 7/8] Closes #23, "Saving item..." notification should show the name of the library where item is imported --- chrome/content/zotero/browser.js | 23 +++++++++++++- chrome/content/zotero/progressWindow.xul | 4 +-- chrome/content/zotero/xpcom/progressWindow.js | 30 +++++++++++++++++-- chrome/locale/en-US/zotero/zotero.properties | 1 + chrome/skin/default/zotero/zotero.css | 17 +++++++++-- 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index 6627012fb..d99657f89 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -669,7 +669,6 @@ Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) { Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID, translator) { if(this.page.translators && this.page.translators.length) { Zotero_Browser.progress.show(); - Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scraping")); Zotero_Browser.isScraping = true; if(collectionID) { @@ -679,6 +678,28 @@ Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID, trans var collection = false; } + if(Zotero.isConnector) { + Zotero.Connector.callMethod("getSelectedCollection", {}, function(response, status) { + if(status !== 200) return; + Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapingTo"), + "chrome://zotero/skin/treesource-"+(response.id ? "collection" : "library")+".png", + response.name+"\u2026"); + }); + } else { + var name; + if(collection) { + name = collection.name; + } else if(libraryID) { + name = Zotero.Libraries.getName(libraryID); + } else { + name = Zotero.getString("pane.collections.library"); + } + + Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapingTo"), + "chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png", + name+"\u2026"); + } + var me = this; // use first translator available diff --git a/chrome/content/zotero/progressWindow.xul b/chrome/content/zotero/progressWindow.xul index a220e008e..534b36058 100755 --- a/chrome/content/zotero/progressWindow.xul +++ b/chrome/content/zotero/progressWindow.xul @@ -8,8 +8,8 @@ windowtype="alert:alert"> - - diff --git a/chrome/content/zotero/xpcom/progressWindow.js b/chrome/content/zotero/xpcom/progressWindow.js index aa2b56c90..71f8369a0 100644 --- a/chrome/content/zotero/xpcom/progressWindow.js +++ b/chrome/content/zotero/xpcom/progressWindow.js @@ -159,8 +159,32 @@ Zotero.ProgressWindow = function(_window){ /** * Changes the "headline" shown at the top of the progress window */ - this.changeHeadline = _deferUntilWindowLoad(function changeHeadline(headline) { - _progressWindow.document.getElementById("zotero-progress-text-headline").value = headline; + this.changeHeadline = _deferUntilWindowLoad(function changeHeadline(text, icon, postText) { + var doc = _progressWindow.document, + headline = doc.getElementById("zotero-progress-text-headline"); + while(headline.hasChildNodes()) headline.removeChild(headline.firstChild); + + var preNode = doc.createElement("label"); + preNode.setAttribute("value", text); + preNode.setAttribute("crop", "end"); + headline.appendChild(preNode); + + if(icon) { + var img = doc.createElement("image"); + img.width = 16; + img.height = 16; + img.setAttribute("src", icon); + headline.appendChild(img); + } + + if(postText) { + var postNode = doc.createElement("label"); + postNode.style.marginLeft = 0; + postNode.setAttribute("value", " "+postText); + postNode.setAttribute("crop", "end"); + postNode.setAttribute("flex", "1"); + headline.appendChild(postNode); + } }); /** @@ -270,6 +294,8 @@ Zotero.ProgressWindow = function(_window){ if(parentItemProgress) { this._hbox.style.marginLeft = "16px"; this._hbox.zoteroIsChildItem; + } else { + this._hbox.setAttribute("parent", "true"); } this._hbox.style.opacity = "0.5"; diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 2431ba905..6f0a42cba 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -412,6 +412,7 @@ save.error.cannotAddFilesToCollection = You cannot add files to the currently se ingester.saveToZotero = Save to Zotero ingester.saveToZoteroUsing = Save to Zotero using "%S" ingester.scraping = Saving Item… +ingester.scrapingTo = Saving to ingester.scrapeComplete = Item Saved ingester.scrapeError = Could Not Save Item ingester.scrapeErrorDescription = An error occurred while saving this item. Check %S for more information. diff --git a/chrome/skin/default/zotero/zotero.css b/chrome/skin/default/zotero/zotero.css index 040ba6c88..b95910d01 100644 --- a/chrome/skin/default/zotero/zotero.css +++ b/chrome/skin/default/zotero/zotero.css @@ -220,12 +220,18 @@ label.zotero-text-link { margin: 0; min-height: 50px; width: 250px; - padding-bottom: 3px; + padding: 3px 0 3px 0; } #zotero-progress-text-headline { font-weight: bold; + margin-bottom: 2px; +} + +.zotero-progress-icon-headline { + width: 16px; + height: 16px; } .zotero-progress-item-icon @@ -237,8 +243,13 @@ label.zotero-text-link { .zotero-progress-item-hbox { padding-left: 5px; - margin-top: 1px; - margin-bottom: 1px; + margin-top: 0; + margin-bottom: 0; +} + +.zotero-progress-item-hbox[parent] +{ + margin-top: 3px; } .zotero-progress-item-label From 5c02a81e816854b950a12e0b11c74b11a8f3844e Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 10 Jun 2012 21:55:56 -0400 Subject: [PATCH 8/8] Fix identification of collections --- chrome/content/zotero/xpcom/server_connector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js index 2e30f4d7f..2f8eb27f3 100755 --- a/chrome/content/zotero/xpcom/server_connector.js +++ b/chrome/content/zotero/xpcom/server_connector.js @@ -549,8 +549,8 @@ Zotero.Server.Connector.GetSelectedCollection.prototype = { try { libraryID = zp.getSelectedLibraryID(); - editable = ZoteroPane.collectionsView.editable; collection = zp.getSelectedCollection(); + editable = zp.collectionsView.editable; } catch(e) {} var response = {