231 lines
8.9 KiB
JavaScript
231 lines
8.9 KiB
JavaScript
|
|
/**
|
|
* Load setting language dropdown
|
|
*/
|
|
function load_setting_language() {
|
|
$("#setting_language").empty().off('change');
|
|
|
|
getLanguages(() => {
|
|
window.languages.forEach((lang) => {
|
|
let $option = $("<option></option>").attr("value", lang).text(lang);
|
|
$("#setting_language").append($option);
|
|
});
|
|
$("#setting_language").on('change', function () {
|
|
change_droparea_enable();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Load setting category dropdown
|
|
*/
|
|
function load_setting_category() {
|
|
$("#setting_category").empty().off('change');
|
|
getCategories(() => {
|
|
window.categories.forEach((cat) => {
|
|
let $option = $("<option></option>").attr("value", cat).text(cat);
|
|
$("#setting_category").append($option);
|
|
});
|
|
$("#setting_category").on('change', function () {
|
|
change_droparea_enable();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Load setting voice dropdown
|
|
*/
|
|
function load_setting_voice() {
|
|
$("#setting_voice").empty().off('change');
|
|
getVoiceTypes(() => {
|
|
window.voiceTypes.forEach((voice) => {
|
|
let $option = $("<option></option>").attr("value", voice).text(voice);
|
|
$("#setting_voice").append($option);
|
|
});
|
|
$("#setting_voice").on('change', function () {
|
|
change_droparea_enable();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get Soundbank path from server
|
|
*/
|
|
function get_soundbank_path() {
|
|
$("#setting_path").val("");
|
|
fetchAPI("Settings/SoundbankDirectory", "GET", {}, null, (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);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Enable or disable drop area based on selections
|
|
*/
|
|
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 {
|
|
$("#drop-area").addClass("disabled");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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, 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() {
|
|
fetchAPI("Settings/FISCode", "GET", {}, null, (okdata) => {
|
|
//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 () {
|
|
console.log("setting.js loaded");
|
|
|
|
|
|
$("#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) => {
|
|
alert("Soundbank directory path saved successfully.");
|
|
}, (errdata) => {
|
|
alert("Error saving soundbank directory path : " + errdata.message);
|
|
});
|
|
} else {
|
|
alert("Please enter a valid soundbank directory path.");
|
|
}
|
|
});
|
|
|
|
|
|
get_soundbank_path();
|
|
load_setting_category();
|
|
load_setting_language();
|
|
load_setting_voice();
|
|
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();
|
|
let fld = $("#input_FLD").val();
|
|
if (gop && gbd && gfc && fld) {
|
|
let data = {
|
|
GOP: gop,
|
|
GBD: gbd,
|
|
GFC: gfc,
|
|
FLD: fld
|
|
};
|
|
fetchAPI("Settings/FISCode", "POST", {}, data, (okdata) => {
|
|
alert("FIS codes saved successfully.");
|
|
}, (errdata) => {
|
|
alert("Error saving FIS codes : " + errdata.message);
|
|
});
|
|
} 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.");
|
|
|
|
});
|
|
|
|
}); |