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 ` ${Form.getEditButtonIcon(row[key], this.name + ".edit", this.allowEdit())} ${Form.getDeleteButtonIcon(row[key], this.name ,this.allowDelete())} `; } else if(key == "changedate") { return `${row[key]}
${System.buildEmployeeName(row.changedby)}`; } else if(key == "state"){ let state = this.GetStateByID(row[key]); return `
${state.name ?? ""}
`; } else if(key == "file_name"){ let val = row[key]; if(val == ""){ val = getTranslation("unknown"); } return ` ${val} `; } else { return `${row[key]}`; } } 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] ?? {} } }