`,
overlayColor: isParentModal ? "transparent" : undefined,
cbClose: () => {
resolve(ui._getFormData());
rdState.pageFilterEntities.filterBox.teardown();
},
});
ui.pRender($modalInner, {rdState})
.catch(e => reject(e));
});
}
constructor ({brewUtil, brew, isModal}) {
super();
TabUiUtil.decorate(this, {isInitMeta: true});
this._brewUtil = brewUtil;
this._brew = MiscUtil.copyFast(brew);
this._isModal = isModal;
this._isDirty = false;
}
_getFormData () {
return {
isDirty: this._isDirty,
brew: this._brew,
};
}
_$getBtnDeleteSelected ({rdState}) {
return $(``)
.click(() => this._handleClick_pButtonDeleteSelected({rdState}));
}
async _handleClick_pButtonDeleteSelected ({rdState}) {
if (this._getActiveTab() === rdState.tabMetaEntities) return this._handleClick_pButtonDeleteSelected_entities({rdState});
if (this._getActiveTab() === rdState.tabMetaSources) return this._handleClick_pButtonDeleteSelected_sources({rdState});
// (The metadata tab does not have any selectable elements, so, no-op)
}
async _handleClick_pButtonDeleteSelected_entities ({rdState}) {
const listItemsSel = rdState.listEntities.items
.filter(it => it.data.cbSel.checked);
if (!listItemsSel.length) return;
if (!await InputUiUtil.pGetUserBoolean({title: "Delete Entities", htmlDescription: `Are you sure you want to delete the ${listItemsSel.length === 1 ? "selected entity" : `${listItemsSel.length} selected entities`}?`, textYes: "Yes", textNo: "Cancel"})) return;
this._isDirty = true;
// Remove the array items from our copy of the brew, and remove the corresponding list items
listItemsSel
.forEach(li => this._doEntityListDelete({rdState, li}));
rdState.listEntities.update();
}
_doEntityListDelete ({rdState, li}) {
const ix = this._brew.body[li.data.prop].indexOf(li.data.ent);
if (!~ix) return;
this._brew.body[li.data.prop].splice(ix, 1);
if (!this._brew.body[li.data.prop].length) delete this._brew.body[li.data.prop];
rdState.listEntities.removeItem(li);
}
async _handleClick_pButtonDeleteSelected_sources ({rdState}) {
const listItemsSel = rdState.listSources.items
.filter(it => it.data.cbSel.checked);
if (!listItemsSel.length) return;
if (
!await InputUiUtil.pGetUserBoolean({
title: "Delete Sources",
htmlDescription: `
Are you sure you want to delete the ${listItemsSel.length === 1 ? "selected source" : `${listItemsSel.length} selected sources`}? This will delete all entities with ${listItemsSel.length === 1 ? "that source" : `these sources`}.
`,
textYes: "Yes",
textNo: "Cancel",
})
) return;
this._isDirty = true;
// Remove the sources from our copy of the brew, and remove the corresponding list items
listItemsSel
.forEach(li => {
const ix = this._brew.body._meta.sources.indexOf(li.data.source);
if (!~ix) return;
this._brew.body._meta.sources.splice(ix, 1);
rdState.listSources.removeItem(li);
});
rdState.listSources.update();
// Remove all entities with matching sources, and remove the corresponding list items
const sourceSetRemoved = new Set(listItemsSel.map(li => li.data.source.json));
rdState.listEntities.visibleItems
.forEach(li => {
const source = SourceUtil.getEntitySource(li.data.ent);
if (!sourceSetRemoved.has(source)) return;
this._doEntityListDelete({rdState, li});
});
rdState.listEntities.update();
}
async pRender ($wrp, {rdState = null} = {}) {
rdState = rdState || new this.constructor._RenderState();
const iptTabMetas = [
new TabUiUtil.TabMeta({name: "Entities", hasBorder: true}),
new TabUiUtil.TabMeta({name: "Metadata", hasBorder: true}),
new TabUiUtil.TabMeta({name: "Sources", hasBorder: true}),
];
const tabMetas = this._renderTabs(iptTabMetas, {$parent: $wrp});
const [tabMetaEntities, tabMetaMetadata, tabMetaSources] = tabMetas;
rdState.tabMetaEntities = tabMetaEntities;
rdState.tabMetaSources = tabMetaSources;
this._pRender_tabEntities({tabMeta: tabMetaEntities, rdState});
this._pRender_tabMetadata({tabMeta: tabMetaMetadata, rdState});
this._pRender_tabSources({tabMeta: tabMetaSources, rdState});
}
_pRender_tabEntities ({tabMeta, rdState}) {
const $btnFilter = $(``);
const $btnToggleSummaryHidden = $(``);
const $btnReset = $(``);
const $wrpMiniPills = $(``);
const $cbAll = $(``);
const $wrpRows = $$``;
const $iptSearch = $(``);
const $dispCntVisible = $(``);
const $wrpBtnsSort = $$`