From 3b6c31319dacdffbf5abb89e7de2c0c5d9d7c82a Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 1 Jul 2021 16:26:40 +0300 Subject: [PATCH] Tweak pdf-reader and note-editor read-only mode code --- chrome/content/zotero/contextPane.js | 8 +----- chrome/content/zotero/xpcom/editorInstance.js | 14 +++------- chrome/content/zotero/xpcom/reader.js | 26 +++++++++++-------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/chrome/content/zotero/contextPane.js b/chrome/content/zotero/contextPane.js index ae49ecebc5..6b840af82c 100644 --- a/chrome/content/zotero/contextPane.js +++ b/chrome/content/zotero/contextPane.js @@ -690,13 +690,7 @@ var ZoteroContextPane = new function () { } function _isLibraryReadOnly(libraryID) { - var type = Zotero.Libraries.get(libraryID).libraryType; - if (type == 'group') { - var groupID = Zotero.Groups.getGroupIDFromLibraryID(libraryID); - var group = Zotero.Groups.get(groupID); - return !group.editable; - } - return false; + return !Zotero.Libraries.get(libraryID).editable; } function _setPinnedNote(itemID) { diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index 462238baa0..ebda503aa4 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -201,17 +201,9 @@ class EditorInstance { _isReadOnly() { let item = this._item; - if (item.deleted || item.parentItem && item.parentItem.deleted) { - return true; - } - let { libraryID } = item; - var type = Zotero.Libraries.get(libraryID).libraryType; - if (type === 'group') { - var groupID = Zotero.Groups.getGroupIDFromLibraryID(libraryID); - var group = Zotero.Groups.get(groupID); - return !group.editable; - } - return false; + return !item.isEditable() + || item.deleted + || item.parentItem && item.parentItem.deleted; } _getFont() { diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index c677821710..5d9792a782 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -257,17 +257,9 @@ class ReaderInstance { _isReadOnly() { let item = Zotero.Items.get(this._itemID); - if (item.deleted || item.parentItem && item.parentItem.deleted) { - return true; - } - let { libraryID } = item; - var type = Zotero.Libraries.get(libraryID).libraryType; - if (type === 'group') { - var groupID = Zotero.Groups.getGroupIDFromLibraryID(libraryID); - var group = Zotero.Groups.get(groupID); - return !group.editable; - } - return false; + return !item.isEditable() + || item.deleted + || item.parentItem && item.parentItem.deleted; } _dataURLtoBlob(dataurl) { @@ -999,8 +991,20 @@ class Reader { } } + /** + * Trigger annotations import + * + * @param {Integer} itemID Attachment item id + * @returns {Promise} + */ async triggerAnnotationsImportCheck(itemID) { let item = await Zotero.Items.getAsync(itemID); + if (!item.isEditable() + || item.deleted + || item.parentItem && item.parentItem.deleted + ) { + return; + } let mtime = await item.attachmentModificationTime; if (item.attachmentLastProcessedModificationTime < Math.floor(mtime / 1000)) { await Zotero.PDFWorker.import(itemID, true);