Use old editor in group libraries
This commit is contained in:
parent
66bed2529c
commit
04c64fe9fc
6 changed files with 131 additions and 42 deletions
|
@ -360,8 +360,17 @@
|
|||
indexStatusRow.hidden = true;
|
||||
}
|
||||
|
||||
var type = Zotero.Libraries.get(this.item.libraryID).libraryType;
|
||||
var switherDeck = this._id('attachment-note-editor-switcher');
|
||||
switherDeck.selectedIndex = type == 'user' ? 1 : 0;
|
||||
// Note editor
|
||||
if (type == 'user') {
|
||||
var noteEditor = this._id('attachment-note-editor');
|
||||
}
|
||||
else {
|
||||
var noteEditor = this._id('attachment-note-editor-old');
|
||||
}
|
||||
|
||||
if (this.displayNote && (this.displayNoteIfEmpty || this.item.note != '')) {
|
||||
noteEditor.linksOnTop = true;
|
||||
noteEditor.hidden = false;
|
||||
|
@ -624,7 +633,10 @@
|
|||
</grid>
|
||||
</vbox>
|
||||
|
||||
<deck id="attachment-note-editor-switcher" flex="1">
|
||||
<oldzoteronoteeditor id="attachment-note-editor-old" notitle="1" flex="1"/>
|
||||
<zoteronoteeditor id="attachment-note-editor" notitle="1" flex="1"/>
|
||||
</deck>
|
||||
|
||||
<button id="select-button" hidden="true"/>
|
||||
</vbox>
|
||||
|
|
|
@ -255,29 +255,45 @@ var ZoteroItemPane = new function() {
|
|||
}
|
||||
|
||||
|
||||
this.switchEditorEngine = function (type) {
|
||||
var switherDeck = document.getElementById('zotero-note-editor-switcher');
|
||||
switherDeck.selectedIndex = type == 'user' ? 1 : 0;
|
||||
};
|
||||
|
||||
|
||||
this.onNoteSelected = function (item, editable) {
|
||||
_selectedNoteID = item.id;
|
||||
|
||||
// If an external note window is open for this item, don't show the editor
|
||||
// if (ZoteroPane.findNoteWindow(item.id)) {
|
||||
// this.showNoteWindowMessage();
|
||||
// return;
|
||||
// }
|
||||
|
||||
var type = Zotero.Libraries.get(item.libraryID).libraryType;
|
||||
if (type == 'user') {
|
||||
var noteEditor = document.getElementById('zotero-note-editor');
|
||||
|
||||
noteEditor.mode = editable ? 'edit' : 'view';
|
||||
noteEditor.parent = null;
|
||||
noteEditor.item = item;
|
||||
}
|
||||
else {
|
||||
// If an external note window is open for this item, don't show the editor
|
||||
if (ZoteroPane.findNoteWindow(item.id)) {
|
||||
this.showNoteWindowMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
var noteEditor = document.getElementById('zotero-note-editor-old');
|
||||
|
||||
// If loading new or different note, disable undo while we repopulate the text field
|
||||
// so Undo doesn't end up clearing the field. This also ensures that Undo doesn't
|
||||
// undo content from another note into the current one.
|
||||
// var clearUndo = noteEditor.item ? noteEditor.item.id != item.id : false;
|
||||
var clearUndo = noteEditor.item ? noteEditor.item.id != item.id : false;
|
||||
|
||||
noteEditor.mode = editable ? 'edit' : 'view';
|
||||
noteEditor.parent = null;
|
||||
noteEditor.item = item;
|
||||
|
||||
// if (clearUndo) {
|
||||
// noteEditor.clearUndo();
|
||||
// }
|
||||
if (clearUndo) {
|
||||
noteEditor.clearUndo();
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('zotero-view-note-button').hidden = !editable;
|
||||
document.getElementById('zotero-item-pane-content').selectedIndex = 2;
|
||||
|
@ -285,7 +301,7 @@ var ZoteroItemPane = new function() {
|
|||
|
||||
|
||||
this.showNoteWindowMessage = function () {
|
||||
// ZoteroPane.setItemPaneMessage(Zotero.getString('pane.item.notes.editingInWindow'));
|
||||
ZoteroPane.setItemPaneMessage(Zotero.getString('pane.item.notes.editingInWindow'));
|
||||
};
|
||||
|
||||
|
||||
|
@ -295,6 +311,8 @@ var ZoteroItemPane = new function() {
|
|||
this.openNoteWindow = async function () {
|
||||
var selectedNote = Zotero.Items.get(_selectedNoteID);
|
||||
|
||||
var type = Zotero.Libraries.get(selectedNote.libraryID).libraryType;
|
||||
if (type == 'group') {
|
||||
// We don't want to show the note in two places, since it causes unnecessary UI updates
|
||||
// and can result in weird bugs where note content gets lost.
|
||||
//
|
||||
|
@ -306,6 +324,7 @@ var ZoteroItemPane = new function() {
|
|||
else {
|
||||
this.showNoteWindowMessage();
|
||||
}
|
||||
}
|
||||
ZoteroPane.openNoteWindow(selectedNote.id);
|
||||
};
|
||||
|
||||
|
|
|
@ -113,8 +113,13 @@
|
|||
'onerror' handler crashes the app on a save error to prevent typing in notes
|
||||
while they're not being saved
|
||||
-->
|
||||
<deck id="zotero-note-editor-switcher" flex="1">
|
||||
<oldzoteronoteeditor id="zotero-note-editor-old" flex="1" notitle="1"
|
||||
previousfocus="zotero-items-tree"
|
||||
onerror="ZoteroPane.displayErrorMessage(); this.mode = 'view'"/>
|
||||
<zoteronoteeditor id="zotero-note-editor" flex="1" notitle="1"
|
||||
previousfocus="zotero-items-tree"/>
|
||||
</deck>
|
||||
<button id="zotero-view-note-button"
|
||||
label="&zotero.notes.separate;"
|
||||
oncommand="ZoteroItemPane.openNoteWindow()"/>
|
||||
|
|
|
@ -25,14 +25,14 @@
|
|||
|
||||
var noteEditor;
|
||||
var notifierUnregisterID;
|
||||
var type;
|
||||
|
||||
function switchEditorEngine(type) {
|
||||
var switherDeck = document.getElementById('zotero-note-editor-switcher');
|
||||
switherDeck.selectedIndex = type === 'user' ? 1 : 0;
|
||||
}
|
||||
|
||||
async function onLoad() {
|
||||
noteEditor = document.getElementById('zotero-note-editor');
|
||||
noteEditor.mode = 'edit';
|
||||
|
||||
// Set font size from pref
|
||||
Zotero.setFontSize(noteEditor);
|
||||
|
||||
if (window.arguments) {
|
||||
var io = window.arguments[0];
|
||||
}
|
||||
|
@ -41,6 +41,35 @@ async function onLoad() {
|
|||
var collectionID = parseInt(io.collectionID);
|
||||
var parentItemKey = io.parentItemKey;
|
||||
|
||||
if (itemID) {
|
||||
var ref = await Zotero.Items.getAsync(itemID);
|
||||
var libraryID = ref.libraryID;
|
||||
}
|
||||
else {
|
||||
if (parentItemKey) {
|
||||
var ref = Zotero.Items.getByLibraryAndKey(parentItemKey);
|
||||
var libraryID = ref.libraryID;
|
||||
}
|
||||
else {
|
||||
if (collectionID && collectionID != '' && collectionID != 'undefined') {
|
||||
var collection = Zotero.Collections.get(collectionID);
|
||||
var libraryID = collection.libraryID;
|
||||
}
|
||||
}
|
||||
}
|
||||
type = Zotero.Libraries.get(libraryID).libraryType;
|
||||
switchEditorEngine(type);
|
||||
if (type === 'group') {
|
||||
noteEditor = document.getElementById('zotero-note-editor-old');
|
||||
}
|
||||
else {
|
||||
noteEditor = document.getElementById('zotero-note-editor');
|
||||
}
|
||||
noteEditor.mode = 'edit';
|
||||
|
||||
// Set font size from pref
|
||||
Zotero.setFontSize(noteEditor);
|
||||
|
||||
if (itemID) {
|
||||
var ref = await Zotero.Items.getAsync(itemID);
|
||||
noteEditor.item = ref;
|
||||
|
@ -77,7 +106,14 @@ function onError() {
|
|||
|
||||
function onUnload() {
|
||||
Zotero.Notifier.unregisterObserver(notifierUnregisterID);
|
||||
if (type == 'user') {
|
||||
noteEditor.saveSync();
|
||||
}
|
||||
else {
|
||||
if (noteEditor.item) {
|
||||
window.opener.ZoteroPane.onNoteWindowClosed(noteEditor.item.id, noteEditor.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var NotifyCallback = {
|
||||
|
|
|
@ -22,5 +22,8 @@
|
|||
</keyset>
|
||||
<command id="cmd_close" oncommand="window.close();"/>
|
||||
|
||||
<deck id="zotero-note-editor-switcher" flex="1">
|
||||
<oldzoteronoteeditor id="zotero-note-editor-old" flex="1" onerror="onError()"/>
|
||||
<zoteronoteeditor id="zotero-note-editor" flex="1" onerror="return;onError()"/>
|
||||
</deck>
|
||||
</window>
|
||||
|
|
|
@ -1198,6 +1198,7 @@ var ZoteroPane = new function()
|
|||
|
||||
// Rename tab
|
||||
Zotero_Tabs.rename('zotero-pane', collectionTreeRow.getName());
|
||||
ZoteroItemPane.switchEditorEngine(Zotero.Libraries.get(collectionTreeRow.ref.libraryID).libraryType);
|
||||
|
||||
// Clear quick search and tag selector when switching views
|
||||
document.getElementById('zotero-tb-search').value = "";
|
||||
|
@ -3556,6 +3557,19 @@ var ZoteroPane = new function()
|
|||
};
|
||||
|
||||
|
||||
this.onNoteWindowClosed = async function (itemID, noteText) {
|
||||
var item = Zotero.Items.get(itemID);
|
||||
item.setNote(noteText);
|
||||
await item.saveTx();
|
||||
|
||||
// If note is still selected, show the editor again when the note window closes
|
||||
var selectedItems = this.getSelectedItems(true);
|
||||
if (selectedItems.length == 1 && itemID == selectedItems[0]) {
|
||||
ZoteroItemPane.onNoteSelected(item, this.collectionsView.editable);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.openBackupNoteWindow = function (itemID) {
|
||||
if (!this.canEdit()) {
|
||||
this.displayCannotEditLibraryMessage();
|
||||
|
|
Loading…
Reference in a new issue