commit 26/01/2026
This commit is contained in:
@@ -48,6 +48,8 @@ window.messagebankids = [];
|
||||
*/
|
||||
window.broadcastzones = [];
|
||||
|
||||
dtUserManagement = null;
|
||||
|
||||
/**
|
||||
* Get Messagebank ANN_IDs from server
|
||||
*/
|
||||
@@ -109,40 +111,42 @@ function get_broadcastzones_descriptions() {
|
||||
* @param {UserDB[]} vv values to fill
|
||||
*/
|
||||
function fill_usertablebody(vv) {
|
||||
$('#usertablebody').empty();
|
||||
dtUserManagement.clear();
|
||||
|
||||
if (!Array.isArray(vv) || vv.length === 0) {
|
||||
$('#btnExport').prop('disabled', true);
|
||||
return;
|
||||
}
|
||||
vv.forEach(item => {
|
||||
const row = `<tr>
|
||||
<td>${item.index}</td>
|
||||
<td>${item.username}</td>
|
||||
<td>${item.location}</td>
|
||||
<td>${item.airline_tags}</td>
|
||||
<td>${item.city_tags}</td>
|
||||
<td>${item.messagebank_ann_id}</td>
|
||||
<td>${item.broadcastzones}</td>
|
||||
</tr>`;
|
||||
$('#usertablebody').append(row);
|
||||
let $addedrow = $('#usertablebody tr:last');
|
||||
$addedrow.off('click').on('click', function () {
|
||||
if (window.selecteduserrow) {
|
||||
window.selecteduserrow.find('td').css('background-color', '');
|
||||
if (window.selecteduserrow.is($(this))) {
|
||||
window.selecteduserrow = null;
|
||||
$('#btnRemove').prop('disabled', true);
|
||||
$('#btnEdit').prop('disabled', true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$(this).find('td').css('background-color', '#ffeeba');
|
||||
window.selecteduserrow = $(this);
|
||||
$('#btnRemove').prop('disabled', false);
|
||||
$('#btnEdit').prop('disabled', false);
|
||||
});
|
||||
|
||||
dtUserManagement.rows.add(vv);
|
||||
dtUserManagement.draw();
|
||||
|
||||
|
||||
$('#usertable tbody').off('click').on('click', 'tr', function () {
|
||||
// if no data
|
||||
if (!dtUserManagement) return;
|
||||
// if user click an empty row
|
||||
if (!dtUserManagement.data().any()) return;
|
||||
|
||||
const selected = dtUserManagement.row(this)
|
||||
// toggle behaviour - unselect if already selected
|
||||
if ($(this).hasClass('row-selected')) {
|
||||
$(this).removeClass('row-selected').find('td').css('background-color', '');
|
||||
window.selecteduserrow = null;
|
||||
$('#btnRemove').prop('disabled', true);
|
||||
$('#btnEdit').prop('disabled', true);
|
||||
return;
|
||||
}
|
||||
|
||||
// unselect previously selected row
|
||||
$('#usertable tbody tr.row-selected').removeClass('row-selected').find('td').css('background-color', '');
|
||||
|
||||
$(this).addClass('row-selected').find('td').css('background-color', '#ffeeba');
|
||||
window.selecteduserrow = selected.data();
|
||||
$('#btnRemove').prop('disabled', false);
|
||||
$('#btnEdit').prop('disabled', false);
|
||||
});
|
||||
|
||||
$('#tablesize').text("Table Size: " + vv.length);
|
||||
$('#btnExport').prop('disabled', false);
|
||||
}
|
||||
@@ -170,6 +174,23 @@ $(document).ready(function () {
|
||||
get_messagebankids();
|
||||
get_broadcastzones_descriptions();
|
||||
|
||||
if (dtUserManagement === null) {
|
||||
dtUserManagement = new DataTable('#usertable', {
|
||||
data: [],
|
||||
pageLength: 25,
|
||||
columns: [
|
||||
{ title: "No", data: "index" },
|
||||
{ title: "Username", data: "username" },
|
||||
{ title: "Location", data: "location" },
|
||||
{ title: "Airline", data: "airline_tags" },
|
||||
{ title: "City", data: "city_tags" },
|
||||
{ title: "Messagebank", data: "messagebank_ann_id" },
|
||||
{ title: "Broadcast Zones", data: "broadcastzones" }
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let APIURL = "UserManagement/";
|
||||
|
||||
function clearAddModal() {
|
||||
@@ -247,29 +268,29 @@ $(document).ready(function () {
|
||||
|
||||
$('#usertablebody').empty();
|
||||
reloaduserDB();
|
||||
$('#finduser').off('input').on('input', function () {
|
||||
let searchTerm = $(this).val().toLowerCase();
|
||||
if (searchTerm.length > 0) {
|
||||
let filteredUsers = window.userdb.filter(user =>
|
||||
user.username.toLowerCase().includes(searchTerm) ||
|
||||
user.airline_tags.toLowerCase().includes(searchTerm) ||
|
||||
user.city_tags.toLowerCase().includes(searchTerm)
|
||||
//user.messagebank_ann_id.toLowerCase().includes(searchTerm) ||
|
||||
//user.broadcastzones.toLowerCase().includes(searchTerm)
|
||||
);
|
||||
fill_usertablebody(filteredUsers);
|
||||
} else {
|
||||
fill_usertablebody(window.userdb);
|
||||
}
|
||||
// $('#finduser').off('input').on('input', function () {
|
||||
// let searchTerm = $(this).val().toLowerCase();
|
||||
// if (searchTerm.length > 0) {
|
||||
// let filteredUsers = window.userdb.filter(user =>
|
||||
// user.username.toLowerCase().includes(searchTerm) ||
|
||||
// user.airline_tags.toLowerCase().includes(searchTerm) ||
|
||||
// user.city_tags.toLowerCase().includes(searchTerm)
|
||||
// //user.messagebank_ann_id.toLowerCase().includes(searchTerm) ||
|
||||
// //user.broadcastzones.toLowerCase().includes(searchTerm)
|
||||
// );
|
||||
// fill_usertablebody(filteredUsers);
|
||||
// } else {
|
||||
// fill_usertablebody(window.userdb);
|
||||
// }
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
/**
|
||||
* Show modal dialog for soundbank, messagebank, broadcastzone selection
|
||||
* @param {boolean} editmode if true, edit mode, else add mode
|
||||
* @param {number} index index of user to edit, default 0
|
||||
*/
|
||||
function modalshow(editmode = false, index=0) {
|
||||
function modalshow(editmode = false, index = 0) {
|
||||
// event on click btnShowSoundbankModal
|
||||
$('#btnShowSoundbankModal').off('click').on('click', function () {
|
||||
$('#soundbankmodal').modal('show');
|
||||
@@ -485,20 +506,15 @@ $(document).ready(function () {
|
||||
$('#btnAdd').off('click').on('click', () => {
|
||||
$('#addmodal').modal('show');
|
||||
clearAddModal();
|
||||
modalshow(false,0);
|
||||
modalshow(false, 0);
|
||||
});
|
||||
$('#btnRemove').off('click').on('click', () => {
|
||||
if (window.selecteduserrow) {
|
||||
let cells = window.selecteduserrow.find('td');
|
||||
|
||||
/** @type {UserDB} */
|
||||
let user = {
|
||||
index: parseInt(cells.eq(0).text()),
|
||||
username: cells.eq(1).text(),
|
||||
password: cells.eq(2).text(),
|
||||
airline_tags: cells.eq(3).text(),
|
||||
city_tags: cells.eq(4).text(),
|
||||
messagebank_ann_id: cells.eq(5).text(),
|
||||
broadcastzones: cells.eq(6).text()
|
||||
index: window.selecteduserrow.index,
|
||||
username: window.selecteduserrow.username
|
||||
}
|
||||
if (confirm(`Are you sure to delete user [${user.index}] Username=${user.username} ?`)) {
|
||||
fetchAPI(APIURL + "DeleteByIndex/" + user.index, "DELETE", {}, null, (okdata) => {
|
||||
@@ -514,8 +530,7 @@ $(document).ready(function () {
|
||||
});
|
||||
$('#btnEdit').off('click').on('click', () => {
|
||||
if (window.selecteduserrow) {
|
||||
let cells = window.selecteduserrow.find('td');
|
||||
let index = parseInt(cells.eq(0).text());
|
||||
let index = window.selecteduserrow.index;
|
||||
if (isNaN(index) || index <= 0) {
|
||||
alert("Invalid user index");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user