Add utility functions for building drop-down library lists
A XUL one for the current use in Advanced Search and an HTML one for future uses. Sets the value to libraryID and adds data attributes for editable/filesEditable on the HTML one.
This commit is contained in:
parent
36436d0b43
commit
045f1fbb7e
|
@ -49,7 +49,16 @@
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
this.searchRef = val;
|
this.searchRef = val;
|
||||||
|
|
||||||
this.buildLibraryMenu();
|
var libraryMenu = this.id('libraryMenu');
|
||||||
|
var libraries = Zotero.Libraries.getAll();
|
||||||
|
Zotero.Utilities.Internal.buildLibraryMenu(
|
||||||
|
libraryMenu, libraries, this.searchRef.libraryID
|
||||||
|
);
|
||||||
|
if (this.searchRef.id) {
|
||||||
|
libraryMenu.disabled = true;
|
||||||
|
}
|
||||||
|
this.updateLibrary();
|
||||||
|
|
||||||
|
|
||||||
var conditionsBox = this.id('conditions');
|
var conditionsBox = this.id('conditions');
|
||||||
while(conditionsBox.hasChildNodes())
|
while(conditionsBox.hasChildNodes())
|
||||||
|
@ -81,43 +90,6 @@
|
||||||
</setter>
|
</setter>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
<method name="buildLibraryMenu">
|
|
||||||
<body><![CDATA[
|
|
||||||
var menulist = this.id('libraryMenu');
|
|
||||||
var menupopup = menulist.firstChild;
|
|
||||||
|
|
||||||
while (menupopup.hasChildNodes()) {
|
|
||||||
menupopup.removeChild(menupopup.firstChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
var libraryID = this.searchRef.libraryID;
|
|
||||||
var libraryIndex = 0;
|
|
||||||
|
|
||||||
var libraries = Zotero.Libraries.getAll();
|
|
||||||
var selectedIndex = 0;
|
|
||||||
var i = 0;
|
|
||||||
for (let library of libraries) {
|
|
||||||
let menuitem = document.createElement('menuitem');
|
|
||||||
menuitem.setAttribute('label', library.name);
|
|
||||||
menuitem.setAttribute('libraryID', library.libraryID);
|
|
||||||
menupopup.appendChild(menuitem);
|
|
||||||
if (library.libraryID == libraryID) {
|
|
||||||
selectedIndex = i;
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
menulist.appendChild(menupopup);
|
|
||||||
menulist.selectedIndex = selectedIndex;
|
|
||||||
|
|
||||||
if (this.searchRef.id) {
|
|
||||||
this.id('libraryMenu').disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateLibrary();
|
|
||||||
]]></body>
|
|
||||||
</method>
|
|
||||||
|
|
||||||
<method name="addCondition">
|
<method name="addCondition">
|
||||||
<parameter name="ref"/>
|
<parameter name="ref"/>
|
||||||
<body>
|
<body>
|
||||||
|
@ -170,7 +142,7 @@
|
||||||
<method name="updateLibrary">
|
<method name="updateLibrary">
|
||||||
<body><![CDATA[
|
<body><![CDATA[
|
||||||
var menu = this.id('libraryMenu');
|
var menu = this.id('libraryMenu');
|
||||||
var libraryID = parseInt(menu.selectedItem.getAttribute('libraryID'));
|
var libraryID = parseInt(menu.selectedItem.value);
|
||||||
|
|
||||||
if (this.onLibraryChange) {
|
if (this.onLibraryChange) {
|
||||||
this.onLibraryChange(libraryID);
|
this.onLibraryChange(libraryID);
|
||||||
|
|
|
@ -986,7 +986,52 @@ Zotero.Utilities.Internal = {
|
||||||
return parts.join('-');
|
return parts.join('-');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
buildLibraryMenu: function (menulist, libraries, selectedLibraryID) {
|
||||||
|
var menupopup = menulist.firstChild;
|
||||||
|
while (menupopup.hasChildNodes()) {
|
||||||
|
menupopup.removeChild(menupopup.firstChild);
|
||||||
|
}
|
||||||
|
var selectedIndex = 0;
|
||||||
|
var i = 0;
|
||||||
|
for (let library of libraries) {
|
||||||
|
let menuitem = menulist.ownerDocument.createElement('menuitem');
|
||||||
|
menuitem.value = library.libraryID;
|
||||||
|
menuitem.setAttribute('label', library.name);
|
||||||
|
menupopup.appendChild(menuitem);
|
||||||
|
if (library.libraryID == selectedLibraryID) {
|
||||||
|
selectedIndex = i;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
menulist.appendChild(menupopup);
|
||||||
|
menulist.selectedIndex = selectedIndex;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
buildLibraryMenuHTML: function (select, libraries, selectedLibraryID) {
|
||||||
|
var namespaceURI = 'http://www.w3.org/1999/xhtml';
|
||||||
|
while (select.hasChildNodes()) {
|
||||||
|
select.removeChild(select.firstChild);
|
||||||
|
}
|
||||||
|
var selectedIndex = 0;
|
||||||
|
var i = 0;
|
||||||
|
for (let library of libraries) {
|
||||||
|
let option = select.ownerDocument.createElementNS(namespaceURI, 'option');
|
||||||
|
option.setAttribute('value', library.libraryID);
|
||||||
|
option.setAttribute('data-editable', library.editable ? 'true' : 'false');
|
||||||
|
option.setAttribute('data-filesEditable', library.filesEditable ? 'true' : 'false');
|
||||||
|
option.textContent = library.name;
|
||||||
|
select.appendChild(option);
|
||||||
|
if (library.libraryID == selectedLibraryID) {
|
||||||
|
option.setAttribute('selected', 'selected');
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a libraryOrCollection DOM tree to place in <menupopup> element.
|
* Create a libraryOrCollection DOM tree to place in <menupopup> element.
|
||||||
* If has no children, returns a <menuitem> element, otherwise <menu>.
|
* If has no children, returns a <menuitem> element, otherwise <menu>.
|
||||||
|
|
|
@ -202,7 +202,7 @@ describe("Advanced Search", function () {
|
||||||
for (let i = 0; i < libraryMenu.itemCount; i++) {
|
for (let i = 0; i < libraryMenu.itemCount; i++) {
|
||||||
let menuitem = libraryMenu.getItemAtIndex(i);
|
let menuitem = libraryMenu.getItemAtIndex(i);
|
||||||
// Switch to group library
|
// Switch to group library
|
||||||
if (menuitem.getAttribute('libraryID') == groupLibraryID) {
|
if (menuitem.value == groupLibraryID) {
|
||||||
menuitem.click();
|
menuitem.click();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user