show channels as options

This commit is contained in:
Corban-Lee Jones 2024-10-02 23:35:01 +01:00
parent c8cd549ca8
commit 40f8c9f899
2 changed files with 32 additions and 3 deletions

View File

@ -154,14 +154,19 @@ getTableFiltersComponent(subTableId).find(".table-del-btn").on("click", async fu
// region New/Edit Modal
$(subTableId).closest('.js-tableBody').siblings('.js-tableFilters').on("click", ".table-new-btn", async function() {
await openDataModal(subModalId, -1);
await openSubModal(-1);
});
$(subTableId).on("click", ".edit-modal", async function() {
const id = $(subTableId).DataTable().row($(this).closest("tr")).data().id;
await openDataModal(subModalId, id, `/api/subscriptions/${id}/`);
await openSubModal(id);
})
async function openSubModal(id) {
await loadChannelOptions();
await openDataModal(subModalId, id, id !== -1 ? `/api/subscriptions/${id}/`: null);
}
$(subModalId).on("submit", async function(event) {
event.preventDefault();
await onModalSubmit(
@ -217,3 +222,27 @@ async function loadSubModalOptions($input, url) {
// Re-enable input
$input.prop("disabled", false);
}
// Channel options aren't loaded from an API, like other options.
function loadChannelOptions() {
$input = $(subModalId).find('[data-field="channels"]');
$input.val("").change();
$input.prop("disabled", true);
$input.find("option").each(function() {
if ($(this).val()) {
$(this).remove();
}
});
const data = loadedChannels(selectedServer.id);
data.forEach(item => {
$input.append($(
"<option>",
{text: `#${item.name}`, value: item.id}
));
})
$input.prop("disabled", false);
}

View File

@ -45,7 +45,7 @@
<div class="col-lg-6 pe-lg-4">
<div class="mb-4">
<label for="subChannels" class="form-label">Channels</label>
<select name="subChannels" id="subChannels" class="select-2" multiple data-dropdownparent="#subFormModal" data-field="" tabindex="5"></select>
<select name="subChannels" id="subChannels" class="select-2" multiple data-dropdownparent="#subFormModal" data-field="channels" tabindex="5"></select>
<div class="form-text">Send content to these channels.</div>
</div>
</div>