From 8499ec6211717f9040d4e1531bbe801ba763c249 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 28 Jan 2015 17:25:17 -0500 Subject: [PATCH] Allow extra data for single-object notifications to be passed directly Previous it had to be keyed by id (and still can be, but if there's only a single id the notifier will now key it automatically) --- chrome/content/zotero/xpcom/data/collection.js | 2 +- chrome/content/zotero/xpcom/data/item.js | 4 +--- chrome/content/zotero/xpcom/notifier.js | 17 ++++++++++++----- chrome/content/zotero/xpcom/search.js | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 0244b578d..4e1c1e6ce 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -362,7 +362,7 @@ Zotero.Collection.prototype._finalizeSave = Zotero.Promise.coroutine(function* ( Zotero.Notifier.trigger('add', 'collection', this.id); } else { - Zotero.Notifier.trigger('modify', 'collection', this.id, this._previousData); + Zotero.Notifier.trigger('modify', 'collection', this.id, { changed: this._previousData }); } // Invalidate cached child collections diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 17129b637..2c0a12c3d 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1218,9 +1218,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { sqlValues.push(parseInt(itemID)); yield Zotero.DB.queryAsync(sql, sqlValues); - var notifierData = {}; - notifierData[itemID] = { changed: this._previousData }; - Zotero.Notifier.trigger('modify', 'item', itemID, notifierData); + Zotero.Notifier.trigger('modify', 'item', itemID, { changed: this._previousData }); } // diff --git a/chrome/content/zotero/xpcom/notifier.js b/chrome/content/zotero/xpcom/notifier.js index 8983917c4..757d529a3 100644 --- a/chrome/content/zotero/xpcom/notifier.js +++ b/chrome/content/zotero/xpcom/notifier.js @@ -138,11 +138,18 @@ Zotero.Notifier = new function(){ // Merge extraData keys if (extraData) { Zotero.debug("ADDING EXTRA DATA"); - for (var dataID in extraData) { - Zotero.debug(dataID); - if (extraData[dataID]) { - Zotero.debug("YES"); - _queue[type][event].data[dataID] = extraData[dataID]; + // If just a single id, extra data can be keyed by id or passed directly + if (ids.length == 1) { + let id = ids[0]; + _queue[type][event].data[id] = extraData[id] ? extraData[id] : extraData; + } + // For multiple ids, check for data keyed by the id + else { + for (let i = 0; i < ids.length; i++) { + let id = ids[i]; + if (extraData[id]) { + _queue[type][event].data[id] = extraData[id]; + } } } } diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index cee68a6aa..9a2bd7d6e 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -260,7 +260,7 @@ Zotero.Search.prototype._finalizeSave = Zotero.Promise.coroutine(function* (env) Zotero.Notifier.trigger('add', 'search', this.id); } else { - Zotero.Notifier.trigger('modify', 'search', this.id, this._previousData); + Zotero.Notifier.trigger('modify', 'search', this.id, { changed: this._previousData }); } if (isNew && Zotero.Libraries.isGroupLibrary(this.libraryID)) {