Update related box if related items are renamed or deleted
This commit is contained in:
parent
61e3e339bb
commit
647afbb089
2 changed files with 84 additions and 7 deletions
|
@ -116,14 +116,25 @@
|
|||
<parameter name="ids"/>
|
||||
<parameter name="extraData"/>
|
||||
<body><![CDATA[
|
||||
if (event != 'modify' || !this.item || !this.item.id) return;
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
let id = ids[i];
|
||||
if (id != this.item.id) {
|
||||
continue;
|
||||
}
|
||||
if (!this.item || !this.item.id) return;
|
||||
|
||||
// Refresh if this item has been modified
|
||||
if (event == 'modify' && ids.includes(this.item.id)) {
|
||||
this.refresh();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
// Or if any listed items have been modified or deleted
|
||||
if (event == 'modify' || event == 'delete') {
|
||||
let libraryID = this.item.libraryID;
|
||||
let relatedItemIDs = new Set(this.item.relatedItems
|
||||
.map(key => Zotero.Items.getIDFromLibraryAndKey(libraryID, key)));
|
||||
for (let id of ids) {
|
||||
if (relatedItemIDs.has(id)) {
|
||||
this.refresh();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
|
|
@ -12,6 +12,72 @@ describe("Related Box", function () {
|
|||
win.close();
|
||||
})
|
||||
|
||||
it("should update if a related item is renamed", async function () {
|
||||
var title1 = 'aaaaaa';
|
||||
var title2 = 'bbbbbb';
|
||||
var item1 = await createDataObject('item', { title: title1 });
|
||||
var item2 = await createDataObject('item', { title: title2 });
|
||||
item1.addRelatedItem(item2);
|
||||
await item1.saveTx();
|
||||
item2.addRelatedItem(item1);
|
||||
await item2.saveTx();
|
||||
|
||||
// Select the Related pane
|
||||
var tabbox = doc.getElementById('zotero-view-tabbox');
|
||||
tabbox.selectedIndex = 3;
|
||||
var relatedbox = doc.getElementById('zotero-editpane-related');
|
||||
|
||||
// Wait for relations list to populate
|
||||
do {
|
||||
await Zotero.Promise.delay(50);
|
||||
}
|
||||
while (!relatedbox.id('relatedRows').childNodes.length);
|
||||
|
||||
assert.include(doc.getAnonymousNodes(relatedbox)[0].innerHTML, title1);
|
||||
|
||||
title1 = 'cccccc';
|
||||
item1.setField('title', title1);
|
||||
await item1.saveTx();
|
||||
|
||||
// New title should appear in list
|
||||
do {
|
||||
await Zotero.Promise.delay(50);
|
||||
}
|
||||
while (!doc.getAnonymousNodes(relatedbox)[0].innerHTML.includes(title1));
|
||||
});
|
||||
|
||||
it("should update if a related item is deleted", async function () {
|
||||
var title1 = 'aaaaaa';
|
||||
var title2 = 'bbbbbb';
|
||||
var item1 = await createDataObject('item', { title: title1 });
|
||||
var item2 = await createDataObject('item', { title: title2 });
|
||||
item1.addRelatedItem(item2);
|
||||
await item1.saveTx();
|
||||
item2.addRelatedItem(item1);
|
||||
await item2.saveTx();
|
||||
|
||||
// Select the Related pane
|
||||
var tabbox = doc.getElementById('zotero-view-tabbox');
|
||||
tabbox.selectedIndex = 3;
|
||||
var relatedbox = doc.getElementById('zotero-editpane-related');
|
||||
|
||||
// Wait for relations list to populate
|
||||
do {
|
||||
await Zotero.Promise.delay(50);
|
||||
}
|
||||
while (!relatedbox.id('relatedRows').childNodes.length);
|
||||
|
||||
assert.include(doc.getAnonymousNodes(relatedbox)[0].innerHTML, title1);
|
||||
|
||||
await item1.eraseTx();
|
||||
|
||||
// Deleted item should be removed from list
|
||||
do {
|
||||
await Zotero.Promise.delay(50);
|
||||
}
|
||||
while (doc.getAnonymousNodes(relatedbox)[0].innerHTML.includes(title1));
|
||||
});
|
||||
|
||||
describe("Add button", function () {
|
||||
it("should add a related item", function* () {
|
||||
var item1 = yield createDataObject('item');
|
||||
|
|
Loading…
Reference in a new issue