commit 26/01/2026
This commit is contained in:
@@ -13,6 +13,8 @@ window.soundChannels = [];
|
||||
// Currently selected sound channel row in the table
|
||||
window.selectedSoundChannel = null;
|
||||
|
||||
dtSoundChannel = null;
|
||||
|
||||
/**
|
||||
* Fills the sound channel table body with the provided data.
|
||||
* @param {SoundChannel[]} vv Sound channel data to populate the table.
|
||||
@@ -20,36 +22,41 @@ window.selectedSoundChannel = null;
|
||||
function fill_soundchanneltablebody(vv) {
|
||||
let $btnEditSoundChannel = $('#btnEditSoundChannel');
|
||||
let $tablesizeSoundChannel = $('#tablesizeSoundChannel');
|
||||
$('#soundchanneltablebody').empty();
|
||||
|
||||
$tablesizeSoundChannel.text('Table Length : N/A');
|
||||
if (!Array.isArray(vv) || vv.length === 0) return;
|
||||
dtSoundChannel.clear();
|
||||
|
||||
if (!Array.isArray(vv) || vv.length === 0) return;
|
||||
dtSoundChannel.rows.add(vv);
|
||||
dtSoundChannel.draw();
|
||||
|
||||
$('#soundchanneltable tbody').off('click').on('click', 'tr', function () {
|
||||
// if no data
|
||||
if (!dtSoundChannel) return;
|
||||
// if user click an empty row
|
||||
if (!dtSoundChannel.data().any()) return;
|
||||
|
||||
const selected = dtSoundChannel.row(this)
|
||||
|
||||
// toggle behaviour - unselect if already selected
|
||||
if ($(this).hasClass('row-selected')) {
|
||||
$(this).removeClass('row-selected').find('td').css('background-color', '');
|
||||
window.selectedSoundChannel = null;
|
||||
$btnEditSoundChannel.prop('disabled', true);
|
||||
return;
|
||||
}
|
||||
|
||||
// unselect previously selected row
|
||||
$('#soundchanneltable tbody tr.row-selected').removeClass('row-selected').find('td').css('background-color', '');
|
||||
|
||||
$(this).addClass('row-selected').find('td').css('background-color', '#ffeeba');
|
||||
window.selectedSoundChannel = selected.data();
|
||||
$btnEditSoundChannel.prop('disabled', false);
|
||||
})
|
||||
|
||||
vv.forEach(item => {
|
||||
const row = `<tr>
|
||||
<td>${item.index}</td>
|
||||
<td>${item.channel}</td>
|
||||
<td>${item.ip}</td>
|
||||
</tr>`;
|
||||
$('#soundchanneltablebody').append(row);
|
||||
let $addedrow = $('#soundchanneltablebody tr:last');
|
||||
$addedrow.off('click').on('click', function () {
|
||||
if (selectedSoundChannel) {
|
||||
selectedSoundChannel.find('td').css('background-color', '');
|
||||
if (selectedSoundChannel.is($(this))) {
|
||||
selectedSoundChannel = null;
|
||||
$btnEditSoundChannel.prop('disabled', true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$(this).find('td').css('background-color', '#ffeeba');
|
||||
selectedSoundChannel = $(this);
|
||||
$btnEditSoundChannel.prop('disabled', false);
|
||||
});
|
||||
});
|
||||
$tablesizeSoundChannel.text("Table Size: " + vv.length);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reload sound channels from server
|
||||
* @param {String} APIURL API URL endpoint (default "SoundChannel/")
|
||||
@@ -66,7 +73,7 @@ function reloadSoundChannel(APIURL = "SoundChannel/") {
|
||||
alert("Error loading sound channels : " + errdata.message);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
console.log("soundchannel.js loaded successfully");
|
||||
let $soundchannelmodal = $('#soundchannelmodal');
|
||||
@@ -82,21 +89,35 @@ $(document).ready(function () {
|
||||
$btnEditSoundChannel.prop('disabled', true);
|
||||
let API_SoundChannel = "SoundChannel/";
|
||||
|
||||
$findsoundchannel.off('input').on('input', function () {
|
||||
let searchTerm = $(this).val().toLowerCase();
|
||||
if (searchTerm.length==0){
|
||||
window.selectedSoundChannel = null;
|
||||
fill_soundchanneltablebody(window.soundChannels);
|
||||
} else {
|
||||
window.selectedSoundChannel = null;
|
||||
let filteredChannels = window.soundChannels.filter(xx =>
|
||||
xx.index.toString().includes(searchTerm) ||
|
||||
xx.channel.toLowerCase().includes(searchTerm) ||
|
||||
xx.ip.toLowerCase().includes(searchTerm)
|
||||
);
|
||||
fill_soundchanneltablebody(filteredChannels);
|
||||
}
|
||||
});
|
||||
if (dtSoundChannel === null) {
|
||||
dtSoundChannel = new DataTable('#soundchanneltable', {
|
||||
data: [],
|
||||
pageLength: 25,
|
||||
columns: [
|
||||
{ title: "No", data: "index" },
|
||||
{ title: "Channel", data: "channel" },
|
||||
{ title: "IP", data: "ip" }
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// $findsoundchannel.off('input').on('input', function () {
|
||||
// let searchTerm = $(this).val().toLowerCase();
|
||||
// if (searchTerm.length == 0) {
|
||||
// window.selectedSoundChannel = null;
|
||||
// fill_soundchanneltablebody(window.soundChannels);
|
||||
// } else {
|
||||
// window.selectedSoundChannel = null;
|
||||
// let filteredChannels = window.soundChannels.filter(xx =>
|
||||
// xx.index.toString().includes(searchTerm) ||
|
||||
// xx.channel.toLowerCase().includes(searchTerm) ||
|
||||
// xx.ip.toLowerCase().includes(searchTerm)
|
||||
// );
|
||||
// fill_soundchanneltablebody(filteredChannels);
|
||||
// }
|
||||
// });
|
||||
|
||||
/**
|
||||
* Clear sound channel modal inputs
|
||||
@@ -117,13 +138,12 @@ $(document).ready(function () {
|
||||
});
|
||||
});
|
||||
$btnEditSoundChannel.off('click').on('click', () => {
|
||||
if (selectedSoundChannel) {
|
||||
let cells = selectedSoundChannel.find('td');
|
||||
if (window.selectedSoundChannel) {
|
||||
/** @type {SoundChannel} */
|
||||
let sc = {
|
||||
index: parseInt(cells.eq(0).text(), 10),
|
||||
description: cells.eq(1).text(),
|
||||
ip: cells.eq(2).text()
|
||||
index: window.selectedSoundChannel.index,
|
||||
description: window.selectedSoundChannel.channel,
|
||||
ip: window.selectedSoundChannel.ip
|
||||
};
|
||||
if (confirm(`Are you sure to edit sound channel [${sc.index}] Description=${sc.description} IP=${sc.ip}?`)) {
|
||||
$soundchannelmodal.modal('show');
|
||||
@@ -147,12 +167,12 @@ $(document).ready(function () {
|
||||
alert("IP cannot be empty");
|
||||
return;
|
||||
}
|
||||
if (newsc.description===sc.description && newsc.ip===sc.ip){
|
||||
if (newsc.description === sc.description && newsc.ip === sc.ip) {
|
||||
alert("No changes detected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fetchAPI(API_SoundChannel + "UpdateByIndex/" + newsc.index, "PATCH", {}, newsc, (okdata) => {
|
||||
reloadSoundChannel(API_SoundChannel);
|
||||
@@ -161,8 +181,8 @@ $(document).ready(function () {
|
||||
alert("Error edit sound channel: " + errdata.message);
|
||||
});
|
||||
$soundchannelmodal.modal('hide');
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
$soundchannelmodal.off('click.soundchannelclose').on('click.soundchannelclose', '#soundchannelclose', function () {
|
||||
$soundchannelmodal.modal('hide');
|
||||
|
||||
Reference in New Issue
Block a user