Fix "Save to Zotero" in download overlay
This commit is contained in:
parent
8197fa4ce8
commit
790d6d3dd6
2 changed files with 44 additions and 39 deletions
|
@ -49,7 +49,7 @@ var Zotero_DownloadOverlay = new function() {
|
||||||
*
|
*
|
||||||
* @return {Boolean} True if an item was saved, false if we were not supposed to save
|
* @return {Boolean} True if an item was saved, false if we were not supposed to save
|
||||||
*/
|
*/
|
||||||
this.handleSave = function() {
|
this.handleSave = Zotero.Promise.coroutine(function* () {
|
||||||
if(!document.getElementById('zotero-radio').selected) return false;
|
if(!document.getElementById('zotero-radio').selected) return false;
|
||||||
|
|
||||||
var retrieveMetadata = document.getElementById('zotero-recognizePDF').selected;
|
var retrieveMetadata = document.getElementById('zotero-recognizePDF').selected;
|
||||||
|
@ -72,6 +72,7 @@ var Zotero_DownloadOverlay = new function() {
|
||||||
else {
|
else {
|
||||||
Zotero.debug("Cannot save files to library " + itemGroup.ref.libraryID
|
Zotero.debug("Cannot save files to library " + itemGroup.ref.libraryID
|
||||||
+ " -- saving to personal library instead", 2);
|
+ " -- saving to personal library instead", 2);
|
||||||
|
libraryID = Zotero.Libraries.userLibraryID;
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
Zotero.debug(e, 1);
|
Zotero.debug(e, 1);
|
||||||
|
@ -80,34 +81,10 @@ var Zotero_DownloadOverlay = new function() {
|
||||||
var recognizePDF = document.getElementById('zotero-recognizePDF').checked
|
var recognizePDF = document.getElementById('zotero-recognizePDF').checked
|
||||||
&& !document.getElementById('zotero-recognizePDF').hidden
|
&& !document.getElementById('zotero-recognizePDF').hidden
|
||||||
&& !document.getElementById('zotero-recognizePDF').disabled;
|
&& !document.getElementById('zotero-recognizePDF').disabled;
|
||||||
|
var contentType = dialog.mLauncher.MIMEInfo.MIMEType;
|
||||||
|
|
||||||
// set up callback
|
// mimic dialog cancellation
|
||||||
var callback = function(item) {
|
dialog.onCancel();
|
||||||
if(!win) return;
|
|
||||||
|
|
||||||
if(item) {
|
|
||||||
progressWin.addLines([item.getDisplayTitle()], [item.getImageSrc()]);
|
|
||||||
progressWin.startCloseTimer();
|
|
||||||
if(collection) collection.addItem(item.id);
|
|
||||||
} else {
|
|
||||||
progressWin.addDescription(Zotero.getString("save.link.error"));
|
|
||||||
progressWin.startCloseTimer(8000);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(recognizePDF) {
|
|
||||||
var timer = Components.classes["@mozilla.org/timer;1"]
|
|
||||||
.createInstance(Components.interfaces.nsITimer);
|
|
||||||
timer.init(function() {
|
|
||||||
try {
|
|
||||||
if(item.getFile()) {
|
|
||||||
timer.cancel();
|
|
||||||
var recognizer = new win.Zotero_RecognizePDF.ItemRecognizer();
|
|
||||||
recognizer.recognizeItems([item]);
|
|
||||||
}
|
|
||||||
} catch(e) { dump(e.toSource()) };
|
|
||||||
}, 1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
var progressWin = new Zotero.ProgressWindow();
|
var progressWin = new Zotero.ProgressWindow();
|
||||||
|
@ -115,15 +92,44 @@ var Zotero_DownloadOverlay = new function() {
|
||||||
progressWin.show();
|
progressWin.show();
|
||||||
|
|
||||||
// perform import
|
// perform import
|
||||||
Zotero.Attachments.importFromURL(url, false, false, false,
|
try {
|
||||||
collection ? [collection.id] : [], dialog.mLauncher.MIMEInfo.MIMEType,
|
var item = yield Zotero.Attachments.importFromURL({
|
||||||
libraryID, callback);
|
libraryID,
|
||||||
|
url,
|
||||||
|
collections: collection ? [collection.id] : [],
|
||||||
|
contentType
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
if (!win) return;
|
||||||
|
progressWin.addDescription(Zotero.getString("save.link.error"));
|
||||||
|
progressWin.startCloseTimer(8000);
|
||||||
|
Zotero.logError(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// mimic dialog cancellation
|
if(!win) return;
|
||||||
dialog.onCancel();
|
|
||||||
|
progressWin.addLines([item.getDisplayTitle()], [item.getImageSrc()]);
|
||||||
|
progressWin.startCloseTimer();
|
||||||
|
if(collection) collection.addItem(item.id);
|
||||||
|
|
||||||
|
if(recognizePDF) {
|
||||||
|
var timer = Components.classes["@mozilla.org/timer;1"]
|
||||||
|
.createInstance(Components.interfaces.nsITimer);
|
||||||
|
timer.init(function() {
|
||||||
|
try {
|
||||||
|
if (item && item.getFile()) {
|
||||||
|
timer.cancel();
|
||||||
|
var recognizer = new win.Zotero_RecognizePDF.ItemRecognizer();
|
||||||
|
recognizer.recognizeItems([item]);
|
||||||
|
}
|
||||||
|
} catch(e) { dump(e.toSource()) };
|
||||||
|
}, 1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when mode in dialog has been changed
|
* Called when mode in dialog has been changed
|
||||||
|
@ -188,9 +194,9 @@ var Zotero_DownloadOverlay = new function() {
|
||||||
|
|
||||||
// Hook in event listener to ondialogaccept
|
// Hook in event listener to ondialogaccept
|
||||||
document.documentElement.setAttribute('ondialogaccept',
|
document.documentElement.setAttribute('ondialogaccept',
|
||||||
'if(!Zotero_DownloadOverlay.handleSave()) { '
|
'Zotero_DownloadOverlay.handleSave().then(function (saved) { if (!saved) {'
|
||||||
+ document.documentElement.getAttribute('ondialogaccept')
|
+ document.documentElement.getAttribute('ondialogaccept')
|
||||||
+'}');
|
+'}})');
|
||||||
|
|
||||||
// Hook in event listener for mode change
|
// Hook in event listener for mode change
|
||||||
var radios = document.getElementById('mode').
|
var radios = document.getElementById('mode').
|
||||||
|
|
|
@ -221,7 +221,7 @@ Zotero.Attachments = new function(){
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} options - 'url', 'parentItemID', 'collections', 'title',
|
* @param {Object} options - 'libraryID', 'url', 'parentItemID', 'collections', 'title',
|
||||||
* 'fileBaseName', 'contentType', 'cookieSandbox'
|
* 'fileBaseName', 'contentType', 'cookieSandbox'
|
||||||
* @return {Promise<Zotero.Item>} - A promise for the created attachment item
|
* @return {Promise<Zotero.Item>} - A promise for the created attachment item
|
||||||
*/
|
*/
|
||||||
|
@ -247,8 +247,7 @@ Zotero.Attachments = new function(){
|
||||||
var urlRe = /^https?:\/\/[^\s]*$/;
|
var urlRe = /^https?:\/\/[^\s]*$/;
|
||||||
var matches = urlRe.exec(url);
|
var matches = urlRe.exec(url);
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
Components.utils.reportError("Invalid URL '" + url + "' in Zotero.Attachments.importFromURL()");
|
throw new Error("Invalid URL '" + url + "'");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save using a hidden browser
|
// Save using a hidden browser
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue