commit 24/10/2025
This commit is contained in:
@@ -1,21 +1,16 @@
|
||||
let selected_language = null;
|
||||
let selected_category = null;
|
||||
let selected_voice = null;
|
||||
|
||||
/**
|
||||
* Load setting language dropdown
|
||||
*/
|
||||
function load_setting_language(){
|
||||
selected_language = null;
|
||||
function load_setting_language() {
|
||||
$("#setting_language").empty().off('change');
|
||||
|
||||
getLanguages( () => {
|
||||
window.languages.forEach( (lang) => {
|
||||
|
||||
getLanguages(() => {
|
||||
window.languages.forEach((lang) => {
|
||||
let $option = $("<option></option>").attr("value", lang).text(lang);
|
||||
$("#setting_language").append($option);
|
||||
});
|
||||
$("#setting_language").on('change', function() {
|
||||
selected_language = $(this).val();
|
||||
$("#setting_language").on('change', function () {
|
||||
change_droparea_enable();
|
||||
});
|
||||
});
|
||||
@@ -24,16 +19,14 @@ function load_setting_language(){
|
||||
/**
|
||||
* Load setting category dropdown
|
||||
*/
|
||||
function load_setting_category(){
|
||||
selected_category = null;
|
||||
function load_setting_category() {
|
||||
$("#setting_category").empty().off('change');
|
||||
getCategories( () => {
|
||||
window.categories.forEach( (cat) => {
|
||||
getCategories(() => {
|
||||
window.categories.forEach((cat) => {
|
||||
let $option = $("<option></option>").attr("value", cat).text(cat);
|
||||
$("#setting_category").append($option);
|
||||
});
|
||||
$("#setting_category").on('change', function() {
|
||||
selected_category = $(this).val();
|
||||
$("#setting_category").on('change', function () {
|
||||
change_droparea_enable();
|
||||
});
|
||||
});
|
||||
@@ -42,25 +35,30 @@ function load_setting_category(){
|
||||
/**
|
||||
* Load setting voice dropdown
|
||||
*/
|
||||
function load_setting_voice(){
|
||||
selected_voice = null;
|
||||
function load_setting_voice() {
|
||||
$("#setting_voice").empty().off('change');
|
||||
getVoiceTypes( () => {
|
||||
window.voiceTypes.forEach( (voice) => {
|
||||
getVoiceTypes(() => {
|
||||
window.voiceTypes.forEach((voice) => {
|
||||
let $option = $("<option></option>").attr("value", voice).text(voice);
|
||||
$("#setting_voice").append($option);
|
||||
});
|
||||
$("#setting_voice").on('change', function() {
|
||||
selected_voice = $(this).val();
|
||||
$("#setting_voice").on('change', function () {
|
||||
change_droparea_enable();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function get_soundbank_path(){
|
||||
/**
|
||||
* Get Soundbank path from server
|
||||
*/
|
||||
function get_soundbank_path() {
|
||||
$("#setting_path").val("");
|
||||
fetchAPI("Settings/SoundbankDirectory", "GET", {}, null, (okdata) => {
|
||||
console.log("Soundbank path : " + okdata);
|
||||
$("#setting_path").val(okdata);
|
||||
if (okdata.message && okdata.message.trim().length > 0) {
|
||||
let path = okdata.message.trim();
|
||||
//console.log("Soundbank path retrieved: " + path);
|
||||
$("#setting_path").val(path);
|
||||
}
|
||||
}, (errdata) => {
|
||||
alert("Error getting soundbank path : " + errdata.message);
|
||||
});
|
||||
@@ -69,7 +67,10 @@ function get_soundbank_path(){
|
||||
/**
|
||||
* Enable or disable drop area based on selections
|
||||
*/
|
||||
function change_droparea_enable(){
|
||||
function change_droparea_enable() {
|
||||
let selected_category = $("#setting_category").val();
|
||||
let selected_language = $("#setting_language").val();
|
||||
let selected_voice = $("#setting_voice").val();
|
||||
if (selected_category && selected_language && selected_voice) {
|
||||
$("#drop-area").removeClass("disabled");
|
||||
} else {
|
||||
@@ -77,45 +78,49 @@ function change_droparea_enable(){
|
||||
}
|
||||
}
|
||||
|
||||
function load_messagebank(cbOK = null){
|
||||
/**
|
||||
* Load message bank data into selection dropdowns
|
||||
* @param {Function || null} cbOK callback when complete
|
||||
*/
|
||||
function load_messagebank(cbOK = null) {
|
||||
$("#input_GOP").empty();
|
||||
$("#input_GBD").empty();
|
||||
$("#input_GFC").empty();
|
||||
$("#input_FLD").empty();
|
||||
|
||||
// get messagebank data from server
|
||||
reloadMessageBank(()=>{
|
||||
console.log("Will load " + window.messagebankdata.length + " message bank items into selection.");
|
||||
window.messagebankdata.forEach((item)=>{
|
||||
let opt = `${item.description} [${item.aNN_ID}]`;
|
||||
console.log("Adding option: " + opt);
|
||||
$("#input_GOP").append($("<option></option>").attr("value", opt).text(opt));
|
||||
$("#input_GBD").append($("<option></option>").attr("value", opt).text(opt));
|
||||
$("#input_GFC").append($("<option></option>").attr("value", opt).text(opt));
|
||||
$("#input_FLD").append($("<option></option>").attr("value", opt).text(opt));
|
||||
});
|
||||
if (window.messagebankdata.length > 0) {
|
||||
if (cbOK) cbOK();
|
||||
}
|
||||
// get messagebank data from server, which contains [FLIGHT_NUMBER]
|
||||
let messageData = [...new Set(window.messagebankdata.filter(mb => mb.message_Detail.includes('[FLIGHT_NUMBER]')).map(mb => `${mb.description} [${mb.aNN_ID}]`))];
|
||||
//console.log("Message bank data with [FLIGHT_NUMBER]: ", messageData);
|
||||
messageData.forEach((item) => {
|
||||
//console.log("Adding option: " + item);
|
||||
$("#input_GOP").append($("<option></option>").attr("value", item).text(item));
|
||||
$("#input_GBD").append($("<option></option>").attr("value", item).text(item));
|
||||
$("#input_GFC").append($("<option></option>").attr("value", item).text(item));
|
||||
$("#input_FLD").append($("<option></option>").attr("value", item).text(item));
|
||||
});
|
||||
if (window.messagebankdata.length > 0) {
|
||||
if (cbOK) cbOK();
|
||||
}
|
||||
}
|
||||
|
||||
function load_remark_selection(){
|
||||
function load_remark_selection() {
|
||||
fetchAPI("Settings/FISCode", "GET", {}, null, (okdata) => {
|
||||
$("#input_GOP").val(okdata.GOP);
|
||||
$("#input_GBD").val(okdata.GBD);
|
||||
$("#input_GFC").val(okdata.GFC);
|
||||
$("#input_FLD").val(okdata.FLD);
|
||||
//console.log("FIS codes retrieved: ", JSON.stringify(okdata));
|
||||
|
||||
$("#input_GOP").val(okdata.gop)
|
||||
$("#input_GBD").val(okdata.gbd);
|
||||
$("#input_GFC").val(okdata.gfc);
|
||||
$("#input_FLD").val(okdata.fld);
|
||||
}, (errdata) => {
|
||||
alert("Error getting FIS codes : " + errdata.message);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
console.log("setting.js loaded");
|
||||
|
||||
|
||||
$("#save_directory").off('click').on('click', function() {
|
||||
|
||||
|
||||
$("#save_directory").off('click').on('click', function () {
|
||||
let new_path = $("#setting_path").val();
|
||||
if (new_path && new_path.trim().length > 0) {
|
||||
fetchAPI("Settings/SoundbankDirectory", "POST", {}, { directory: new_path }, (okdata) => {
|
||||
@@ -126,15 +131,15 @@ $(document).ready(function() {
|
||||
} else {
|
||||
alert("Please enter a valid soundbank directory path.");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// get_soundbank_path();
|
||||
get_soundbank_path();
|
||||
load_setting_category();
|
||||
load_setting_language();
|
||||
load_setting_voice();
|
||||
load_messagebank(()=> load_remark_selection());
|
||||
$("#fiscodesave").off('click').on('click', function() {
|
||||
load_messagebank(() => load_remark_selection());
|
||||
$("#fiscodesave").off('click').on('click', function () {
|
||||
let gop = $("#input_GOP").val();
|
||||
let gbd = $("#input_GBD").val();
|
||||
let gfc = $("#input_GFC").val();
|
||||
@@ -154,7 +159,73 @@ $(document).ready(function() {
|
||||
} else {
|
||||
alert("Please select all FIS codes (GOP, GBD, GFC, FLD) before saving.");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
$("#drop-area").on('dragover', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
$(this).addClass('dragover');
|
||||
}).on('dragleave', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
$(this).removeClass('dragover');
|
||||
}).on('drop', function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
$(this).removeClass('dragover');
|
||||
if ($(this).hasClass('disabled')) {
|
||||
alert("Please select Category, Language, and Voice Type before uploading files.");
|
||||
return;
|
||||
}
|
||||
let lang = $("#setting_language").val().trim();
|
||||
let category = $("#setting_category").val().trim();
|
||||
let voice = $("#setting_voice").val().trim();
|
||||
let files = e.originalEvent.dataTransfer.files;
|
||||
if (lang && lang.length > 0) {
|
||||
if (category && category.length > 0) {
|
||||
if (voice && voice.length > 0) {
|
||||
if (files.length > 0) {
|
||||
// check if each file have type audio/wav , size more than 0, and name ends with .wav
|
||||
let allValid = true;
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
let file = files[i];
|
||||
if (file.type !== 'audio/wav' && !file.name.toLowerCase().endsWith('.wav')) {
|
||||
allValid = false;
|
||||
}
|
||||
if (file.size <= 0) {
|
||||
allValid = false;
|
||||
}
|
||||
}
|
||||
if (allValid) {
|
||||
if (confirm(`Are you sure want to upload ${files.length} file(s) to the soundbank directory for Category: ${$("#setting_category").val()}, Language: ${$("#setting_language").val()}, Voice Type: ${$("#setting_voice").val()}?`)) {
|
||||
let url = `api/Settings/UploadSoundbank/${lang}/${voice}/${category}`;
|
||||
const formdata = new FormData();
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
formdata.append('files', files[i]);
|
||||
}
|
||||
try{
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
body: formdata
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(okdata => {
|
||||
console.log("Upload result: ", JSON.stringify(okdata));
|
||||
})
|
||||
.catch(errdata => {
|
||||
alert("Error uploading files to soundbank directory : " + errdata.message);
|
||||
});
|
||||
} catch(err){
|
||||
alert("Error preparing file upload: " + err.message);
|
||||
}
|
||||
}
|
||||
} else alert("Please upload only valid WAV audio files. Type must be audio/wav and size must be more than 0 bytes.");
|
||||
} else alert("No files detected for upload.");
|
||||
} else alert("Please select Voice Type before uploading files.");
|
||||
} else alert("Please select Category before uploading files.");
|
||||
} else alert("Please select Language before uploading files.");
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user