1)
{
continue;
}
itemIDs = itemIDs.concat(this.serialize(trie[key]));
}
if ( trie.isComplete )
{
itemIDs.push(...trie.ids);
}
return itemIDs;
}
collate(trees)
{
/*
takes a list of tries
returns a list of ids of objects that are available
*/
const results = [];
for( const tree of trees )
{
const available_IDs = this.serialize(tree);
for( const itemID of available_IDs ) {
results[itemID] = this.items[itemID];
}
}
return results;
}
generate_element_text(obj)
{
const content_strings = [obj.expanded_name, obj.small_name, obj.string].filter(x => Boolean(x));
const result = content_strings.shift();
if( result == null || content_strings.length < 1) {
return result;
} else {
return result + " (" + content_strings.join(", ") + ")";
}
}
dropdown(ids)
{
/*
takes in a mapping of ids to objects in items
and displays them in the dropdown
*/
const drop = document.getElementById("drop_results");
while(drop.firstChild)
{
drop.removeChild(drop.firstChild);
}
for( const id in ids )
{
const result_entry = document.createElement("li");
const result_button = document.createElement("a");
const obj = this.items[id];
const result_text = this.generate_element_text(obj);
result_entry.classList.add("list-group-item", "list-group-item-action");
result_entry.innerText = result_text;
result_entry.onclick = function() { searchable_select_multiple_widget.select_item(obj.id); };
const tooltip = document.createElement("span");
const tooltiptext = document.createTextNode(result_text);
tooltip.appendChild(tooltiptext);
tooltip.classList.add("d-none");
result_entry.appendChild(tooltip);
drop.appendChild(result_entry);
}
const scroll_restrictor = document.getElementById("scroll_restrictor");
if( !drop.firstChild )
{
scroll_restrictor.style.visibility = 'hidden';
}
else
{
scroll_restrictor.style.visibility = 'inherit';
}
}
select_item(item_id)
{
if( (this.selectable_limit > -1 && this.added_items.size < this.selectable_limit) || this.selectable_limit < 0 )
{
this.added_items.add(item_id);
}
this.update_selected_list();
// clear search bar contents
document.getElementById("user_field").value = "";
document.getElementById("user_field").focus();
this.search("");
}
remove_item(item_id)
{
this.added_items.delete(item_id);
this.update_selected_list()
document.getElementById("user_field").focus();
}
update_selected_list()
{
document.getElementById("added_number").innerText = this.added_items.size;
const selector = document.getElementById('selector');
selector.value = JSON.stringify([...this.added_items]);
const added_list = document.getElementById('added_list');
while(selector.firstChild)
{
selector.removeChild(selector.firstChild);
}
while(added_list.firstChild)
{
added_list.removeChild(added_list.firstChild);
}
let list_html = "";
for( const item_id of this.added_items )
{
const item = this.items[item_id];
const element_entry_text = this.generate_element_text(item);
list_html += ''
+ element_entry_text
+ '';
list_html += '
';
}
added_list.innerHTML = list_html;
}
}