/** * @typedef {Object} BroadcastZone * @property {number} index * @property {string} description * @property {String} SoundChannel * @property {String} Box * @property {String} Relay */ /** * List of broadcast zones available * @type {BroadcastZone[]} */ window.BroadcastZoneList ??= []; /** * Currently selected broadcast zone row in the table * @type {JQuery|null} */ window.selectedBroadcastZoneRow = null; /** * List of sound channels available * @type {String[]} */ window.SoundChannelList = [] /** * Fill broadcast zone table body with values * @param {BroadcastZone[]} vv values to fill */ function fill_broadcastzonetablebody(vv) { $('#broadcastzonetablebody').empty(); if (!Array.isArray(vv) || vv.length === 0) return; vv.forEach(item => { const row = ` ${item.index} ${item.description} ${item.soundChannel} ${item.id} ${item.bp} `; $('#broadcastzonetablebody').append(row); let $addedrow = $('#broadcastzonetablebody tr:last'); $addedrow.off('click').on('click', function () { if (window.selectedBroadcastZoneRow) { window.selectedBroadcastZoneRow.find('td').css('background-color', ''); if (window.selectedBroadcastZoneRow.is($(this))) { window.selectedBroadcastZoneRow = null; $('#btnRemove').prop('disabled', true); $('#btnEdit').prop('disabled', true); return; } } $(this).find('td').css('background-color', '#ffeeba'); window.selectedBroadcastZoneRow = $(this); $('#btnRemove').prop('disabled', false); $('#btnEdit').prop('disabled', false); }); }); $('#tablesize').text("Table Size: " + vv.length); } /** * Reload broadcast zones from server * @param {String} APIURL API URL endpoint (default "BroadcastZones/") */ function reloadBroadcastZones(APIURL = "BroadcastZones/") { window.BroadcastZoneList = []; fetchAPI(APIURL + "List", "GET", {}, null, (okdata) => { if (Array.isArray(okdata)) { //console.log("reloadBroadcastZones : ", okdata) window.BroadcastZoneList.push(...okdata); fill_broadcastzonetablebody(window.BroadcastZoneList); } else console.log("reloadBroadcastZones: okdata is not array"); }, (errdata) => { alert("Error loading broadcast zones : " + errdata.message); }); } function fetchSoundChannels(APIURL = "SoundChannel/") { window.SoundChannelList = []; fetchAPI(APIURL + "SoundChannelDescriptions", "GET", {}, null, (okdata) => { if (Array.isArray(okdata)) { //console.log("fetchSoundChannels : ", okdata) window.SoundChannelList.push(...okdata); } else console.log("fetchSoundChannels: okdata is not array"); }, (errdata) => { alert("Error loading sound channels : " + errdata.message); }); } $(document).ready(function () { console.log("broadcastzones.js loaded successfully"); window.selectedBroadcastZoneRow = null; let $btnClear = $('#btnClear'); let $btnAdd = $('#btnAdd'); let $btnEdit = $('#btnEdit'); let $btnRemove = $('#btnRemove'); let $btnExport = $('#btnExport'); let $btnImport = $('#btnImport'); $btnEdit.prop('disabled', true); $btnRemove.prop('disabled', true); let APIURL_BroadcastZone = "BroadcastZones/"; let $broadcastzonemodal = $('#broadcastzonemodal'); let $broadcastzoneindex = $broadcastzonemodal.find('#broadcastzoneindex'); let $broadcastzonedescription = $broadcastzonemodal.find('#broadcastzonedescription'); let $broadcastzonesoundchannel = $broadcastzonemodal.find('#broadcastzonesoundchannel'); let $broadcastzonebox = $broadcastzonemodal.find('#broadcastzonebox'); let $findzone = $('#findzone'); $findzone.off('input').on('input', function () { let searchTerm = $findzone.val().trim().toLowerCase(); if (searchTerm.length > 0) { window.selectedBroadcastZoneRow = null; let filtered = window.BroadcastZoneList.filter(item => item.description.toLowerCase().includes(searchTerm) || item.id.toLowerCase().includes(searchTerm) || item.soundChannel.toLowerCase().includes(searchTerm) || item.bp.toLowerCase().includes(searchTerm)); fill_broadcastzonetablebody(filtered); } else { window.selectedBroadcastZoneRow = null; fill_broadcastzonetablebody(window.BroadcastZoneList); } }); /** * Find Checkbox for relays 1 to 32 * Checkbox id is 01 to 32 with leading zero for 1 to 9 * @param {number} id 1 - 32 * @returns JQuery */ function cbRelay(id) { return $broadcastzonemodal.find('#R' + (id < 10 ? '0' : '') + id); } /** * Clear broadcast zone modal to default state */ function clearBroadcastZoneModal() { $broadcastzoneindex.prop('disabled', true).val(''); $broadcastzonedescription.val(''); // fill broadcastzonesoundchannel from SoundChannelList $broadcastzonesoundchannel.empty(); console.log("SoundChannelList:", window.SoundChannelList); if (Array.isArray(window.SoundChannelList) && window.SoundChannelList.length > 0) { // SoundChannelList ada isinya window.SoundChannelList.forEach(ch => { if (ch && ch.length>0){ $broadcastzonesoundchannel.append($('