2019-02-24 23:57:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
class BreadcrumbListing {
|
|
|
|
|
|
|
|
constructor(elem) {
|
|
|
|
this.elem = elem;
|
|
|
|
this.searchInput = elem.querySelector('input');
|
|
|
|
this.loadingElem = elem.querySelector('.loading-container');
|
|
|
|
this.entityListElem = elem.querySelector('.breadcrumb-listing-entity-list');
|
|
|
|
|
|
|
|
// this.loadingElem.style.display = 'none';
|
|
|
|
const entityDescriptor = elem.getAttribute('breadcrumb-listing').split(':');
|
|
|
|
this.entityType = entityDescriptor[0];
|
|
|
|
this.entityId = Number(entityDescriptor[1]);
|
|
|
|
|
2019-08-25 01:26:28 +08:00
|
|
|
this.elem.addEventListener('show', this.onShow.bind(this));
|
2019-02-24 23:57:35 +08:00
|
|
|
this.searchInput.addEventListener('input', this.onSearch.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
this.loadEntityView();
|
|
|
|
}
|
|
|
|
|
|
|
|
onSearch() {
|
|
|
|
const input = this.searchInput.value.toLowerCase().trim();
|
|
|
|
const listItems = this.entityListElem.querySelectorAll('.entity-list-item');
|
|
|
|
for (let listItem of listItems) {
|
|
|
|
const match = !input || listItem.textContent.toLowerCase().includes(input);
|
|
|
|
listItem.style.display = match ? 'flex' : 'none';
|
2019-06-04 18:25:19 +08:00
|
|
|
listItem.classList.toggle('hidden', !match);
|
2019-02-24 23:57:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loadEntityView() {
|
|
|
|
this.toggleLoading(true);
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
'entity_id': this.entityId,
|
|
|
|
'entity_type': this.entityType,
|
|
|
|
};
|
|
|
|
|
2019-06-08 07:02:51 +08:00
|
|
|
window.$http.get('/search/entity/siblings', params).then(resp => {
|
2019-02-24 23:57:35 +08:00
|
|
|
this.entityListElem.innerHTML = resp.data;
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
}).then(() => {
|
|
|
|
this.toggleLoading(false);
|
|
|
|
this.onSearch();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleLoading(show = false) {
|
|
|
|
this.loadingElem.style.display = show ? 'block' : 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BreadcrumbListing;
|