From 877b8741ae2f78e7cb2ddbfe31957cedfdf17cf1 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 1 May 2013 23:58:04 -0400 Subject: [PATCH] Fix some tag bugs from efda43f6e3 (and maybe also earlier?) --- chrome/content/zotero/xpcom/data/tag.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/tag.js b/chrome/content/zotero/xpcom/data/tag.js index fb67b9a90..810a142f3 100644 --- a/chrome/content/zotero/xpcom/data/tag.js +++ b/chrome/content/zotero/xpcom/data/tag.js @@ -502,8 +502,6 @@ Zotero.Tag.prototype.save = function (full) { this._key = key; } - Zotero.Tags.reload(this.id); - if (isNew) { Zotero.Notifier.trigger('add', 'tag', this.id); } @@ -511,6 +509,9 @@ Zotero.Tag.prototype.save = function (full) { Zotero.Notifier.trigger('modify', 'tag', this.id, this._previousData); } + this._reset(); + Zotero.Tags.reload(this.id); + return this.id; } @@ -644,10 +645,23 @@ Zotero.Tag.prototype.erase = function () { Zotero.DB.commitTransaction(); + this._reset(); + Zotero.Prefs.set('purge.tags', true); } +Zotero.Tag.prototype._reset = function () { + var id = this._id; + var libraryID = this._libraryID; + var key = this._key; + this._init(); + this._id = id; + this._libraryID = libraryID; + this._key = key; +} + + Zotero.Tag.prototype._loadLinkedItems = function() { if (!this.id && !this.key) { this._linkedItemsLoaded = true; @@ -709,7 +723,7 @@ Zotero.Tag.prototype._setLinkedItems = function (itemIDs) { throw new Error("Invalid itemID '" + itemIDs[i] + "'"); } - if (this._linkedItemIDs[id]) { + if (this._linkedItems[id]) { Zotero.debug("Item " + id + " is already linked to tag " + this.id); } else { @@ -728,13 +742,14 @@ Zotero.Tag.prototype._setLinkedItems = function (itemIDs) { // Rebuild linked items with items that exist var items = Zotero.Items.get(itemIDs) || []; this._linkedItems = {}; - for (let i=0; i