Reset Collection search condition menu on library change

Reported here:
https://github.com/zotero/zotero/issues/145#issuecomment-252678872
This commit is contained in:
Dan Stillman 2016-10-11 23:55:17 -04:00
parent f0aafe4c21
commit bc47b6b171
2 changed files with 75 additions and 2 deletions

View file

@ -178,6 +178,8 @@
if (!this.searchRef.id) {
this.searchRef.libraryID = libraryID;
}
[...this.id('conditions').childNodes].forEach(x => x.onLibraryChange());
]]></body>
</method>
@ -448,12 +450,13 @@
<method name="onConditionSelected">
<parameter name="conditionName"/>
<parameter name="reload"/>
<body><![CDATA[
var conditionsMenu = this.id('conditionsmenu');
var operatorsList = this.id('operatorsmenu');
// Skip if no condition or correct condition already selected
if (!conditionName || conditionName == this.selectedCondition) {
if (!conditionName || (conditionName == this.selectedCondition && !reload)) {
return;
}
@ -701,7 +704,7 @@
this.id('conditionsmenu').focus();
]]></body>
</method>
<!-- Gets the value from the field and updates the associated search condition -->
<!-- Gets the value from the UI and updates the associated condition on the Zotero.Search object -->
<method name="updateSearch">
<body>
<![CDATA[
@ -812,6 +815,16 @@
return false;
]]></body></method>
<method name="onLibraryChange">
<body><![CDATA[
switch (this.selectedCondition) {
case 'collection':
this.onConditionSelected(this.selectedCondition, true);
break;
}
]]></body>
</method>
<method name="onRemoveClicked">
<body>
<![CDATA[

View file

@ -164,6 +164,66 @@ describe("Advanced Search", function () {
yield collection.eraseTx();
yield search.eraseTx();
});
it("should update when the library is changed", function* () {
var group = yield getGroup();
var groupLibraryID = group.libraryID;
var collection1 = yield createDataObject('collection', { name: "A" });
var search1 = yield createDataObject('search', { name: "B" });
var collection2 = yield createDataObject('collection', { name: "C", libraryID: groupLibraryID });
var search2 = yield createDataObject('search', { name: "D", libraryID: groupLibraryID });
var s = new Zotero.Search();
s.addCondition('title', 'is', '');
searchBox.search = s;
var searchCondition = conditions.firstChild;
var conditionsMenu = searchCondition.id('conditionsmenu');
var valueMenu = searchCondition.id('valuemenu');
// Select 'Collection' condition
for (let i = 0; i < conditionsMenu.itemCount; i++) {
let menuitem = conditionsMenu.getItemAtIndex(i);
if (menuitem.value == 'collection') {
menuitem.click();
break;
}
}
for (let i = 0; i < valueMenu.itemCount; i++) {
let menuitem = valueMenu.getItemAtIndex(i);
if (menuitem.getAttribute('value') == "S" + search1.key) {
menuitem.click();
break;
}
}
assert.equal(valueMenu.value, "S" + search1.key);
var libraryMenu = searchWin.document.getElementById('libraryMenu');
for (let i = 0; i < libraryMenu.itemCount; i++) {
let menuitem = libraryMenu.getItemAtIndex(i);
// Switch to group library
if (menuitem.getAttribute('libraryID') == groupLibraryID) {
menuitem.click();
break;
}
}
var values = [];
valueMenu = searchCondition.id('valuemenu')
assert.equal(valueMenu.value, "C" + collection2.key);
for (let i = 0; i < valueMenu.itemCount; i++) {
let menuitem = valueMenu.getItemAtIndex(i);
values.push(menuitem.getAttribute('value'));
}
assert.notInclude(values, "C" + collection1.key);
assert.notInclude(values, "S" + search1.key);
assert.include(values, "C" + collection2.key);
assert.include(values, "S" + search2.key);
yield Zotero.Collections.erase([collection1.id, collection2.id]);
yield Zotero.Searches.erase([search1.id, search2.id]);
});
});
describe("Saved Search", function () {