Closes #805, Translation shouldn't create new item in My Publications

And in download overlay, save and switch to My Library if My
Publications is selected.
This commit is contained in:
Dan Stillman 2015-12-10 01:09:40 -05:00
parent e3033b056e
commit 177dac3fd2
7 changed files with 92 additions and 7 deletions

View file

@ -631,6 +631,15 @@ var Zotero_Browser = new function() {
}
}
if (libraryID === Zotero.Libraries.publicationsLibraryID) {
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
var desc = Zotero.getString('save.error.cannotAddToMyPublications');
Zotero_Browser.progress.addDescription(desc);
Zotero_Browser.progress.show();
Zotero_Browser.progress.startCloseTimer(8000);
return;
}
if(Zotero.isConnector) {
Zotero.Connector.callMethod("getSelectedCollection", {}, function(response, status) {
if(status !== 200) {

View file

@ -64,14 +64,14 @@ var Zotero_DownloadOverlay = new function() {
var libraryID, collection;
try {
let itemGroup = win.ZoteroPane.getCollectionTreeRow();
if (itemGroup.filesEditable) {
if (itemGroup.filesEditable && !itemGroup.isPublications()) {
libraryID = win.ZoteroPane.getSelectedLibraryID();
collection = win.ZoteroPane.getSelectedCollection();
}
// TODO: Just show an error instead?
else {
Zotero.debug("Cannot save files to library " + itemGroup.ref.libraryID
+ " -- saving to personal library instead", 2);
+ " -- saving to My Library instead", 2);
libraryID = Zotero.Libraries.userLibraryID;
}
} catch(e) {
@ -98,7 +98,7 @@ var Zotero_DownloadOverlay = new function() {
url,
collections: collection ? [collection.id] : [],
contentType
})
});
}
catch (e) {
if (!win) return;
@ -112,7 +112,11 @@ var Zotero_DownloadOverlay = new function() {
progressWin.addLines([item.getDisplayTitle()], [item.getImageSrc()]);
progressWin.startCloseTimer();
if(collection) collection.addItem(item.id);
if (collection) {
yield collection.addItem(item.id);
}
yield win.ZoteroPane.selectItem(item.id);
if(recognizePDF) {
var timer = Components.classes["@mozilla.org/timer;1"]

View file

@ -98,6 +98,11 @@ Zotero.ProgressWindowSet = new function() {
_progressWindows[i].instance.startCloseTimer(null, true);
}
}
this.closeAll = function () {
_progressWindows.forEach(pw => pw.instance.close());
}
}

View file

@ -3341,6 +3341,12 @@ var ZoteroPane = new function()
return false;
}
var collectionTreeRow = this.collectionsView.getRow(row);
if (collectionTreeRow.isPublications()) {
this.displayCannotAddToMyPublicationsMessage();
return false;
}
return this.addItemFromDocument(window.content.document, itemType, saveSnapshot, row);
});
@ -3977,6 +3983,13 @@ var ZoteroPane = new function()
}
this.displayCannotAddToMyPublicationsMessage = function () {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
ps.alert(null, "", Zotero.getString('save.error.cannotAddToMyPublications'));
}
// TODO: Figure out a functioning way to get the original path and just copy the real file
this.displayCannotAddShortcutMessage = function (path) {
Zotero.alert(

View file

@ -491,6 +491,7 @@ save.link = Saving Link…
save.link.error = An error occurred while saving this link.
save.error.cannotMakeChangesToCollection = You cannot make changes to the currently selected collection.
save.error.cannotAddFilesToCollection = You cannot add files to the currently selected collection.
save.error.cannotAddToMyPublications = You cannot save items directly to My Publications. To add items to My Publications, drag them from another library.
ingester.saveToZotero = Save to Zotero
ingester.saveToZoteroUsing = Save to Zotero using "%S"

View file

@ -127,7 +127,12 @@ function waitForDialog(onOpen, button='accept', url) {
failure = e;
}
}
if (button != 'cancel') {
if (button === false) {
if (failure) {
throw failure;
}
}
else if (button != 'cancel') {
let deferred = Zotero.Promise.defer();
function acceptWhenEnabled() {
// Handle delayed buttons

View file

@ -2,14 +2,20 @@
describe("Zotero_Browser", function () {
var win;
before(function* () {
win = yield loadBrowserWindow();
});
after(function* () {
win.close();
});
it("should save webpage item to current collection", function* () {
afterEach(function () {
Zotero.ProgressWindowSet.closeAll();
})
it("should save webpage to current collection", function* () {
var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html");
var deferred = Zotero.Promise.defer();
win.addEventListener('pageshow', () => deferred.resolve());
@ -28,7 +34,7 @@ describe("Zotero_Browser", function () {
assert.isTrue(collection.hasItem(items[0].id));
})
it("should save journalArticle to current collection", function* () {
it("should save journal article to current collection", function* () {
var uri = OS.Path.join(
getTestDataDirectory().path, "metadata", "journalArticle-single.html"
);
@ -48,4 +54,46 @@ describe("Zotero_Browser", function () {
assert.equal(Zotero.ItemTypes.getName(items[0].itemTypeID), 'journalArticle');
assert.isTrue(collection.hasItem(items[0].id));
})
it("shouldn't save webpage to My Publications", function* () {
var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html");
var deferred = Zotero.Promise.defer();
win.addEventListener('pageshow', () => deferred.resolve());
win.loadURI(uri);
yield deferred.promise;
yield loadZoteroPane(win);
yield selectLibrary(win, Zotero.Libraries.publicationsLibraryID);
var promise = waitForDialog(function (dialog) {
assert.include(
dialog.document.documentElement.textContent,
Zotero.getString('save.error.cannotAddToMyPublications')
);
});
yield win.Zotero_Browser.scrapeThisPage();
yield promise;
})
it("shouldn't save journal article to My Publications", function* () {
var uri = OS.Path.join(
getTestDataDirectory().path, "metadata", "journalArticle-single.html"
);
var deferred = Zotero.Promise.defer();
win.addEventListener('pageshow', () => deferred.resolve());
win.loadURI(uri);
yield deferred.promise;
yield loadZoteroPane(win);
yield selectLibrary(win, Zotero.Libraries.publicationsLibraryID);
var promise = waitForDialog(function (dialog) {
assert.include(
dialog.document.documentElement.textContent,
Zotero.getString('save.error.cannotAddToMyPublications')
);
}, false, 'chrome://zotero/content/progressWindow.xul');
yield win.Zotero_Browser.scrapeThisPage();
yield promise;
})
})