commit 20/10/2025

TODO Schedule belum beres
This commit is contained in:
2025-10-20 16:12:12 +07:00
parent 2dfc095f04
commit 19e587fc36
9 changed files with 250 additions and 146 deletions

View File

@@ -103,30 +103,26 @@ $(document).ready(function () {
let $scheduleminute = $schedulemodal.find('#scheduleminute');
// select2 for message
let $schedulemessage = $schedulemodal.find('#schedulemessage');
$schedulemessage.select2({});
// number input 0-5
let $schedulerepeat = $schedulemodal.find('#schedulerepeat');
// checkbox
let $scheduleenable = $schedulemodal.find('#scheduleenable');
// select2 for broadcastzones
let $schedulezones = $schedulemodal.find('#schedulezones');
$schedulezones.select2({});
// radio button for everyday
let $scheduleeveryday = $schedulemodal.find('#scheduleeveryday');
// radio button for weekly
let $scheduleweekly = $schedulemodal.find('#scheduleweekly');
// select2 for weekly selection
let $weeklyselect = $schedulemodal.find('#weeklyselect');
$weeklyselect.select2({});
// radio button for specific date
let $schedulespecialdate = $schedulemodal.find('#schedulespecialdate');
// date input
let $scheduledate = $schedulemodal.find('#scheduledate');
// select2 for language
let $languageselect = $schedulemodal.find('#languageselect');
$languageselect.select2({});
$schedulespecialdate.on('change', function () {
$schedulespecialdate.off('change').on('change', function () {
if ($(this).is(':checked')) {
$scheduledate.prop('disabled', false);
} else {
@@ -139,18 +135,73 @@ $(document).ready(function () {
$scheduledescription.val('');
$schedulehour.val('0');
$scheduleminute.val('0');
$schedulerepeat.val('0');
$schedulerepeat.val('1');
$scheduleenable.prop('checked', true);
$scheduleeveryday.prop('checked', false);
$scheduleweekly.prop('checked', false);
$schedulespecialdate.prop('checked', false);
$weeklyselect.empty().select2({
data: window.scheduledays.filter(day => day !== 'Everyday').map(day => ({ id: day, text: day })),
placeholder: 'Select days of the week',
multiple: false,
width: '100%',
dropdownParent: $('#schedulemodal')
});
$languageselect.empty().select2({
data: window.languages.map(lang => ({ id: lang, text: lang })),
placeholder: 'Select languages',
multiple: true,
width: '100%',
dropdownParent: $('#schedulemodal')
});
$scheduledate.prop('disabled', true).val('');
$schedulezones.empty().select2({
data: window.BroadcastZoneList.map(zone => ({ id: zone.description, text: zone.description })),
placeholder: 'Select broadcast zones',
multiple: true,
width: '100%',
dropdownParent: $('#schedulemodal')
});
let messageData = [...new Set(window.messagebankdata.filter(mb => !mb.message_Detail.includes('[')).map(mb => `${mb.description} [${mb.aNN_ID}]`))];
$schedulemessage.empty().select2({
placeholder: 'Select message',
multiple: false,
width: '100%',
dropdownParent: $('#schedulemodal'),
data: messageData.map(mb => ({ id: mb, text: mb }))
});
$scheduleeveryday.off('change').on('change', function () {
if ($(this).is(':checked')) {
$weeklyselect.prop('disabled', true);
$scheduledate.prop('disabled', true);
}
});
$scheduleweekly.off('change').on('change', function () {
if ($(this).is(':checked')) {
$weeklyselect.prop('disabled', false);
$scheduledate.prop('disabled', true);
} else {
$weeklyselect.prop('disabled', true);
}
});
$schedulespecialdate.off('change').on('change', function () {
if ($(this).is(':checked')) {
$weeklyselect.prop('disabled', true);
$scheduledate.prop('disabled', false);
} else {
$scheduledate.prop('disabled', true);
}
});
}
let $findschedule = $('#findschedule');
$findschedule.on('input', function () {
$findschedule.off('input').on('input', function () {
let searchTerm = $findschedule.val().toLowerCase();
if (searchTerm.length > 0) {
window.selectedschedulerow = null;
@@ -167,6 +218,10 @@ $(document).ready(function () {
reloadTimerBank(APIURL);
reloadBroadcastZones();
getLanguages();
getScheduledDays();
reloadMessageBank();
$btnClear.click(() => {
DoClear(APIURL, "Timerbank", (okdata) => {
reloadTimerBank(APIURL);
@@ -186,58 +241,54 @@ $(document).ready(function () {
$schedulemodal.off('click.schedulesave').on('click.schedulesave', '#schedulesave', function () {
// Gather form values
const Description = $scheduledescription.val();
const Soundpath = $schedulesoundpath.val();
const Message = $schedulemessage.val();
const Repeat = parseInt($schedulerepeat.val(), 10);
const Enable = $scheduleenable.is(':checked');
// Collect selected days
let Day = "";
let _Day = "";
if ($scheduleeveryday.is(':checked')) {
Day = "Everyday";
_Day = "Everyday";
} else if ($schedulespecialdate.is(':checked')) {
Day = $scheduledate.val();
} else {
if ($schedulesunday.is(':checked')) Day = "Sunday";
if ($schedulemonday.is(':checked')) Day = "Monday";
if ($scheduletuesday.is(':checked')) Day = "Tuesday";
if ($schedulewednesday.is(':checked')) Day = "Wednesday";
if ($schedulethursday.is(':checked')) Day = "Thursday";
if ($schedulefriday.is(':checked')) Day = "Friday";
if ($schedulesaturday.is(':checked')) Day = "Saturday";
_Day = $scheduledate.val();
} else if ($scheduleweekly.is(':checked')) {
_Day = $weeklyselect.val();
}
// Broadcast zones (assuming comma-separated string)
const BroadcastZones = $schedulezones.val();
// Validate required fields
if (!Description || !Soundpath || Day === "") {
alert("Description, sound path, and day are required.");
return;
}
const Language = $languageselect.val().join(';');
const broadcastZones = $schedulezones.val().join(';');
// Format time as HH:mm
const hour = parseInt($schedulehour.val(), 10);
const minute = parseInt($scheduleminute.val(), 10);
const Time = `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
const _Time = `${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`;
console.log(`Adding schedule: Description=${Description}, Day=${_Day}, Time=${_Time}, Message=${Message}, Repeat=${Repeat}, Enable=${Enable}, BroadcastZones=${broadcastZones}, Language=${Language}`);
if (Description.length > 0) {
if (_Day.length > 0) {
if (Message.length > 0) {
if (Language.length > 0) {
if (broadcastZones.length > 0) {
// Prepare object
const scheduleObj = {
Description: Description,
Day: _Day,
Time: _Time,
Soundpath: Message,
Repeat: Repeat,
Enable: Enable,
BroadcastZones: broadcastZones,
Language: Language
};
// Prepare object
const scheduleObj = {
Description,
Day,
Time,
Soundpath,
Repeat,
Enable,
BroadcastZones
};
fetchAPI(APIURL + "Add", "POST", {}, scheduleObj, (okdata) => {
alert("Success add schedule: " + okdata.message);
reloadTimerBank(APIURL);
}, (errdata) => {
alert("Error add schedule: " + errdata.message);
});
$schedulemodal.modal('hide');
fetchAPI(APIURL + "Add", "POST", {}, scheduleObj, (okdata) => {
alert("Success add schedule: " + okdata.message);
reloadTimerBank(APIURL);
}, (errdata) => {
alert("Error add schedule: " + errdata.message);
});
$schedulemodal.modal('hide');
} else alert("At least one Broadcast Zone is required");
} else alert("Language is required");
} else alert("Message is required");
} else alert("Day is required");
} else alert("Description is required");
});
});
$btnRemove.click(() => {
@@ -282,13 +333,15 @@ $(document).ready(function () {
}
if (confirm(`Are you sure to edit schedule [${sr.index}] Description=${sr.description}?`)) {
$schedulemodal.modal('show');
clearScheduleModal();
// fill the form with existing data
$scheduleid.val(sr.index);
$scheduledescription.val(sr.description);
let [hour, minute] = sr.time.split(':').map(num => parseInt(num, 10));
$schedulehour.val(hour.toString());
$scheduleminute.val(minute.toString());
$schedulesoundpath.val(sr.soundpath);
$schedulemessage.val(sr.soundpath);
$schedulerepeat.val(sr.repeat.toString());
$scheduleenable.prop('checked', sr.enable.toLowerCase() === 'true');
switch (sr.day) {
@@ -331,7 +384,7 @@ $(document).ready(function () {
$schedulemodal.off('click.schedulesave').on('click.schedulesave', '#schedulesave', function () {
// Gather form values
const Description = $scheduledescription.val();
const Soundpath = $schedulesoundpath.val();
const Soundpath = $schedulemessage.val();
const Repeat = parseInt($schedulerepeat.val(), 10);
const Enable = $scheduleenable.is(':checked');
// Collect selected days