Fix some tag bugs from efda43f6e3 (and maybe also earlier?)

This commit is contained in:
Dan Stillman 2013-05-01 23:58:04 -04:00
parent efda43f6e3
commit 877b8741ae

View File

@ -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);
}
}