Zotero: don't show if integrator doesn't support

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I5d8ab1fda1760b038009f0bf13779cddbabfef09
This commit is contained in:
Szymon Kłos 2023-02-16 11:05:35 +01:00 committed by Andras Timar
parent add1e10447
commit a60fd0f508
2 changed files with 16 additions and 18 deletions

View file

@ -51,6 +51,9 @@ L.Control.UIManager = L.Control.extend({
event.target.parentElement.id === 'document-titlebar') { // checks if clicked on the document titlebar container
that.map.fire('editorgotfocus');}
});
if (window.zoteroEnabled)
this.map.on('updateviewslist', this.onUpdateViews, this);
},
// UI initialization
@ -114,10 +117,6 @@ L.Control.UIManager = L.Control.extend({
this.map.addControl(L.control.infobar());
this.map.userList = L.control.userList();
this.map.addControl(this.map.userList);
if (window.zoteroEnabled) {
this.map.zotero = L.control.zotero(this.map);
this.map.addControl(this.map.zotero);
}
var openBusyPopup = function(label) {
this.busyPopupTimer = setTimeout(function() {
@ -692,6 +691,19 @@ L.Control.UIManager = L.Control.extend({
this.map.invalidateSize();
},
onUpdateViews: function () {
var userPrivateInfo = this.map._docLayer ? this.map._viewInfo[this.map._docLayer._viewId].userprivateinfo : null;
if (userPrivateInfo) {
var apiKey = userPrivateInfo.ZoteroAPIKey;
if (apiKey) {
this.map.zotero = L.control.zotero(this.map);
this.map.zotero.apiKey = apiKey;
this.map.addControl(this.map.zotero);
this.map.zotero.updateUserID();
}
}
},
enterReadonlyOrClose: function() {
if (this.map.isEditMode()) {
// in edit mode, passing 'edit' actually enters readonly mode

View file

@ -38,7 +38,6 @@ L.Control.Zotero = L.Control.extend({
onAdd: function (map) {
this.map = map;
this.enable = false;
this.map.on('updateviewslist', this.onUpdateViews, this);
},
extractItemKeyFromLink: function(link) {
@ -121,10 +120,6 @@ L.Control.Zotero = L.Control.extend({
},
onRemove: function () {
this.map.off('updateviewslist', this.onUpdateViews, this);
},
askForApiKey: function () {
this.map.fire('postMessage', {msgId: 'UI_ZoteroKeyMissing'});
// if empty - integrator supports Zotero and will ask user to provide the key
@ -133,15 +128,6 @@ L.Control.Zotero = L.Control.extend({
this.map.uiManager.showSnackbar(_('Zotero API key is not configured'));
},
onUpdateViews: function () {
var userPrivateInfo = this.map._docLayer ? this.map._viewInfo[this.map._docLayer._viewId].userprivateinfo : null;
if (userPrivateInfo) {
this.apiKey = userPrivateInfo.ZoteroAPIKey;
if (this.apiKey)
this.updateUserID();
}
},
updateUserID: function () {
var that = this;
fetch('https://api.zotero.org/keys/' + this.apiKey)