commit 23/09/2025

This commit is contained in:
2025-09-23 13:56:16 +07:00
parent 7c67fe90ee
commit 85ccf05634
8 changed files with 237 additions and 56 deletions

View File

@@ -123,7 +123,17 @@ $(document).ready(function () {
function clearBroadcastZoneModal() {
$broadcastzoneindex.prop('disabled', true).val('');
$broadcastzonedescription.val('');
$broadcastzonesoundchannel.val('');
// fill broadcastzonesoundchannel from SoundChannelList
$broadcastzonesoundchannel.empty();
if (Array.isArray(SoundChannelList) && SoundChannelList.length > 0) {
// SoundChannelList ada isinya
SoundChannelList.forEach(ch => {
if (ch.channel && ch.channel.length > 0){
// hanya yang punya channel saja
$broadcastzonesoundchannel.append($('<option>').val(ch.channel).text(ch.channel));
}
});
}
$broadcastzonebox.val('');
for (let i = 1; i <= 32; i++) {
cbRelay(i).prop('checked', false);
@@ -179,7 +189,7 @@ $(document).ready(function () {
Box: box,
Relay: relay
};
fetchAPI(APIURL_BroadcastZone + "Add", "POST", bz, null, (okdata) => {
fetchAPI(APIURL_BroadcastZone + "Add", "POST", {}, bz, (okdata) => {
reloadBroadcastZones(APIURL_BroadcastZone);
alert("Success add new broadcast zone: " + okdata.message);
}, (errdata) => {
@@ -272,7 +282,7 @@ $(document).ready(function () {
Box: box,
Relay: relay
};
fetchAPI(APIURL_BroadcastZone + "UpdateByIndex/" + bz.index, "PATCH", bzUpdate, null, (okdata) => {
fetchAPI(APIURL_BroadcastZone + "UpdateByIndex/" + bz.index, "PATCH", {}, bzUpdate, (okdata) => {
reloadBroadcastZones(APIURL_BroadcastZone);
alert("Success edit broadcast zone: " + okdata.message);
}, (errdata) => {

View File

@@ -69,9 +69,16 @@ function fetchAPI(endpoint, method, headers = {}, body = null, cbOK, cbError) {
}
}
fetch(url, options)
.then(response => {
.then(async(response) => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
let msg ;
try{
let _xxx = await response.json();
msg = _xxx.message || response.statusText;
} catch {
msg = await response.statusText;
}
throw new Error(msg);
}
return response.json();
})

View File

@@ -150,7 +150,9 @@ $(document).ready(function () {
return;
}
fetchAPI(API_SoundChannel + "UpdateByIndex/" + newsc.index, "PATCH", newsc, null, (okdata) => {
fetchAPI(API_SoundChannel + "UpdateByIndex/" + newsc.index, "PATCH", {}, newsc, (okdata) => {
reloadSoundChannel(API_SoundChannel);
alert("Success edit sound channel: " + okdata.message);
}, (errdata) => {

View File

@@ -282,8 +282,8 @@
</div>
</div>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/broadcastzones.js"></script>
<script src="assets/js/soundchannel.js"></script>
<script src="assets/js/broadcastzones.js"></script>
</body>
</html>