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

138 lines
No EOL
3.3 KiB
JavaScript

class EvidenceRoomArticles{
constructor(){
this.name = "evidenceroomarticles";
}
static isCustom(){
return true;
}
static allowEdit(){
return userrights.has("evidencerooms.edit");
}
static allowDelete(){
return userrights.has("evidencerooms.delete");
}
static GetColumns(isReadOnly){
if(isReadOnly == true){
return ["name","amount","file_name","state","changedate"]
}
else{
return ["name","amount","file_name","state","changedate","id"]
}
}
static TableDataCreate(row, key,isReadOnly){
if(key == "id"){
return `
<td>
${Form.getEditButtonIcon(row[key], this.name + ".edit", this.allowEdit())}
${Form.getDeleteButtonIcon(row[key], this.name ,this.allowDelete())}
</td>`;
}
else if(key == "changedate") {
return `<td>${row[key]}<br>${System.buildEmployeeName(row.changedby)}</td>`;
}
else if(key == "state"){
let state = this.GetStateByID(row[key]);
return `
<td>
<div class="badge font-bold ${state.color ?? ""}">${state.name ?? ""}</div>
</td>`;
}
else if(key == "file_name"){
let val = row[key];
if(val == ""){
val = getTranslation("unknown");
}
return `
<td>
${val}
</td>`;
}
else {
return `<td>${row[key]}</td>`;
}
}
static GetEdit(data={}){
let filesOptions = [
{"id":-1, "name":getTranslation("unknown")}
,{"id":-2, "name":getTranslation("new_file"), "show_extra_field":true}
];
if(sync.isActive("files")){
filesOptions = [
{"id":-1, "name":getTranslation("unknown")}
];
}
let files = [...filesOptions, ...data.extraData.files];
return {
"evidenceroom_id": {
"val" : data.evidenceroom_id ?? "-1"
,"type" : "hidden"
},
"name": {
"val" : data.name ?? ""
,"type" : "text"
,"isRow":true
,"mandatory":true
}
,"amount": {
"val" : data.amount ?? ""
,"type" : "number"
,"isRow":true
,"mandatory":true
}
,"state": {
"val" : data.state ?? 0
,"type" : "dropdown"
,"isRow":true
,"mandatory":true
,options:this.GetStateOptions()
}
,"file_id": {
"val" : data.file_id ?? -1
,"type" : "searchdropdown"
,"mandatory":true
,"isRow":true
,options:files
}
}
}
static GetStateOptions(){
let retval = [];
let json = this.GetStates();
Object.keys(json).forEach(function(key){
retval.push({"id": key, "name":json[key].name })
});
return retval;
}
static GetStates(){
return {
"0" : {name:getTranslation("state_new"), "color":"badge-primary"},
"1" : {name:getTranslation("state_inprogress"), "color":"badge-warning"},
"2" : {name:getTranslation("state_stored"), "color":"badge-success"},
"3" : {name:getTranslation("state_destoyed"), "color":"badge-error"}
}
}
static GetStateByID(id){
return this.GetStates()[id] ?? {}
}
}