From 383b6a70800b078f984b77e2c366b43796ca19be Mon Sep 17 00:00:00 2001 From: Pranam Lashkari Date: Wed, 4 Jan 2023 00:47:18 +0530 Subject: [PATCH] zotero: implement citation refresh Signed-off-by: Pranam Lashkari Change-Id: Id91acbed6c651dfed02777d7fa4142edf597a55a --- browser/src/control/Control.Menubar.js | 10 ++-------- browser/src/control/Control.Zotero.js | 8 ++++++++ browser/src/control/Toolbar.js | 5 +++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/browser/src/control/Control.Menubar.js b/browser/src/control/Control.Menubar.js index 03e253663..d688538a8 100644 --- a/browser/src/control/Control.Menubar.js +++ b/browser/src/control/Control.Menubar.js @@ -1843,14 +1843,8 @@ L.Control.Menubar = L.Control.extend({ this._map.sendUnoCommand('.uno:LOKSidebarWriterPage'); this._map.fire('showwizardsidebar', {noRefresh: true}); window.pageMobileWizard = true; - } else if (id === 'zoteroaddeditbibliography') { - this._map.dispatch('zoteroaddeditbibliography'); - } else if (id === 'zoteroaddeditcitation') { - this._map.dispatch('zoteroaddeditcitation'); - } else if (id === 'zoterosetdocprefs') { - this._map.dispatch('zoterosetdocprefs'); - } else if (id === 'zoteroaddnote') { - this._map.dispatch('zoteroaddnote'); + } else if (id.startsWith('zotero')) { + this._map.dispatch(id); } // Inform the host if asked if (postmessage) diff --git a/browser/src/control/Control.Zotero.js b/browser/src/control/Control.Zotero.js index b614ce382..0628b8cf1 100644 --- a/browser/src/control/Control.Zotero.js +++ b/browser/src/control/Control.Zotero.js @@ -966,6 +966,14 @@ L.Control.Zotero = L.Control.extend({ }); }, + refreshCitations: function() { + //discard the cached url and fetch fresh one + var refreshURL = 'https://api.zotero.org/users/' + this.userID + '/items/top' + this.getZoteroItemQuery() + '&itemKey=' + this.getCitationKeys().join(','); + if (this._cachedURL[refreshURL]) + delete this._cachedURL[refreshURL]; + this.updateCitations(); + }, + _onMessage: function(message) { if (message.startsWith('itemslist: ')) { this.handleItemList(message); diff --git a/browser/src/control/Toolbar.js b/browser/src/control/Toolbar.js index f9f7c4249..e41673962 100644 --- a/browser/src/control/Toolbar.js +++ b/browser/src/control/Toolbar.js @@ -875,6 +875,11 @@ L.Map.include({ this.zotero.handleInsertNote(); } break; + case 'zoterorefresh': + { + this.zotero.refreshCitations(); + } + break; case 'exportpdf': { this.sendUnoCommand('.uno:ExportToPDF', {