From 26d784ca0fe0e55a5c016485b3c0e9b98efcc897 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 30 Jun 2021 16:26:14 +0300 Subject: [PATCH] Allow read-only note editing in a separate window in PDF build --- chrome/content/zotero/xpcom/editorInstance.js | 17 ++++++++++++++++- chrome/content/zotero/zoteroPane.js | 11 ++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index 018c06f31d..462238baa0 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -57,7 +57,7 @@ class EditorInstance { // TODO: Consider to use only itemID instead of loaded item this._item = options.item; this._viewMode = options.viewMode; - this._readOnly = options.readOnly; + this._readOnly = options.readOnly || this._isReadOnly(); this._disableUI = options.disableUI; this._onReturn = options.onReturn; this._iframeWindow = options.iframeWindow; @@ -199,6 +199,21 @@ class EditorInstance { this._iframeWindow.postMessage({ instanceID: this.instanceID, message }, '*'); } + _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; + } + _getFont() { let fontSize = Zotero.Prefs.get('note.fontSize'); // Fix empty old font prefs before a value was enforced diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 36c8a4d4cb..18525cafd8 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -3560,7 +3560,9 @@ var ZoteroPane = new function() this.openNoteWindow = function (itemID, col, parentKey) { - if (!this.canEdit()) { + var item = Zotero.Items.get(itemID); + var type = Zotero.Libraries.get(item.libraryID).libraryType; + if (!this.canEdit() && (type == 'group' || !Zotero.isPDFBuild)) { this.displayCannotEditLibraryMessage(); return; } @@ -3613,7 +3615,9 @@ var ZoteroPane = new function() this.openBackupNoteWindow = function (itemID) { - if (!this.canEdit()) { + var item = Zotero.Items.get(itemID); + var type = Zotero.Libraries.get(item.libraryID).libraryType; + if (!this.canEdit() && (type == 'group' || !Zotero.isPDFBuild)) { this.displayCannotEditLibraryMessage(); return; } @@ -4095,7 +4099,8 @@ var ZoteroPane = new function() } } else if (item.isNote()) { - if (!this.collectionsView.editable) { + var type = Zotero.Libraries.get(item.libraryID).libraryType; + if (!this.collectionsView.editable && (type == 'group' || !Zotero.isPDFBuild)) { continue; } document.getElementById('zotero-view-note-button').doCommand();