www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit dcfddac519e6bcb9842b6279ed13525ce95563ce
parent 7c020da594077710091826192793ceead632a21c
Author: Adomas VenĨkauskas <adomas.ven@gmail.com>
Date:   Mon, 19 Jun 2017 12:18:48 +0300

Refactor Connector.callMethod calls to use the promisified form

Diffstat:
Mchrome/content/zotero/xpcom/progressWindow.js | 32++++++++++----------------------
Mchrome/content/zotero/xpcom/translation/translate.js | 14++++++--------
Mchrome/content/zotero/zoteroPane.js | 12------------
3 files changed, 16 insertions(+), 42 deletions(-)

diff --git a/chrome/content/zotero/xpcom/progressWindow.js b/chrome/content/zotero/xpcom/progressWindow.js @@ -404,30 +404,18 @@ Zotero.ProgressWindow = function(options = {}) { }; this.Translation.scrapingTo = function(libraryID, collection) { - if(Zotero.isConnector) { - Zotero.Connector.callMethod("getSelectedCollection", {}, function(response, status) { - if(status !== 200) { - self.changeHeadline(Zotero.getString("ingester.scraping")); - } else { - self.changeHeadline(Zotero.getString("ingester.scrapingTo"), - "chrome://zotero/skin/treesource-"+(response.id ? "collection" : "library")+".png", - response.name+"\u2026"); - } - }); + var name; + if(collection) { + name = collection.name; + } else if(libraryID) { + name = Zotero.Libraries.getName(libraryID); } else { - var name; - if(collection) { - name = collection.name; - } else if(libraryID) { - name = Zotero.Libraries.getName(libraryID); - } else { - name = Zotero.getString("pane.collections.library"); - } - - self.changeHeadline(Zotero.getString("ingester.scrapingTo"), - "chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png", - name+"\u2026"); + name = Zotero.getString("pane.collections.library"); } + + self.changeHeadline(Zotero.getString("ingester.scrapingTo"), + "chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png", + name+"\u2026"); }; this.Translation.doneHandler = function(obj, returnValue) { diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js @@ -1206,12 +1206,11 @@ Zotero.Translate.Base.prototype = { uri: this.location.toString(), cookie: this.document.cookie, html: this.document.documentElement.innerHTML - }, - function (rpcTranslators) { + }).catch(() => false).then(function (rpcTranslators) { this._waitingForRPC = false; // if there are translators, add them to the list of found translators - if(rpcTranslators) { + if (rpcTranslators) { for(var i=0, n=rpcTranslators.length; i<n; i++) { rpcTranslators[i] = new Zotero.Translator(rpcTranslators[i]); rpcTranslators[i].runMode = Zotero.Translator.RUN_MODE_ZOTERO_STANDALONE; @@ -1224,8 +1223,7 @@ Zotero.Translate.Base.prototype = { if (this._currentState === null) { this._detectTranslatorsCollected(); } - }.bind(this) - ); + }.bind(this)); } return deferred.promise; @@ -2071,7 +2069,7 @@ Zotero.Translate.Web.prototype._translateTranslatorLoaded = function() { cookie: this.document.cookie, proxy: this._proxy ? this._proxy.toJSON() : null, html: this.document.documentElement.innerHTML - }, function(obj) { me._translateRPCComplete(obj) }); + }).then(obj => me._translateRPCComplete(obj)); } else if(runMode === Zotero.Translator.RUN_MODE_ZOTERO_SERVER) { var me = this; Zotero.API.createItem({"url":this.document.location.href.toString()}, @@ -2093,8 +2091,8 @@ Zotero.Translate.Web.prototype._translateRPCComplete = function(obj, failureCode this._runHandler("select", obj.selectItems, function(selectedItems) { Zotero.Connector.callMethod("selectItems", - {"instanceID":obj.instanceID, "selectedItems":selectedItems}, - function(obj) { me._translateRPCComplete(obj) }) + {"instanceID":obj.instanceID, "selectedItems":selectedItems}) + .then((obj) => me._translateRPCComplete(obj)) } ); } else { diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -3670,18 +3670,6 @@ var ZoteroPane = new function() * @return {Promise<Zotero.Item>|false} */ this.addItemFromPage = Zotero.Promise.method(function (itemType, saveSnapshot, row) { - if(Zotero.isConnector) { - // In connector, save page via Zotero Standalone - var doc = window.content.document; - Zotero.Connector.callMethod("saveSnapshot", {"url":doc.location.toString(), - "cookie":doc.cookie, "html":doc.documentElement.innerHTML, - "skipSnapshot": saveSnapshot === false || (saveSnapshot === true ? false : undefined)}, - function(returnValue, status) { - _showPageSaveStatus(doc.title); - }); - return false; - } - if (row == undefined && this.collectionsView && this.collectionsView.selection) { row = this.collectionsView.selection.currentIndex; }