Refactor Connector.callMethod calls to use the promisified form
This commit is contained in:
parent
7c020da594
commit
dcfddac519
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user