1
0
Fork 0
forked from Simnation/Main
Main/resources/[jobs]/[mdt]/myEmergency/html/js/modules/RadioState.js
2025-08-14 13:21:51 +02:00

118 lines
No EOL
3.7 KiB
JavaScript

class RadioState{
constructor(){
this.name = "radio_state";
}
static allowAddNew(){
return userrights.has("radiostate.edit")
}
static allowEdit(){
return userrights.has("radiostate.edit")
}
static allowDelete(){
return userrights.has("radiostate.delete")
}
static GetExtraForOverview(data){
let retval = {
top:"",
bottom:""
}
let buttons = ``;
let radioDetails = System.getRadioState(data.current_state_vehicle, data.current_state_person);
let currentRadio = radioDetails.radio_default;
if(radioDetails.vehicle == null){
if(radioDetails.radio !== null){
currentRadio = data.current_state_person[0].state_name
buttons = `
<button type="button" class="btn btn-sm btn-primary" onclick="SetRadioState(-1,'radiostate.overview')">${getTranslation("emergency_vehicles_no_radio")}</button>
`
}
}
else{
currentRadio = currentRadio + " (" + radioDetails.vehicle + ")"
if(radioDetails.radio !== null){
currentRadio = radioDetails.radio + " (" + radioDetails.vehicle + ")"
buttons = `
<button type="button" class="btn btn-sm btn-warning" onclick="SetVehicle(-1,'radiostate.overview')">${getTranslation("leave_patrol")}</button>
<button type="button" class="btn btn-sm btn-primary" onclick="SetRadioState(-1,'radiostate.overview')">${getTranslation("emergency_vehicles_no_radio")}</button>
`
}
else{
buttons = `
<button type="button" class="btn btn-sm btn-warning" onclick="SetVehicle(-1,'radiostate.overview')">${getTranslation("leave_patrol")}</button>
`
}
}
retval.top = `
<div class="alert alert-info shadow-lg mb-4">
<div>
<div>${getTranslation("current_state")}: <strong>${currentRadio}</strong></div>
<div>
${buttons}
</div>
</div>
</div>
`;
return retval;
}
static GetColumns(){
return ["name","short_name","setstate","id"]
}
static TableDataCreate(row, key){
let FgColor = System.GetFgColorByBgColor(row["color"]);
if(key == "id"){
return `
<td style="color:${FgColor}; background:${row["color"]}">
${Form.getEditButtonIcon(row[key] , this.name + ".edit", this.allowEdit())}
${Form.getDeleteButtonIcon(row[key], this.name, this.allowDelete())}
</td>`;
}
else if(key == "setstate"){
return `
<td style="color:${FgColor}; background:${row["color"]}">
<button type="button" class="btn btn-sm btn-primary" onclick="SetRadioState(${row["id"]},'radiostate.overview')">${getTranslation("set_state")}</button>
</td>`;
}
else if(key != "id"){
return `<td style="color:${FgColor}; background:${row["color"]}">${row[key]}</td>`;
}
else{
return `<td style="color:${FgColor}; background:${row["color"]}">${row[key]}</td>`;
}
}
static GetEdit(data = {}){
return {
"name": {
"val" : data.name ?? ""
,"type" : "text"
,"isRow": true
,"mandatory":true
}
,"short_name": {
"val" : data.short_name ?? ""
,"type" : "text"
,"isRow": true
,"mandatory":true
}
,"color": {
"val" : data.color ?? ""
,"type" : "dropdown"
,"isRow": true
,"mandatory":true
,options:System.GetColorOptions()
}
}
}
}