commit 877b8741ae2f78e7cb2ddbfe31957cedfdf17cf1
parent efda43f6e39bfe16c2852fbf59a424fa69018f9d
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 1 May 2013 23:58:04 -0400
Fix some tag bugs from efda43f6e3 (and maybe also earlier?)
Diffstat:
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
@@ -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<items; i++) {
+ for (let i=0; i<items.length; i++) {
this._linkedItems[items[i].id] = items[i];
}
// Mark items not found for removal
for (let i=0; i<itemIDs.length; i++) {
- if (!this._linkedItemIDs[id]) {
+ let id = itemIDs[i];
+ if (!this._linkedItems[id]) {
this._linkedItemIDsToRemove.push(id);
}
}