From d715197b2f8470dada38cdbb3ab7bf95824c5e21 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 27 Apr 2017 03:57:33 -0400 Subject: [PATCH] Don't show Show/Hide button in My Publications for linked files --- chrome/content/zotero/zoteroPane.js | 17 ++++++++++------ test/tests/itemTreeViewTest.js | 31 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 9ad9495c5..2365aa685 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -1605,12 +1605,17 @@ var ZoteroPane = new function() } // My Publications buttons - let isPublications = this.getCollectionTreeRow().isPublications(); - let myPublicationsButtons = document.getElementById('zotero-item-pane-top-buttons-my-publications'); - let regularItemsSelected = selectedItems.some(item => item.isRegularItem()); - let myPublicationsShown = isPublications && !regularItemsSelected; - myPublicationsButtons.hidden = !myPublicationsShown; - if (myPublicationsShown) { + var isPublications = this.getCollectionTreeRow().isPublications(); + // Show in My Publications view if selected items are all notes or non-linked-file attachments + var showMyPublicationsButtons = isPublications + && selectedItems.every((item) => { + return item.isNote() + || (item.isAttachment() + && item.attachmentLinkMode != Zotero.Attachments.LINK_MODE_LINKED_FILE); + }); + var myPublicationsButtons = document.getElementById('zotero-item-pane-top-buttons-my-publications'); + myPublicationsButtons.hidden = !showMyPublicationsButtons; + if (showMyPublicationsButtons) { let button = myPublicationsButtons.firstChild; let hiddenItemsSelected = selectedItems.some(item => !item.inPublications); let str, onclick; diff --git a/test/tests/itemTreeViewTest.js b/test/tests/itemTreeViewTest.js index b2471813e..00e9b1f9a 100644 --- a/test/tests/itemTreeViewTest.js +++ b/test/tests/itemTreeViewTest.js @@ -604,6 +604,37 @@ describe("Zotero.ItemTreeView", function() { assert.isNumber(iv.getRowIndexByID(item2.id)); }); + + it("should show Show/Hide button for imported file attachment", function* () { + var item = yield createDataObject('item', { inPublications: true }); + var attachment = yield importFileAttachment('test.png', { parentItemID: item.id }); + + yield zp.collectionsView.selectByID("P" + item.libraryID); + yield waitForItemsLoad(win); + var iv = zp.itemsView; + + yield iv.selectItem(attachment.id); + + var box = win.document.getElementById('zotero-item-pane-top-buttons-my-publications'); + assert.isFalse(box.hidden); + }); + + it("shouldn't show Show/Hide button for linked file attachment", function* () { + var item = yield createDataObject('item', { inPublications: true }); + var attachment = yield Zotero.Attachments.linkFromFile({ + file: OS.Path.join(getTestDataDirectory().path, 'test.png'), + parentItemID: item.id + }); + + yield zp.collectionsView.selectByID("P" + item.libraryID); + yield waitForItemsLoad(win); + var iv = zp.itemsView; + + yield iv.selectItem(attachment.id); + + var box = win.document.getElementById('zotero-item-pane-top-buttons-my-publications'); + assert.isTrue(box.hidden); + }); }); })