From 2ad0dc00daa945f22041612639abfcb001b96408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Mon, 16 Oct 2017 14:05:23 +0300 Subject: [PATCH] Add session.getItems in preparation for document collections --- chrome/content/zotero/xpcom/cite.js | 2 +- chrome/content/zotero/xpcom/integration.js | 29 +++++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index afcc210cc..0745c4375 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -303,7 +303,7 @@ Zotero.Cite = { session = Zotero.Integration.sessions[sessionID], item; if(session) { - item = session.embeddedZoteroItems[id.substr(slashIndex+1)]; + item = session.embeddedItems[id.substr(slashIndex+1)]; } if(!item) { diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 2d82a8d04..fa68d77cd 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -231,6 +231,8 @@ Zotero.Integration = new function() { // TODO: this is pretty awful session.fields = new Zotero.Integration.Fields(session, document); session._doc = document; + // TODO: figure this out + // Zotero.Notifier.trigger('delete', 'collection', 'document'); yield (new Zotero.Integration.Interface(application, document, session))[command](); document.setDocumentData(session.data.serialize()); } @@ -304,8 +306,7 @@ Zotero.Integration = new function() { inProgress = Zotero.Integration.currentDoc = - Zotero.Integration.currentWindow = - Zotero.Integration.currentSession = false; + Zotero.Integration.currentWindow = false; } }); }; @@ -906,6 +907,8 @@ Zotero.Integration.Fields.prototype._processFields = Zotero.Promise.coroutine(fu this._session.bibliography = new Zotero.Integration.Bibliography(this._bibliographyFields[0]); yield this._session.bibliography.loadItemData(); } + // TODO: figure this out + // Zotero.Notifier.trigger('add', 'collection', 'document'); }); /** @@ -1263,7 +1266,7 @@ Zotero.Integration.CitationEditInterface.prototype = { return indexB - indexA; }); - return Zotero.Cite.getItem(ids); + return Zotero.Cite.getItem(ids); }), } @@ -1271,10 +1274,8 @@ Zotero.Integration.CitationEditInterface.prototype = { * Keeps track of all session-specific variables */ Zotero.Integration.Session = function(doc, app) { - // holds items not in document that should be in bibliography this.embeddedItems = {}; - this.embeddedZoteroItems = {}; - this.embeddedZoteroItemsByURI = {}; + this.embeddedItemsByURI = {}; this.resetRequest(doc); this.primaryFieldType = app.primaryFieldType; this.secondaryFieldType = app.secondaryFieldType; @@ -1619,6 +1620,11 @@ Zotero.Integration.Session.prototype.writeDelayedCitation = Zotero.Promise.corou }); +Zotero.Integration.Session.prototype.getItems = function() { + return Zotero.Cite.getItem(Object.keys(this.citationsByItemID)); +} + + /** * Edits integration bibliography * @param {Zotero.Integration.Bibliography} bibliography @@ -1903,8 +1909,8 @@ Zotero.Integration.URIMap.prototype.getZoteroItemForURIs = Zotero.Promise.corout var uri = uris[i]; // First try embedded URI - if(this.session.embeddedZoteroItemsByURI[uri]) { - embeddedItem = this.session.embeddedZoteroItemsByURI[uri]; + if(this.session.embeddedItemsByURI[uri]) { + embeddedItem = this.session.embeddedItemsByURI[uri]; } // Next try getting URI directly @@ -2316,17 +2322,16 @@ Zotero.Integration.Citation = class { // assign a random string as an item ID var anonymousID = Zotero.randomString(); var globalID = itemData.id = citationItem.id = Zotero.Integration.currentSession.data.sessionID+"/"+anonymousID; - Zotero.Integration.currentSession.embeddedItems[anonymousID] = itemData; // assign a Zotero item - var surrogateItem = Zotero.Integration.currentSession.embeddedZoteroItems[anonymousID] = new Zotero.Item(); + var surrogateItem = Zotero.Integration.currentSession.embeddedItems[anonymousID] = new Zotero.Item(); Zotero.Utilities.itemFromCSLJSON(surrogateItem, itemData); surrogateItem.cslItemID = globalID; surrogateItem.cslURIs = citationItem.uris; surrogateItem.cslItemData = itemData; for(var j=0, m=citationItem.uris.length; j