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) {
|
this.Translation.scrapingTo = function(libraryID, collection) {
|
||||||
if(Zotero.isConnector) {
|
var name;
|
||||||
Zotero.Connector.callMethod("getSelectedCollection", {}, function(response, status) {
|
if(collection) {
|
||||||
if(status !== 200) {
|
name = collection.name;
|
||||||
self.changeHeadline(Zotero.getString("ingester.scraping"));
|
} else if(libraryID) {
|
||||||
} else {
|
name = Zotero.Libraries.getName(libraryID);
|
||||||
self.changeHeadline(Zotero.getString("ingester.scrapingTo"),
|
|
||||||
"chrome://zotero/skin/treesource-"+(response.id ? "collection" : "library")+".png",
|
|
||||||
response.name+"\u2026");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
var name;
|
name = Zotero.getString("pane.collections.library");
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.changeHeadline(Zotero.getString("ingester.scrapingTo"),
|
||||||
|
"chrome://zotero/skin/treesource-"+(collection ? "collection" : "library")+".png",
|
||||||
|
name+"\u2026");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Translation.doneHandler = function(obj, returnValue) {
|
this.Translation.doneHandler = function(obj, returnValue) {
|
||||||
|
|
|
@ -1206,12 +1206,11 @@ Zotero.Translate.Base.prototype = {
|
||||||
uri: this.location.toString(),
|
uri: this.location.toString(),
|
||||||
cookie: this.document.cookie,
|
cookie: this.document.cookie,
|
||||||
html: this.document.documentElement.innerHTML
|
html: this.document.documentElement.innerHTML
|
||||||
},
|
}).catch(() => false).then(function (rpcTranslators) {
|
||||||
function (rpcTranslators) {
|
|
||||||
this._waitingForRPC = false;
|
this._waitingForRPC = false;
|
||||||
|
|
||||||
// if there are translators, add them to the list of found translators
|
// 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++) {
|
for(var i=0, n=rpcTranslators.length; i<n; i++) {
|
||||||
rpcTranslators[i] = new Zotero.Translator(rpcTranslators[i]);
|
rpcTranslators[i] = new Zotero.Translator(rpcTranslators[i]);
|
||||||
rpcTranslators[i].runMode = Zotero.Translator.RUN_MODE_ZOTERO_STANDALONE;
|
rpcTranslators[i].runMode = Zotero.Translator.RUN_MODE_ZOTERO_STANDALONE;
|
||||||
|
@ -1224,8 +1223,7 @@ Zotero.Translate.Base.prototype = {
|
||||||
if (this._currentState === null) {
|
if (this._currentState === null) {
|
||||||
this._detectTranslatorsCollected();
|
this._detectTranslatorsCollected();
|
||||||
}
|
}
|
||||||
}.bind(this)
|
}.bind(this));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
|
@ -2071,7 +2069,7 @@ Zotero.Translate.Web.prototype._translateTranslatorLoaded = function() {
|
||||||
cookie: this.document.cookie,
|
cookie: this.document.cookie,
|
||||||
proxy: this._proxy ? this._proxy.toJSON() : null,
|
proxy: this._proxy ? this._proxy.toJSON() : null,
|
||||||
html: this.document.documentElement.innerHTML
|
html: this.document.documentElement.innerHTML
|
||||||
}, function(obj) { me._translateRPCComplete(obj) });
|
}).then(obj => me._translateRPCComplete(obj));
|
||||||
} else if(runMode === Zotero.Translator.RUN_MODE_ZOTERO_SERVER) {
|
} else if(runMode === Zotero.Translator.RUN_MODE_ZOTERO_SERVER) {
|
||||||
var me = this;
|
var me = this;
|
||||||
Zotero.API.createItem({"url":this.document.location.href.toString()},
|
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,
|
this._runHandler("select", obj.selectItems,
|
||||||
function(selectedItems) {
|
function(selectedItems) {
|
||||||
Zotero.Connector.callMethod("selectItems",
|
Zotero.Connector.callMethod("selectItems",
|
||||||
{"instanceID":obj.instanceID, "selectedItems":selectedItems},
|
{"instanceID":obj.instanceID, "selectedItems":selectedItems})
|
||||||
function(obj) { me._translateRPCComplete(obj) })
|
.then((obj) => me._translateRPCComplete(obj))
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3670,18 +3670,6 @@ var ZoteroPane = new function()
|
||||||
* @return {Promise<Zotero.Item>|false}
|
* @return {Promise<Zotero.Item>|false}
|
||||||
*/
|
*/
|
||||||
this.addItemFromPage = Zotero.Promise.method(function (itemType, saveSnapshot, row) {
|
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) {
|
if (row == undefined && this.collectionsView && this.collectionsView.selection) {
|
||||||
row = this.collectionsView.selection.currentIndex;
|
row = this.collectionsView.selection.currentIndex;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user