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

117 lines
No EOL
3.7 KiB
JavaScript

class EvidenceRooms{
constructor(){
this.name = "evidencerooms";
}
static allowAddNew(){
return userrights.has("evidencerooms.edit");
}
static allowEdit(){
return userrights.has("evidencerooms.edit");
}
static allowDelete(){
return userrights.has("evidencerooms.delete");
}
static isCustom(){
return true;
}
static CreateCustom(data, isEditMode = false){
let retval = ``;
if(!isEditMode){
document.getElementById("currentpage-content").innerHTML = Form.overviewHeadline(this.name.toLowerCase() + ".add", false, this.allowAddNew());
}
for(let i=0; i<data.data.length; i++){
let row = data.data[i];
let buttons = ``;
let bottomButton = ``;
let mbClass = "";
let mtClass = "";
if(this.allowAddNew()){
buttons += `<button type="button" class="btn btn-sm btn-success evidencerooms-add-entry" data-parentID="${row.id}">${getTranslation("add_entry")}</button>`;
}
if(this.allowEdit()){
buttons += `<button type="button" class="btn btn-sm btn-warning evidencerooms-edit" data-parentID="${row.id}">${getTranslation("edit")}</button>`;
}
if(this.allowDelete()){
buttons += `<button type="button" class="btn btn-sm btn-error" onclick="Form.openDeleteModal(${row.id}, 'evidencerooms')">${getTranslation("delete")}</button>`;
}
if(this.allowEdit()){
bottomButton += `<button type="button" class="btn btn-sm btn-block btn-primary evidencerooms-history" data-parentID="${row.id}">${getTranslation("view_destroyed")}</button>`;
}
if(buttons != ""){
mbClass = "mb-2";
}
if(bottomButton != ""){
mtClass = "mt-2";
}
if(!isEditMode || row.laws.length > 0){
retval += `
<div class="collapse collapse-arrow border border-base-300 bg-base-100 rounded-box mt-4">
<input type="checkbox" />
<div class="collapse-title text-xl font-medium">
${row.name}
</div>
<div class="collapse-content">
<div class="${mbClass}">
${buttons}
</div>
${System.GetTable(System.getClassByName("evidenceroomarticles"), row.articles)}
<div class = "${mtClass}">
${bottomButton}
</div>
</div>
</div>
`;
}
}
document.getElementById("currentpage-content").innerHTML += retval;
Form.initTableButtons();
Array.from(document.querySelectorAll(".evidencerooms-add-entry")).forEach(function(button){
button.onclick = function(){
let staticData = {
data:{
evidenceroom_id:this.getAttribute("data-parentID")
}
}
loadPage("evidenceroomarticles.add",this.getAttribute("data-parentID"),"false", staticData)
}
});
Array.from(document.querySelectorAll(".evidencerooms-edit")).forEach(function(button){
button.onclick = function(){
loadPage("evidencerooms.edit",this.getAttribute("data-parentID"),"true", {})
}
});
Array.from(document.querySelectorAll(".evidencerooms-history")).forEach(function(button){
button.onclick = function(){
loadPage("evidenceroomarticlesdestroyed.dataload",this.getAttribute("data-parentID"),"true", {})
}
});
}
static GetEdit(data={}){
return {
"name": {
"val" : data.name ?? ""
,"type" : "text"
,"mandatory":true
,"isRow":true
}
}
}
}