commit 8499ec6211717f9040d4e1531bbe801ba763c249
parent b785a3bfced493acf1051c4a93c83d962f9f185f
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 28 Jan 2015 17:25:17 -0500
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)
Diffstat:
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
@@ -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
@@ -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
@@ -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
@@ -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)) {