forked from Simnation/Main
111 lines
No EOL
3 KiB
JavaScript
111 lines
No EOL
3 KiB
JavaScript
class Investigation{
|
|
constructor(){
|
|
this.name = "investigation";
|
|
}
|
|
|
|
static allowAddNew(){
|
|
return userrights.has("investigation.edit");
|
|
}
|
|
static allowEdit(){
|
|
return userrights.has("investigation.edit");
|
|
}
|
|
static allowDelete(){
|
|
return userrights.has("investigation.delete");
|
|
}
|
|
static allowClose(){
|
|
return userrights.has("investigation.close");
|
|
}
|
|
|
|
static GetExtraForView(data){
|
|
let retval = {
|
|
top:"",
|
|
bottom:""
|
|
}
|
|
|
|
let closeTxt = getTranslation("close");
|
|
let closedValueNew = 1;
|
|
if(data.closed){
|
|
closeTxt = getTranslation("reopen");
|
|
closedValueNew = 0;
|
|
}
|
|
|
|
let buttons = ``;
|
|
|
|
if(this.allowAddNew()){
|
|
buttons += `<button type="button" class="btn btn-sm btn-success" onclick="loadPage('investigationentry.add',-1,'false',{data:{investigation_id:'${data.id}'}})">${getTranslation("add_entry")}</button>`;
|
|
}
|
|
if(this.allowClose()){
|
|
buttons += `<button type="button" class="btn btn-sm btn-primary" onclick="changeDataInColumn('investigation','closed','${data.id}','${closedValueNew}')">${closeTxt}</button>`;
|
|
}
|
|
|
|
|
|
retval.bottom += `
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-6 pb-6">
|
|
${buttons}
|
|
</div>
|
|
`;
|
|
|
|
|
|
if(data.extraData.entries !== undefined && data.extraData.entries !== null && data.extraData.entries.length > 0){
|
|
retval.bottom += System.GetTable(InvestigationEntry, data.extraData.entries);
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
static TableDataCreate(row, key){
|
|
if(key == "id"){
|
|
return `
|
|
<td>
|
|
${Form.getViewButtonIcon(row[key], this.name + ".view")}
|
|
${Form.getEditButtonIcon(row[key] , this.name + ".edit", this.allowEdit())}
|
|
${Form.getDeleteButtonIcon(row[key], this.name, this.allowDelete())}
|
|
</td>`;
|
|
}
|
|
else if(key == "reason"){
|
|
|
|
let txt = row[key];
|
|
|
|
if(txt.length > 30){
|
|
txt = txt.substr(0,30) + "..";
|
|
}
|
|
return `
|
|
<td>
|
|
${txt}
|
|
</td>`;
|
|
}
|
|
else if(key == "state"){
|
|
if(row.closed){
|
|
return `<td><div class="badge badge-info font-bold">${getTranslation("tag_closed")}</div></td>`;
|
|
}
|
|
else{
|
|
return `<td><div class="badge badge-warning font-bold">${getTranslation("state_open")}</div></td>`;
|
|
}
|
|
}
|
|
else{
|
|
return `<td>${row[key]}</td>`;
|
|
}
|
|
}
|
|
|
|
static GetColumns(){
|
|
return ["name","reason","state","id"]
|
|
}
|
|
static GetEdit(data={}){
|
|
return {
|
|
"name": {
|
|
"val" : data.name ?? ""
|
|
,"type" : "text"
|
|
,"isRow": true
|
|
,"mandatory":true
|
|
}
|
|
,"reason": {
|
|
"val" : data.reason ?? ""
|
|
,"type" : "textarea"
|
|
,"isRow": true
|
|
,"mandatory":true
|
|
,autogrow: true
|
|
,rows:3
|
|
}
|
|
}
|
|
}
|
|
} |