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)
This commit is contained in:
Dan Stillman 2015-01-28 17:25:17 -05:00
parent b785a3bfce
commit 8499ec6211
4 changed files with 15 additions and 10 deletions

View file

@ -362,7 +362,7 @@ Zotero.Collection.prototype._finalizeSave = Zotero.Promise.coroutine(function* (
Zotero.Notifier.trigger('add', 'collection', this.id); Zotero.Notifier.trigger('add', 'collection', this.id);
} }
else { else {
Zotero.Notifier.trigger('modify', 'collection', this.id, this._previousData); Zotero.Notifier.trigger('modify', 'collection', this.id, { changed: this._previousData });
} }
// Invalidate cached child collections // Invalidate cached child collections

View file

@ -1218,9 +1218,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
sqlValues.push(parseInt(itemID)); sqlValues.push(parseInt(itemID));
yield Zotero.DB.queryAsync(sql, sqlValues); yield Zotero.DB.queryAsync(sql, sqlValues);
var notifierData = {}; Zotero.Notifier.trigger('modify', 'item', itemID, { changed: this._previousData });
notifierData[itemID] = { changed: this._previousData };
Zotero.Notifier.trigger('modify', 'item', itemID, notifierData);
} }
// //

View file

@ -138,11 +138,18 @@ Zotero.Notifier = new function(){
// Merge extraData keys // Merge extraData keys
if (extraData) { if (extraData) {
Zotero.debug("ADDING EXTRA DATA"); Zotero.debug("ADDING EXTRA DATA");
for (var dataID in extraData) { // If just a single id, extra data can be keyed by id or passed directly
Zotero.debug(dataID); if (ids.length == 1) {
if (extraData[dataID]) { let id = ids[0];
Zotero.debug("YES"); _queue[type][event].data[id] = extraData[id] ? extraData[id] : extraData;
_queue[type][event].data[dataID] = extraData[dataID]; }
// 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];
}
} }
} }
} }

View file

@ -260,7 +260,7 @@ Zotero.Search.prototype._finalizeSave = Zotero.Promise.coroutine(function* (env)
Zotero.Notifier.trigger('add', 'search', this.id); Zotero.Notifier.trigger('add', 'search', this.id);
} }
else { 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)) { if (isNew && Zotero.Libraries.isGroupLibrary(this.libraryID)) {