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

777 lines
No EOL
25 KiB
JavaScript

class Files{
constructor(){
this.name = "files";
}
static allowAddNew(){
return userrights.has("files.edit") && !sync.isActive("files");
}
static allowEdit(){
return userrights.has("files.edit");
}
static allowDelete(ingoreSync=false){
return userrights.has("files.delete") && (!sync.isActive("files") || ingoreSync);
}
static allowClose(){
return userrights.has("files.close");
}
static allowBlacken(){
return userrights.has("files.blacken");
}
static allowShare(){
return userrights.has("files.share");
}
static allowLicenses(){
return userrights.has("files.licenses");
}
static allowFinishmanhunt(){
return userrights.has("manhunt.finish");
}
static allowFinishEntry(){
return userrights.has("filesentry.finish");
}
static GetColumns(){
if(currentSystem == "police"){
return ["name","alias","phone","shared","state","id"];
}
else if(currentSystem == "medic"){
return ["name","phone","shared","state","id"];
}
}
static GetPropertyHTML(data){
if(data.extraData.properties == null || data.extraData.properties == undefined){
return "";
}
else{
let tbody = ``;
for(let i=0; i<data.extraData.properties.length; i++){
let row = data.extraData.properties[i];
tbody += `
<tr>
<td>
${row.label}
</td>
<td>
<button type="button" class="btn btn-primary btn-sm" data-entering='${row.entering}' data-is-qs-housing="${row._is_qs_housing}" data-is-my-property="${row._is_myproperty}" onclick="GenerateRoute(this, true)">
<i class="fa-solid fa-location-dot"></i>
<button>
</td>
</tr>
`;
}
return `
<div class="collapse collapse-open border border-base-300 bg-base-100 rounded-box mt-4">
<div class="collapse-title text-xl font-medium">
${getTranslation("properties")}
</div>
<div class="collapse-content">
<table class="table table-compact w-full">
<thead>
<tr>
<th>
${getTranslation("name")}
</th>
<th>
</th>
</tr>
</thead>
<tbody>
${tbody}
</tbody>
</table>
</div>
</div>
`
}
}
static GetFileEntryHTML(data, allowButtons){
let html = ``;
let activeWantingRow = null;
if(data.fromsystem == "police"){
if(data.extraData.file_entries !== undefined){
let entryTypes = System.getFileEntryTypes();
html += `
<div class="collapse collapse-open border border-base-300 bg-base-100 rounded-box mt-4">
<div class="collapse-title text-xl font-medium">
${getTranslation("fileentry.overview")}
</div>
<div class="collapse-content">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-6">`;
for(let i=0;i<data.extraData.file_entries.length;i++){
//check if entry is even
let row = data.extraData.file_entries[i];
let bgColor = entryTypes[row.type_of_entry].color ?? "ghost";
let type_name = entryTypes[row.type_of_entry].name ?? "";
let badges = ``;
if(row.is_wanted){
if(row.is_wanted_done == 1){
badges += `<div class="badge badge-warning font-bold gap-2">${getTranslation("old_manhunt")}</div>`;
}
else{
if(activeWantingRow == null){
activeWantingRow = row;
}
badges += `<div class="badge badge-error font-bold gap-2">${getTranslation("active_manhunt")}</div>`;
}
}
badges += `<div class="badge badge-${bgColor} gap-2 font-bold">${type_name}</div>`;
if(row.closed){
badges += `<div class="badge badge-success gap-2 font-bold">${getTranslation("entry_finished")}</div>`;
}
let buttons = ``;
if(!row.closed && this.allowFinishEntry() && allowButtons == true){
buttons += `<button onclick="changeDataInColumn('fileentry','closed','${row.id}','1')" class="btn btn-primary btn-sm">${getTranslation("finish_file_entry")}</button>`;
}
if(this.allowDelete(true) && allowButtons == true){
buttons += `<button onclick="Form.openDeleteModal('${row.id}','fileentry')" class="btn btn-sm btn-error">${getTranslation("delete")}</button>`;
}
let content = row.content.replace(/\n/g,"<br>");
if(row.crimeData.length > 0){
content+="<br><br>";
content+=`<u>${getTranslation("fine_crime")}:</u><br>`;
let tempContent = "";
for(let j=0;j<row.crimeData.length;j++){
tempContent += (tempContent == "" ? "" : "<br>");
let crime = row.crimeData[j];
if(crime["_deleted"] == 1){
tempContent += "<s>";
}
tempContent+=crime.amount + "x " + crime.lawbook_shortname + " $" + crime.paragraph +" - "+crime.crime;
if(crime["_deleted"] == 1){
tempContent += "</s>";
}
}
content+=tempContent;
}
let temp = `
<div class="card w-full bg-neutral text-neutral-content">
<div class="card-body">
<h2 class="card-title uppercase font-bold">${row.file_entry_id}</h2>
<h2>${badges}</h2>
<p><strong>${System.buildEmployeeName(row.creator)} - ${System.formatTimestamp(row.creationdate)}</strong></p>
<p></p>
<p class="border border-current rounded-xl p-1 break-all">${content}</p>
<p></p>
<p></p>
<p><strong>${getTranslation("fine")}: </strong>${row.fine}</p>
<p><strong>${getTranslation("detention_time")}:</strong> ${row.detention_time}</p>
<div class="card-actions justify-start">
${buttons}
</div>
</div>
</div>
`;
if( i % 2 === 0){
temp += `<div></div>`
}
else{
temp = `<div></div>` + temp
}
html += temp;
}
html += `
</div>
</div>
</div>`;
}
}
else if(data.fromsystem == "medic"){
if(data.extraData.file_entries !== undefined){
let injuryTypes = [
"head"
,"left_shoulder"
,"left_arm"
,"left_hand"
,"right_shoulder"
,"right_arm"
,"right_hand"
,"chest"
,"stomach"
,"left_leg"
,"left_foot"
,"right_leg"
,"right_foot"
];
html += `
<div class="collapse collapse-open border border-base-300 bg-base-100 rounded-box mt-4">
<div class="collapse-title text-xl font-medium">
${getTranslation("fileentry.overview")}
</div>
<div class="collapse-content">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-6">`;
for(let i=0;i<data.extraData.file_entries.length;i++){
//check if entry is even
let row = data.extraData.file_entries[i];
let badges = ``;
if(row.closed){
badges += `<div class="badge badge-success gap-2">${getTranslation("entry_finished")}</div>`;
}
if(row.needs_follow_up_treatment){
badges += `<div class="badge badge-warning gap-2">${getTranslation("needs_follow_up_treatment")}</div>`;
}
let buttons = ``;
if(!row.closed && this.allowFinishEntry() && allowButtons == true){
buttons += `<button onclick="changeDataInColumn('fileentry','closed','${row.id}','1')" class="btn btn-sm btn-primary">${getTranslation("finish_file_entry")}</button>`;
}
if(this.allowDelete(true) && allowButtons == true){
buttons += `<button onclick="Form.openDeleteModal('${row.id}','fileentry')" class="btn btn-sm btn-error">${getTranslation("delete")}</button>`;
}
let knownInjuries = "";
for(let i=0; i<injuryTypes.length;i++){
if(row[`injury_${injuryTypes[i]}`]){
knownInjuries += `
<li>- ${getTranslation(injuryTypes[i])}</li>
`;
}
}
if(knownInjuries != ""){
knownInjuries = `
<ul>
${knownInjuries}
</ul>
`;
}
let temp = `
<div class="card w-full bg-neutral text-neutral-content">
<div class="card-body">
<h2 class="card-title uppercase font-bold">${row.file_entry_id}</h2>
<h2 class="card-title uppercase font-bold">${badges}</h2>
<p><strong>${System.buildEmployeeName(row.creator)} - ${System.formatTimestamp(row.creationdate)}</strong></p>
<p></p>
<p class="border border-current rounded-xl p-1 break-all">${row.content.replace(/\n/g,"<br>")}</p>
<p></p>
<p></p>
<p><strong>${getTranslation("intensity_of_wounds")}: </strong>${row.intensity_of_wounds}</p>
<p><strong>${getTranslation("type_of_bleeding")}:</strong> ${row.type_of_bleeding}</p>
<p><strong>${getTranslation("treatment")}:</strong> ${row.treatment}</p>
<div class="divider">${getTranslation("injuries")}</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 pt-2">
<div>${knownInjuries}</div>
<div class="border border-current rounded-xl p-1 col-span-2 break-all">${row.injury_summary.replace(/\n/g,"<br>")}</div>
</div>
<div class="card-actions justify-start">
${buttons}
</div>
</div>
</div>
`;
if( i % 2 === 0){
temp += `<div></div>`
}
else{
temp = `<div></div>` + temp
}
html += temp;
}
html += `
</div>
</div>
</div>`;
}
}
let retval = {
"html": html,
"activeWantingRow": activeWantingRow
};
return retval;
}
static GetLicensesHTML(data){
if(this.allowLicenses()){
let dropdown = ``;
let table = ``;
if(!sync.isActive("files_licenses") || currentSystem == "medic"){
if(data.extraData.possible_licenses !== undefined && data.extraData.possible_licenses.length>0){
let optionsHtml = ``;
for(let i=0; i<data.extraData.possible_licenses.length; i++){
optionsHtml += `<option value="${data.extraData.possible_licenses[i].id}">${data.extraData.possible_licenses[i].name}</option>`;
}
dropdown = `
<div class="w-full">
<div class="input-group w-full">
<select id="input-files-license" class="select select-sm select-bordered ignore-readonly">
${optionsHtml}
</select>
<button type="button" onclick="addLicenseToFile('${data.id}')" class="btn btn-sm btn-success">${getTranslation("add")}</button>
</div>
</div>
`;
}
}
if(data.extraData.given_licenses !== undefined && data.extraData.given_licenses.length>0){
let tbody = ``;
for(let i=0; i<data.extraData.given_licenses.length; i++){
let row = data.extraData.given_licenses[i];
if(!sync.isActive("files_licenses") || currentSystem == "medic"){
tbody += `
<tr>
<td>
${row.name}
</td>
<td>
<button type="button" class="btn btn-error btn-sm" onclick="deleteData('fileslicenses','${row.id}')">
${getTranslation("remove_license")}
</button>
</td>
</tr>
`;
}
else{
tbody += `
<tr>
<td>
${row.name}
</td>
<td>
</td>
</tr>
`;
}
tbody += `</tr>`
}
table = `
<table class="table table-compact w-full">
<thead>
<tr>
<th>
${getTranslation("name")}
</th>
<th>
</th>
</tr>
</thead>
<tbody>
${tbody}
</tbody>
</table>
`;
}
return `
<div class="collapse collapse-open border border-base-300 bg-base-100 rounded-box mt-4">
<div class="collapse-title text-xl font-medium">
${getTranslation("licenses.overview")}
</div>
<div class="collapse-content">
${dropdown}
${table}
</div>
</div>
`
}
}
static GetExtraForView(data){
let retval = {
top:"",
bottom:"",
initTableButtons:false,
}
if(currentSystem == "police"){
let blackenTxt = getTranslation("blacken");
let shareTxt = getTranslation("share");
let closeTxt = getTranslation("close");
let blacken_new = 1;
let closed_new = 1;
let shared_new = 1;
if(data.blackend){
blackenTxt = getTranslation("deblacken");
blacken_new = 0;
}
if(data.closed){
closeTxt = getTranslation("reopen");
closed_new = 0;
}
if(data.is_shared){
shareTxt = getTranslation("unshare");
shared_new = 0;
}
let buttons = ``;
let cnt = 0;
if(this.allowEdit()){
cnt++;
//buttons += `<button type="button" class="btn btn-sm btn-success" onclick="loadPage('fileentry.add',-1,'false',{data:{file_id:'${data.id}'}})">${getTranslation("fileentry.add")}</button>`;
buttons += `<button type="button" class="btn btn-sm btn-success" onclick="loadPage('fileentry.add','${data.id}','true')">${getTranslation("fileentry.add")}</button>`;
}
if(this.allowBlacken()){
cnt++;
buttons += `<button type="button" class="btn btn-sm btn-warning" onclick="changeDataInColumn('files','blackend','${data.id}','${blacken_new}')">${blackenTxt}</button>`;
}
if(this.allowClose()){
cnt++;
buttons += `<button type="button" class="btn btn-sm btn-error" onclick="changeDataInColumn('files','closed','${data.id}','${closed_new}')">${closeTxt}</button>`;
}
if(this.allowShare()){
cnt++;
buttons += `<button type="button" class="btn btn-sm btn-primary" onclick="changeDataInColumn('sharedfiles','is_shared','${data.id}','${shared_new}')">${shareTxt}</button>`;
}
retval.bottom += `
<div class="grid grid-cols-1 md:grid-cols-${cnt} gap-4 pt-6">
${buttons}
</div>
`;
let activeWantingRow = null;
retval.bottom += this.GetLicensesHTML(data);
retval.bottom += this.GetPropertyHTML(data);
if(RegVehicle.allowView()){
if(data.extraData.vehicles !== undefined){
retval.bottom += `
<div class="collapse collapse-open border border-base-300 bg-base-100 rounded-box mt-4">
<div class="collapse-title text-xl font-medium">
${getTranslation("regvehicle.overview")}
</div>
<div class="collapse-content">
${System.GetTable(RegVehicle, data.extraData.vehicles)}
</div>
</div>
`;
retval.initTableButtons = true
}
}
let temp = this.GetFileEntryHTML(data, true)
retval.bottom += temp.html;
activeWantingRow = temp.activeWantingRow;
if(activeWantingRow !== null){
let btn = ``;
if(this.allowFinishmanhunt()){
btn = `<button onclick="finishManhunt('filesentry','${data.id}')" class="btn btn-sm btn-primary">${getTranslation("is_wanted_end")}</button>`;
}
retval.top = `
<div class="card w-full bg-error text-error-content">
<div class="card-body">
<h2 class="card-title uppercase font-bold">${getTranslation("vehicle_wanted")}</h2>
<p><strong>${System.buildEmployeeName(activeWantingRow.creator)} - ${System.formatTimestamp(activeWantingRow.creationdate)}</strong></p>
<p></p>
<p class="border border-current rounded-xl p-1 break-all">${activeWantingRow.content.replace(/\n/g,"<br>")}</p>
<div class="card-actions justify-start">
${btn}
</div>
</div>
</div>
`;
}
}
else if(currentSystem == "medic"){
let blackenTxt = getTranslation("blacken");
let closeTxt = getTranslation("close");
let blacken_new = 1;
let closed_new = 1;
let shareTxt = getTranslation("share");
let shared_new = 1;
if(data.blackend){
blackenTxt = getTranslation("deblacken");
blacken_new = 0;
}
if(data.closed){
closeTxt = getTranslation("reopen");
closed_new = 0;
}
if(data.is_shared){
shareTxt = getTranslation("unshare");
shared_new = 0;
}
let buttons = ``;
let cnt = 0;
if(this.allowEdit()){
cnt++;
buttons += `<button type="button" class="btn btn-sm btn-success" onclick="loadPage('fileentry.add',-1,'false',{data:{file_id:'${data.id}'}})">${getTranslation("fileentry.add")}</button>`;
}
if(this.allowBlacken()){
cnt++;
buttons += `<button type="button" class="btn btn-sm btn-warning" onclick="changeDataInColumn('files','blackend','${data.id}','${blacken_new}')">${blackenTxt}</button>`;
}
if(this.allowClose()){
cnt++;
buttons += `<button type="button" class="btn btn-sm btn-error" onclick="changeDataInColumn('files','closed','${data.id}','${closed_new}')">${closeTxt}</button>`;
}
if(this.allowShare()){
cnt++;
buttons += `<button type="button" class="btn btn-sm btn-primary" onclick="changeDataInColumn('sharedfiles','is_shared','${data.id}','${shared_new}')">${shareTxt}</button>`;
}
retval.bottom += `
<div class="grid grid-cols-1 md:grid-cols-${cnt} gap-4 pt-6">
${buttons}
</div>
`;
retval.bottom += this.GetLicensesHTML(data);
let temp = this.GetFileEntryHTML(data, true)
retval.bottom += temp.html;
}
return retval;
}
static TableDataCreate(row, key){
if(key == "state"){
let badges = ``;
if(row[key] != ""){
badges += `<div class="badge badge-error font-bold">${getTranslation("tag_" + row[key])}</div>`;
}
if(row.blackend){
badges += `<div class="badge badge-warning font-bold">${getTranslation("tag_blackend")}</div>`;
}
if(row.closed){
badges += `<div class="badge badge-info font-bold">${getTranslation("tag_closed")}</div>`;
}
return `<td>${badges}</td>`;
}
else if(key == "id"){
let isWantedButton = ``;
if(currentSystem == "police"){
if(this.allowEdit()){
isWantedButton = Form.getIsWantedButton(row[key], this.name, row.state == "is_wanted");
}
}
return `
<td>
${Form.getViewButtonIcon(row[key], this.name + ".view")}
${Form.getEditButtonIcon(row[key] , this.name + ".edit", this.allowEdit())}
${isWantedButton}
${Form.getDeleteButtonIcon(row[key], this.name , this.allowDelete())}
</td>`;
}
else if(key == "shared"){
if(row[key]){
return `
<td class="font-bold">
<i class="fa-solid fa-check"></i>
</td>
`;
}
else{
return `<td></td>`;
}
}
else{
return `<td>${row[key]}</td>`;
}
}
static GetEdit(data = {}){
if(currentSystem == "police"){
return {
"name": {
"val" : data.name ?? ""
,"type" : "text"
,"mandatory":true
}
,"alias": {
"val" : data.alias ?? ""
,"type" : "text"
,"mandatory":true
}
,"sex": {
"val" : data.sex ?? ""
,"type" : "dropdown"
,"mandatory":true
,"options":[
{id:0, name:getTranslation("unknown")},
{id:1, name:getTranslation("male")},
{id:2, name:getTranslation("female")},
{id:3, name:getTranslation("diverse")}
]
}
,"phone": {
"val" : data.phone ?? ""
,"type" : "text"
,"mandatory":false
}
,"size": {
"val" : data.size ?? ""
,"type" : "number"
,"mandatory":false
}
,"birth": {
"val" : data.birth ?? ""
,"type" : "date"
,"mandatory":false
}
,"eyecolor": {
"val" : data.eyecolor ?? ""
,"type" : "text"
,"mandatory":false
}
,"haircolor": {
"val" : data.haircolor ?? ""
,"type" : "text"
,"mandatory":false
}
};
}
else if(currentSystem == "medic"){
return {
"name": {
"val" : data.name ?? ""
,"type" : "text"
,"mandatory":true
,"isRow":true
}
,"blood_type": {
"val" : data.blood_type ?? "A"
,"type" : "dropdown"
,"mandatory":true
,options:[
{id:"A", name:"A+"},
{id:"A-", name:"A-"},
{id:"B", name:"B+"},
{id:"B-", name:"B-"},
{id:"AB", name:"AB+"},
{id:"AB-", name:"AB-"},
{id:"0", name:"0+"},
{id:"0-", name:"0-"},
]
}
,"sex": {
"val" : data.sex ?? ""
,"type" : "dropdown"
,"mandatory":true
,"options":[
{id:0, name:getTranslation("unknown")},
{id:1, name:getTranslation("male")},
{id:2, name:getTranslation("female")},
{id:3, name:getTranslation("diverse")}
]
}
,"phone": {
"val" : data.phone ?? ""
,"type" : "text"
,"mandatory":false
}
,"birth": {
"val" : data.birth ?? ""
,"type" : "date"
,"mandatory":false
}
,"size": {
"val" : data.size ?? ""
,"type" : "number"
,"mandatory":false
}
,"weight": {
"val" : data.weight ?? ""
,"type" : "number"
,"mandatory":false
}
,"allergies": {
"val" : data.allergies ?? ""
,"type" : "textarea"
,"mandatory":false
,rows:3
}
,"known_illnesses": {
"val" : data.known_illnesses ?? ""
,"type" : "textarea"
,"mandatory":false
,rows:3
}
};
}
}
}