Fix saving to My Library if Zotero pane hasn't been opened
This commit is contained in:
parent
9c53fe893c
commit
23e01fcefd
5 changed files with 84 additions and 36 deletions
|
@ -622,17 +622,19 @@ var Zotero_Browser = new function() {
|
|||
|
||||
// Get libraryID and collectionID
|
||||
if(libraryID === undefined && ZoteroPane && !Zotero.isConnector) {
|
||||
try {
|
||||
if (!ZoteroPane.collectionsView.editable) {
|
||||
Zotero_Browser.progress.cannotEditCollection();
|
||||
return;
|
||||
}
|
||||
|
||||
libraryID = ZoteroPane.getSelectedLibraryID();
|
||||
collection = ZoteroPane.getSelectedCollection();
|
||||
} catch(e) {
|
||||
Zotero.debug(e, 1);
|
||||
// Save to My Library by default if pane hasn't been opened
|
||||
if (!ZoteroPane.collectionsView || !ZoteroPane.collectionsView.selectedTreeRow) {
|
||||
libraryID = Zotero.Libraries.userLibraryID;
|
||||
}
|
||||
else if (!ZoteroPane.collectionsView.editable) {
|
||||
Zotero_Browser.progress.Translation.cannotEditCollection();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
libraryID = ZoteroPane.getSelectedLibraryID();
|
||||
}
|
||||
|
||||
collection = ZoteroPane.getSelectedCollection();
|
||||
}
|
||||
|
||||
if (libraryID === Zotero.Libraries.publicationsLibraryID) {
|
||||
|
|
|
@ -3484,19 +3484,21 @@ var ZoteroPane = new function()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!row && this.collectionsView && this.collectionsView.selection) {
|
||||
if (row == undefined && this.collectionsView && this.collectionsView.selection) {
|
||||
row = this.collectionsView.selection.currentIndex;
|
||||
}
|
||||
|
||||
if (!this.canEdit(row)) {
|
||||
this.displayCannotEditLibraryMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
var collectionTreeRow = this.collectionsView.getRow(row);
|
||||
if (collectionTreeRow.isPublications()) {
|
||||
this.displayCannotAddToMyPublicationsMessage();
|
||||
return false;
|
||||
if (row !== undefined) {
|
||||
if (!this.canEdit(row)) {
|
||||
this.displayCannotEditLibraryMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
var collectionTreeRow = this.collectionsView.getRow(row);
|
||||
if (collectionTreeRow.isPublications()) {
|
||||
this.displayCannotAddToMyPublicationsMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return this.addItemFromDocument(window.content.document, itemType, saveSnapshot, row);
|
||||
|
|
|
@ -171,7 +171,7 @@ describe("Zotero.Attachments", function() {
|
|||
assert.equal(attachment.getField('url'), "file://" + uri);
|
||||
|
||||
// Check indexing
|
||||
var matches = yield Zotero.Fulltext.findTextInItems([attachment.id], 'works');
|
||||
var matches = yield Zotero.Fulltext.findTextInItems([attachment.id], 'share your research');
|
||||
assert.lengthOf(matches, 1);
|
||||
assert.propertyVal(matches[0], 'id', attachment.id);
|
||||
})
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
describe("Zotero_Browser", function () {
|
||||
var win;
|
||||
var win, collection;
|
||||
|
||||
before(function* () {
|
||||
win = yield loadBrowserWindow();
|
||||
collection = yield createDataObject('collection');
|
||||
});
|
||||
|
||||
after(function* () {
|
||||
|
@ -15,6 +16,55 @@ describe("Zotero_Browser", function () {
|
|||
Zotero.ProgressWindowSet.closeAll();
|
||||
})
|
||||
|
||||
|
||||
it("should save webpage to My Library if the Zotero pane hasn't been opened yet in a Firefox window", function* () {
|
||||
var win = yield loadBrowserWindow();
|
||||
|
||||
var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html");
|
||||
var deferred = Zotero.Promise.defer();
|
||||
win.Zotero_Browser.addDetectCallback(() => deferred.resolve());
|
||||
win.loadURI(uri);
|
||||
yield deferred.promise;
|
||||
|
||||
var promise = waitForWindow('chrome://zotero/content/progressWindow.xul', function (progressWin) {
|
||||
assert.include(
|
||||
progressWin.document.documentElement.textContent,
|
||||
"Test"
|
||||
);
|
||||
});
|
||||
yield win.Zotero_Browser.scrapeThisPage();
|
||||
yield promise;
|
||||
|
||||
win.close();
|
||||
});
|
||||
|
||||
it("should save journal article to My Library if the Zotero pane hasn't been opened yet in a Firefox window", function* () {
|
||||
Zotero.Prefs.set('lastViewedFolder', collection.collectionTreeViewID);
|
||||
|
||||
var win = yield loadBrowserWindow();
|
||||
|
||||
var deferred = Zotero.Promise.defer();
|
||||
win.Zotero_Browser.addDetectCallback(() => deferred.resolve());
|
||||
var uri = OS.Path.join(
|
||||
getTestDataDirectory().path, "metadata", "journalArticle-single.html"
|
||||
);
|
||||
win.loadURI(uri);
|
||||
yield deferred.promise;
|
||||
|
||||
var promise1 = waitForWindow('chrome://zotero/content/progressWindow.xul', function (progressWin) {});
|
||||
var promise2 = waitForItemEvent('add');
|
||||
yield win.Zotero_Browser.scrapeThisPage();
|
||||
yield promise1;
|
||||
var ids = yield promise2;
|
||||
var items = Zotero.Items.get(ids);
|
||||
assert.lengthOf(items, 1);
|
||||
assert.equal(items[0].libraryID, Zotero.Libraries.userLibraryID);
|
||||
assert.equal(Zotero.ItemTypes.getName(items[0].itemTypeID), 'journalArticle');
|
||||
assert.lengthOf(items[0].getCollections(), 0);
|
||||
|
||||
win.close();
|
||||
});
|
||||
|
||||
it("should save webpage to current collection", function* () {
|
||||
var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html");
|
||||
var deferred = Zotero.Promise.defer();
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
|
||||
|
||||
<meta name="wpd_version" content="0.2">
|
||||
<meta name="wpd_baseurl" content="http://209.141.35.188/">
|
||||
<meta name="wpd_url" content="http://209.141.35.188/">
|
||||
<meta name="wpd_date" content="2015-05-05T00:06Z">
|
||||
</head>
|
||||
<body><h1>It works!</h1>
|
||||
<p>This is the default web page for this server.</p>
|
||||
<p>The web server software is running but no content has been added, yet.</p>
|
||||
|
||||
</body>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test</h1>
|
||||
<p>Zotero [zoh-TAIR-oh] is a free, easy-to-use tool to help you collect, organize, cite, and share your research sources.</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue