commit 06/11/2025

This commit is contained in:
2025-11-06 11:31:02 +07:00
parent 72c509feec
commit b24c153615
34 changed files with 719 additions and 174 deletions

View File

@@ -344,6 +344,16 @@ th, td {
color: #fff;
}
.btn-disable {
color: white;
background-color: var(--bs-red);
}
.btn-enable {
color: white;
background-color: #36d636;
}
.btn-logout {
background-color: #4280ab;
color: #fff;

View File

@@ -28,8 +28,7 @@ let $input_gatenumber = null;
let $input_flightnumber = null;
let $input_licenseplate = null;
let $input_conveyorbelt = null;
let $input_hours = null;
let $input_minutes = null;
let $input_etad = null;
let $row_airplane = null;
let $row_city = null;
@@ -42,6 +41,11 @@ let $col_conveyorbelt = null;
let $col_procedure = null;
let $col_licenseplate = null;
/**
* @type {message[]}
*/
let selected_messages = [];
/**
* @typedef {Object} message
* @property {number} id - The ID of the message
@@ -438,8 +442,8 @@ function reload_database() {
});
}
function empty_preview(){
$preview_arabic.empty();
function empty_preview() {
$preview_arabic.empty();
$preview_chinese.empty();
$preview_english.empty();
$preview_indonesia.empty();
@@ -455,7 +459,7 @@ function empty_preview(){
}
function enable_disable_fields(){
function enable_disable_fields() {
$row_airplane.hide();
$row_city.hide();
$row_gatenumber.hide();
@@ -469,10 +473,10 @@ function enable_disable_fields(){
// show airplane row if English preview contains the placeholder
const text = $preview_english.text() || "";
if (text.indexOf('[CITY]') !== -1) $row_city.show();
if (text.indexOf('[AIRPLANE_NAME]') !== -1) $row_airplane.show();
if (text.indexOf('[FLIGHT_NUMBER]') !== -1) $row_airplane.show();
if (text.indexOf('[GATENUMBER]') !== -1) $row_gatenumber.show();
if (text.indexOf('[CITY]') !== -1) $row_city.show();
if (text.indexOf('[AIRPLANE_NAME]') !== -1) $row_airplane.show();
if (text.indexOf('[FLIGHT_NUMBER]') !== -1) $row_airplane.show();
if (text.indexOf('[GATENUMBER]') !== -1) $row_gatenumber.show();
if (text.indexOf('[ETAD]') !== -1) $row_time.show();
if (text.indexOf('[REASON]') !== -1) $col_reason.show();
if (text.indexOf('[PLACES]') !== -1) $col_places.show();
@@ -482,76 +486,140 @@ function enable_disable_fields(){
if (text.indexOf('[PLATNOMOR]') !== -1) $col_licenseplate.show();
}
function update_preview(language){
function ValidString(str) {
return (str != null && typeof str === 'string' && str.trim().length > 0);
}
function update_preview(language) {
let text = "";
let $preview = null;
if (language === "indonesia") {
$preview = $preview_indonesia;
text = selected_messages.find(m => (m.language || "").toLowerCase() === "indonesia")?.message_details || "";
} else if (language === "english") {
$preview = $preview_english;
text = selected_messages.find(m => (m.language || "").toLowerCase() === "english")?.message_details || "";
} else if (language === "chinese") {
$preview = $preview_chinese;
text = selected_messages.find(m => (m.language || "").toLowerCase() === "chinese")?.message_details || "";
} else if (language === "japanese") {
$preview = $preview_japanese;
text = selected_messages.find(m => (m.language || "").toLowerCase() === "japanese")?.message_details || "";
} else if (language === "arabic") {
$preview = $preview_arabic;
text = selected_messages.find(m => (m.language || "").toLowerCase() === "arabic")?.message_details || "";
} else if (language === "local") {
$preview = $preview_local;
text = selected_messages.find(m => (m.language || "").toLowerCase() === "local")?.message_details || "";
}
if ($preview) {
text = $preview.text();
}
if (text.indexOf('[CITY]') !== -1) {
let cities = $select_city.val();
if (Array.isArray(cities)) {
text = text.replace(/\[CITY\]/g, cities.join(", "));
} else {
text = text.replace(/\[CITY\]/g, cities || "");
if (Array.isArray(cities) && cities.length > 0) {
let citiesNames = [];
for (let cityTag of cities) {
let ct = window.semiautodata.cities.find(c => c.tag === cityTag);
if (ct) {
citiesNames.push(ct.value);
}
}
if (citiesNames.length > 0) {
text = text.replace(/\[CITY\]/g, citiesNames.join(", "));
}
}
}
if (text.indexOf('[AIRPLANE_NAME]') !== -1) {
let airlineTag = $select_airline.val() || "";
let airlineObj = window.semiautodata.airlines.find(a => a.tag === airlineTag);
let airlineName = airlineObj ? airlineObj.value : "";
text = text.replace(/\[AIRPLANE_NAME\]/g, airlineName);
let airlineTag = $select_airline.val();
if (ValidString(airlineTag)) {
let airlineObj = window.semiautodata.airlines.find(a => a.tag === airlineTag);
let airlineName = airlineObj ? airlineObj.value : "";
if (airlineName.length > 0) {
text = text.replace(/\[AIRPLANE_NAME\]/g, airlineName);
}
}
}
if (text.indexOf('[FLIGHT_NUMBER]') !== -1) {
let flightNumber = $input_flightnumber.val() || "";
text = text.replace(/\[FLIGHT_NUMBER\]/g, flightNumber);
let airlineTag = $select_airline.val();
let flightNumber = $input_flightnumber.val();
if (ValidString(airlineTag) && ValidString(flightNumber)) {
text = text.replace(/\[FLIGHT_NUMBER\]/g, `${airlineTag} ${flightNumber}`);
}
}
if (text.indexOf('[GATENUMBER]') !== -1) {
let gateNumber = $input_gatenumber.val() || "";
text = text.replace(/\[GATENUMBER\]/g, gateNumber);
let gateNumber = $input_gatenumber.val();
if (ValidString(gateNumber)) {
text = text.replace(/\[GATENUMBER\]/g, gateNumber);
}
}
if (text.indexOf('[ETAD]') !== -1) {
let etad = $input_etad.val() || "";
text = text.replace(/\[ETAD\]/g, etad);
let etad = $input_etad.val();
if (ValidString(etad)) {
text = text.replace(/\[ETAD\]/g, etad);
}
}
if (text.indexOf('[REASON]') !== -1) {
let reason = $select_reason.val() || "";
text = text.replace(/\[REASON\]/g, reason);
let reason = $select_reason.val();
if (ValidString(reason)) {
let reasonobj = window.semiautodata.reasons.find(r => r.tag === reason);
let reasontext = reasonobj ? reasonobj.value : "";
if (ValidString(reasontext)) {
text = text.replace(/\[REASON\]/g, reasontext);
}
}
}
if (text.indexOf('[PLACES]') !== -1) {
let placeTag = $select_places.val() || "";
text = text.replace(/\[PLACES\]/g, placeTag);
let placeTag = $select_places.val();
if (ValidString(placeTag)) {
let placeobj = window.semiautodata.places.find(p => p.tag === placeTag);
let placetext = placeobj ? placeobj.value : "";
if (ValidString(placetext)) {
text = text.replace(/\[PLACES\]/g, placetext);
}
}
}
if (text.indexOf('[SHALAT]') !== -1) {
let shalatTag = $select_shalat.val() || "";
text = text.replace(/\[SHALAT\]/g, shalatTag);
let shalatTag = $select_shalat.val();
if (ValidString(shalatTag)) {
let shalatobj = window.semiautodata.shalat.find(s => s.tag === shalatTag);
let shalattext = shalatobj ? shalatobj.value : "";
if (ValidString(shalattext)) {
text = text.replace(/\[SHALAT\]/g, shalattext);
}
}
}
if (text.indexOf('[BCB]') !== -1) {
let bcbTag = $select_bcb.val() || "";
text = text.replace(/\[BCB\]/g, bcbTag);
let bcbTag = $select_bcb.val();
if (ValidString(bcbTag)) {
text = text.replace(/\[BCB\]/g, bcbTag);
}
}
if (text.indexOf('[PROCEDURE]') !== -1) {
let procedureTag = $select_procedure.val() || "";
text = text.replace(/\[PROCEDURE\]/g, procedureTag);
let procedureTag = $select_procedure.val();
if (ValidString(procedureTag)) {
let procedureobj = window.semiautodata.procedures.find(p => p.tag === procedureTag);
let proceduretext = procedureobj ? procedureobj.value : "";
if (ValidString(proceduretext)) {
text = text.replace(/\[PROCEDURE\]/g, proceduretext);
}
}
}
if (text.indexOf('[PLATNOMOR]') !== -1) {
let platNomorTag = $select_licenseplate.val() || "";
text = text.replace(/\[PLATNOMOR\]/g, platNomorTag);
let platNomorTag = $select_licenseplate.val();
if (ValidString(platNomorTag)) {
text = text.replace(/\[PLATNOMOR\]/g, platNomorTag);
}
}
if (text.indexOf('[SEQUENCE]') !== -1) {
let sequenceTag = $select_sequence.val();
if (ValidString(sequenceTag)) {
let sequenceobj = window.semiautodata.sequences.find(s => s.tag === sequenceTag);
let sequencetext = sequenceobj ? sequenceobj.value : "";
if (ValidString(sequencetext)) {
text = text.replace(/\[SEQUENCE\]/g, sequencetext);
}
}
}
if ($preview) {
@@ -559,13 +627,45 @@ function update_preview(language){
}
}
function update_all_previews(){
function isComplete(chkbox, preview) {
if (chkbox.is(":checked")) {
const text = preview.text();
if (text.indexOf('[') !== -1) {
return false;
}
if (text.indexOf(']') !== -1) {
return false;
}
}
return true;
}
function check_complete_message() {
let complete = true;
if (!isComplete($enable_indonesia, $preview_indonesia)) complete = false;
if (!isComplete($enable_english, $preview_english)) complete = false;
if (!isComplete($enable_chinese, $preview_chinese)) complete = false;
if (!isComplete($enable_japanese, $preview_japanese)) complete = false;
if (!isComplete($enable_arabic, $preview_arabic)) complete = false;
if (!isComplete($enable_local, $preview_local)) complete = false;
if (complete) {
$("#send_broadcast").removeClass("btn-disable").addClass("btn-enable");
} else {
$("#send_broadcast").removeClass("btn-enable").addClass("btn-disable");
}
}
function update_all_previews() {
update_preview("indonesia");
update_preview("english");
update_preview("chinese");
update_preview("japanese");
update_preview("arabic");
update_preview("local");
check_complete_message();
}
function fill_items() {
@@ -584,8 +684,7 @@ function fill_items() {
$input_flightnumber.empty();
$input_licenseplate.empty();
$input_conveyorbelt.empty();
$input_hours.empty();
$input_minutes.empty();
$input_etad.empty();
empty_preview();
@@ -623,17 +722,17 @@ function fill_items() {
$enable_indonesia.prop("checked", !!checked);
return true;
}
if (l.startsWith("english") ) {
if (l.startsWith("english")) {
if (checked) $preview_english.text(value); else $preview_english.empty();
$enable_english.prop("checked", !!checked);
return true;
}
if (l.startsWith("chinese") ) {
if (l.startsWith("chinese")) {
if (checked) $preview_chinese.text(value); else $preview_chinese.empty();
$enable_chinese.prop("checked", !!checked);
return true;
}
if (l.startsWith("japanese") ) {
if (l.startsWith("japanese")) {
if (checked) $preview_japanese.text(value); else $preview_japanese.empty();
$enable_japanese.prop("checked", !!checked);
return true;
@@ -660,6 +759,7 @@ function fill_items() {
}
}
selected_messages = [];
if (willSelect) {
// unselect other selected rows and clear their previews
$tbody_message.find("tr.table-active").each(function () {
@@ -676,8 +776,10 @@ function fill_items() {
const sameMsgs = window.semiautodata.messages.filter(m => Number(m.id) === Number(groupId));
for (let m of sameMsgs) {
applyLang(m.language, m.message_details, true);
selected_messages.push(m);
}
enable_disable_fields();
update_all_previews();
}
} else {
// deselect this row and clear its previews
@@ -711,7 +813,7 @@ function fill_items() {
multiple: false
});
$select_airline.val(null).trigger("change");
$select_airline.on('change', function () {
update_all_previews();
});
@@ -742,21 +844,21 @@ function fill_items() {
placeholder: "Select a place",
width: '100%',
multiple: false,
data: window.semiautodata.places.map(p => ({ id: p.tag, text: p.value }))
data: window.semiautodata.places.map(p => ({ id: p.tag, text: p.value + " [" + p.tag + "]" }))
});
$select_places.val(null).trigger("change");
$select_places.on('change', function () {
update_all_previews();
});
}
if (window.semiautodata.shalat !== null && Array.isArray(window.semiautodata.shalat) && window.semiautodata.shalat.length > 0) {
$select_shalat.select2({
placeholder: "Select shalat time",
width: '100%',
multiple: false,
data: window.semiautodata.shalat.map(s => ({ id: s.tag, text: s.value }))
data: window.semiautodata.shalat.map(s => ({ id: s.tag, text: s.value + " [" + s.tag + "]" }))
});
$select_shalat.val(null).trigger("change");
}
@@ -765,20 +867,20 @@ function fill_items() {
placeholder: "Select a reason",
width: '100%',
multiple: false,
data: window.semiautodata.reasons.map(r => ({ id: r.tag, text: r.value }))
data: window.semiautodata.reasons.map(r => ({ id: r.tag, text: r.value + " [" + r.tag + "]" }))
});
$select_reason.val(null).trigger("change");
$select_reason.on('change', function () {
update_all_previews();
});
}
if (window.semiautodata.compensation !== null && Array.isArray(window.semiautodata.compensation) && window.semiautodata.compensation.length > 0) {
$select_compensation.select2({
placeholder: "Select compensation",
width: '100%',
multiple: false,
data: window.semiautodata.compensation.map(c => ({ id: c.tag, text: c.value }))
data: window.semiautodata.compensation.map(c => ({ id: c.tag, text: c.value + " [" + c.tag + "]" }))
});
$select_compensation.val(null).trigger("change");
$select_compensation.on('change', function () {
@@ -790,7 +892,7 @@ function fill_items() {
placeholder: "Select procedure",
width: '100%',
multiple: false,
data: window.semiautodata.procedures.map(p => ({ id: p.tag, text: p.value }))
data: window.semiautodata.procedures.map(p => ({ id: p.tag, text: p.value + " [" + p.tag + "]" }))
});
$select_procedure.val(null).trigger("change");
$select_procedure.on('change', function () {
@@ -813,11 +915,112 @@ function fill_items() {
$input_licenseplate.on('input', function () {
update_all_previews();
});
$input_etad.on('input', function () {
update_all_previews();
});
}
}
function send_broadcast_message() {
console.log("send_broadcast_message");
if ($("#send_broadcast").hasClass("btn-disable")) {
alert("Cannot send broadcast message. Please complete all required fields.");
return;
}
// get all checked broadcast zones from tbody_broadcastzones
let selected_zones = [];
$tbody_broadcastzones.find("input[type='checkbox']").each(function () {
const $checkbox = $(this);
if ($checkbox.is(":checked")) {
selected_zones.push($checkbox.val());
}
});
if (selected_zones.length === 0) {
alert("Please select at least one broadcast zone.");
return;
}
let languages = [];
if ($enable_indonesia.is(":checked")) languages.push("INDONESIA");
if ($enable_english.is(":checked")) languages.push("ENGLISH");
if ($enable_chinese.is(":checked")) languages.push("CHINESE");
if ($enable_japanese.is(":checked")) languages.push("JAPANESE");
if ($enable_arabic.is(":checked")) languages.push("ARABIC");
if ($enable_local.is(":checked")) languages.push("LOCAL");
if (languages.length === 0) {
alert("Please select at least one language to send.");
return;
}
let description = selected_messages.length > 0 ? selected_messages[0].description : "";
if (!ValidString(description)) {
alert("Message not selected");
return;
}
let tags = [];
let msg = selected_messages[0];
tags.push("ANN_ID:"+msg.id);
if (msg.message_details.indexOf('[CITY]') !== -1) {
let cities = $select_city.val();
if (Array.isArray(cities) && cities.length > 0) {
tags.push("CITY:" + cities.join(";"));
}
}
if (msg.message_details.indexOf('[AIRPLANE_NAME]') !== -1) {
tags.push("AL:" + $select_airline.val());
}
if (msg.message_details.indexOf('[FLIGHT_NUMBER]') !== -1) {
tags.push("FLNUM:" + $input_flightnumber.val());
}
if (msg.message_details.indexOf('[PLATNOMOR]') !== -1) {
tags.push("PLATNOMOR:" + $input_licenseplate.val());
}
if (msg.message_details.indexOf('[PLACES]') !== -1) {
tags.push("PLACES:" + $select_places.val());
}
if (msg.message_details.indexOf('[ETAD]') !== -1) {
tags.push("ETAD:" + $input_etad.val());
}
if (msg.message_details.indexOf('[SHALAT]') !== -1) {
tags.push("SHALAT:" + $select_shalat.val());
}
if (msg.message_details.indexOf('[BCB]') !== -1) {
tags.push("BCB:" + $input_conveyorbelt.val());
}
if (msg.message_details.indexOf('[GATENUMBER]') !== -1) {
tags.push("GATECODE:" + $input_gatenumber.val());
}
if (msg.message_details.indexOf('[REASON]') !== -1) {
tags.push("REASON:" + $select_reason.val());
}
if (msg.message_details.indexOf('[PROCEDURE]') !== -1) {
tags.push("PROCEDURE:" + $select_procedure.val());
}
let payload = {
description: description,
languages: languages.join(";"),
tags: tags.join(" "),
broadcastzones: selected_zones.join(";")
}
console.log("Payload:", payload);
fetchAPI("SemiAuto", "POST", {}, payload, (data) => {
alert("Broadcast message sent successfully.");
}, (error) => {
console.error("Error:", error);
alert("Error sending broadcast message: " + error);
});
}
// App start here
$(document).ready(function () {
console.log("javascript loaded");
@@ -846,8 +1049,7 @@ $(document).ready(function () {
$input_flightnumber = $("#input_flightnumber");
$input_licenseplate = $("#input_licenseplate");
$input_conveyorbelt = $("#input_conveyorbelt");
$input_hours = $("#input_hours");
$input_minutes = $("#input_minutes");
$input_etad = $("#input_etad");
$row_airplane = $("#row_airplane");
$row_city = $("#row_city");
$row_gatenumber = $("#row_gatenumber");
@@ -864,5 +1066,9 @@ $(document).ready(function () {
reload_database();
});
$("#send_broadcast").off("click").on("click", function () {
send_broadcast_message();
});
});

View File

@@ -110,7 +110,7 @@
<div class="col-5 pad-row-input">
<div class="row">
<div class="col-5"><label class="col-form-label">Flight Number</label></div>
<div class="col-7 pad-select"><input type="text" id="input_flightnumber" class="form-control pad-input"></div>
<div class="col-7 pad-select"><input type="text" id="input_flightnumber" class="form-control pad-input" placeholder="flight number" minlength="1" maxlength="4" inputmode="numeric"></div>
</div>
</div>
</div>
@@ -123,18 +123,8 @@
<div class="col-8 col-sm-8 col-md-9 col-lg-9 col-xl-10 pad-input-left pad-row-input"><input type="text" id="input_gatenumber" class="pad-input form-control" placeholder="gate number"></div>
</div>
<div class="row" id="row_time">
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 pad-row-input">
<div class="row">
<div class="col-4 col-sm-4 col-md-6 col-lg-6 col-xl-4"><label class="col-form-label">Hours</label></div>
<div class="col-8 col-sm-8 col-md-6 col-lg-6 col-xl-8 pad-select"><input type="number" id="input_hours" class="form-control pad-input" value="0" min="0" max="23" step="1" placeholder="hour"></div>
</div>
</div>
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 pad-row-input">
<div class="row">
<div class="col-4 col-sm-4 col-md-6 col-lg-6 col-xl-4"><label class="col-form-label">Minutes</label></div>
<div class="col-8 col-sm-8 col-md-6 col-lg-6 col-xl-8 pad-select"><input type="number" id="input_minutes" class="form-control pad-input" value="0" min="0" max="59" step="1" placeholder="minute"></div>
</div>
</div>
<div class="col-4 col-sm-4 col-md-3 col-lg-3 col-xl-2 pad-row-input"><label class="col-form-label">ETAD</label></div>
<div class="col"><input id="input_etad" type="time"></div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 pad-row-input" id="col_reason">
@@ -236,7 +226,7 @@
<path d="M19.933 13.041a8 8 0 1 1 -9.925 -8.788c3.899 -1 7.935 1.007 9.425 4.747"></path>
<path d="M20 4v5h-5"></path>
</svg>&nbsp;Reload Database</button></div>
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-4 col-xxl-4 py-2"><button class="btn btn-primary w-100 pad-input btn-broadcast" id="send_broadcast" type="button" style="font-family: Raleway, sans-serif;box-shadow: 0px 0px 0px 0px var(--bs-blue);border-color: rgba(255,255,255,0.5);"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-send pad-icon">
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-4 col-xxl-4 py-2"><button class="btn w-100 pad-input btn-disable" id="send_broadcast" type="button" style="font-family: Raleway, sans-serif;box-shadow: 0px 0px 0px 0px var(--bs-blue);border-color: rgba(255,255,255,0.5);"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icon-tabler-send pad-icon">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M10 14l11 -11"></path>
<path d="M21 3l-6.5 18a.55 .55 0 0 1 -1 0l-3.5 -7l-7 -3.5a.55 .55 0 0 1 0 -1l18 -6.5"></path>

View File

@@ -1337,7 +1337,7 @@
</div>
</div>
</div>
<div class="accordion-item invisible pad-accordion">
<div class="accordion-item pad-accordion">
<h2 class="accordion-header" role="tab"><button class="accordion-button bg-heading3" type="button" data-bs-toggle="collapse" data-bs-target="#accordion-1 .item-4" aria-expanded="true" aria-controls="accordion-1 .item-4">Remote Listening</button></h2>
<div class="accordion-collapse collapse show item-4" role="tabpanel" data-bs-parent="#accordion-1">
<div class="accordion-body">