commit 23e01fcefd07a05f3a59e696640bf4994df51ca8
parent 9c53fe893cb2d977bec26823bf4b982d67487791
Author: Dan Stillman <dstillman@zotero.org>
Date: Sat, 9 Apr 2016 18:34:54 -0400
Fix saving to My Library if Zotero pane hasn't been opened
Diffstat:
5 files changed, 83 insertions(+), 35 deletions(-)
diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js
@@ -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;
- }
-
+ // 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();
- } catch(e) {
- Zotero.debug(e, 1);
}
+
+ collection = ZoteroPane.getSelectedCollection();
}
if (libraryID === Zotero.Libraries.publicationsLibraryID) {
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -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);
diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js
@@ -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);
})
diff --git a/test/tests/browserTest.js b/test/tests/browserTest.js
@@ -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();
diff --git a/test/tests/data/snapshot/index.html b/test/tests/data/snapshot/index.html
@@ -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>