Fix saving of single files to library root via save button
This commit is contained in:
parent
ea1486f62f
commit
20ece48a57
4 changed files with 44 additions and 5 deletions
|
@ -634,7 +634,7 @@ Zotero.Attachments = new function(){
|
|||
attachmentItem.attachmentLinkMode = Zotero.Attachments.LINK_MODE_IMPORTED_URL;
|
||||
attachmentItem.attachmentCharset = 'utf-8'; // WPD will output UTF-8
|
||||
attachmentItem.attachmentContentType = contentType;
|
||||
if (collections) {
|
||||
if (collections && collections.length) {
|
||||
attachmentItem.setCollections(collections);
|
||||
}
|
||||
var itemID = yield attachmentItem.save();
|
||||
|
@ -861,11 +861,9 @@ Zotero.Attachments = new function(){
|
|||
this.createTemporaryStorageDirectory = Zotero.Promise.coroutine(function* () {
|
||||
var tmpDir = Zotero.getStorageDirectory();
|
||||
tmpDir.append("tmp-" + Zotero.Utilities.randomString(6));
|
||||
Zotero.debug("RANDOM IS " + tmpDir.leafName);
|
||||
yield OS.File.makeDir(tmpDir.path, {
|
||||
unixMode: 0755
|
||||
});
|
||||
Zotero.debug("MADE DIRECTORY at " + tmpDir.path);
|
||||
return tmpDir;
|
||||
});
|
||||
|
||||
|
|
|
@ -3405,7 +3405,7 @@ var ZoteroPane = new function()
|
|||
let item = yield Zotero.Attachments.importFromDocument({
|
||||
libraryID: libraryID,
|
||||
document: doc,
|
||||
collections: [collectionID]
|
||||
collections: collectionID ? [collectionID] : []
|
||||
});
|
||||
|
||||
yield this.selectItem(item.id);
|
||||
|
|
|
@ -42,7 +42,9 @@ function loadBrowserWindow() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads a Zotero pane in a new window and selects My Library. Returns the containing window.
|
||||
* Opens the Zotero pane and selects My Library. Returns the containing window.
|
||||
*
|
||||
* @param {Window} [win] - Existing window to use; if not specified, a new window is opened
|
||||
*/
|
||||
var loadZoteroPane = Zotero.Promise.coroutine(function* (win) {
|
||||
if (!win) {
|
||||
|
|
|
@ -55,6 +55,45 @@ describe("Zotero_Browser", function () {
|
|||
assert.isTrue(collection.hasItem(items[0].id));
|
||||
})
|
||||
|
||||
it("should save PDF to library root", function* () {
|
||||
var uri = OS.Path.join(getTestDataDirectory().path, "test.pdf");
|
||||
var deferred = Zotero.Promise.defer();
|
||||
win.addEventListener('pageshow', () => deferred.resolve());
|
||||
win.loadURI(uri);
|
||||
yield deferred.promise;
|
||||
|
||||
yield loadZoteroPane(win);
|
||||
|
||||
var promise = waitForItemEvent('add');
|
||||
yield win.Zotero_Browser.scrapeThisPage();
|
||||
var ids = yield promise;
|
||||
var items = Zotero.Items.get(ids);
|
||||
assert.lengthOf(items, 1);
|
||||
assert.equal(Zotero.ItemTypes.getName(items[0].itemTypeID), 'attachment');
|
||||
assert.equal(items[0].getField('title'), 'test.pdf');
|
||||
assert.equal(items[0].attachmentContentType, 'application/pdf');
|
||||
assert.equal(Zotero.Attachments.linkModeToName(items[0].attachmentLinkMode), 'imported_url');
|
||||
});
|
||||
|
||||
it("should save PDF to current collection", function* () {
|
||||
var uri = OS.Path.join(getTestDataDirectory().path, "test.pdf");
|
||||
var deferred = Zotero.Promise.defer();
|
||||
win.addEventListener('pageshow', () => deferred.resolve());
|
||||
win.loadURI(uri);
|
||||
yield deferred.promise;
|
||||
|
||||
yield loadZoteroPane(win);
|
||||
var collection = yield createDataObject('collection');
|
||||
|
||||
var promise = waitForItemEvent('add');
|
||||
yield win.Zotero_Browser.scrapeThisPage();
|
||||
var ids = yield promise;
|
||||
var items = Zotero.Items.get(ids);
|
||||
assert.lengthOf(items, 1);
|
||||
assert.equal(Zotero.ItemTypes.getName(items[0].itemTypeID), 'attachment');
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue