forked from Simnation/Main
162 lines
No EOL
4.3 KiB
JavaScript
162 lines
No EOL
4.3 KiB
JavaScript
class RegWeapons{
|
|
constructor(){
|
|
this.name = "regweapons";
|
|
}
|
|
|
|
static allowAddNew(){
|
|
return userrights.has("regweapons.edit");
|
|
}
|
|
static allowEdit(){
|
|
return userrights.has("regweapons.edit");
|
|
}
|
|
static allowDelete(){
|
|
return userrights.has("regweapons.delete");
|
|
}
|
|
static allowFinishmanhunt(){
|
|
return userrights.has("manhunt.finish");
|
|
}
|
|
static allowSetManhunt(){
|
|
return userrights.has("manhunt.add");
|
|
}
|
|
|
|
|
|
static GetColumns(){
|
|
return ["serialno","weapontype","weaponmodel","owner","state","id"]
|
|
}
|
|
|
|
static GetExtraForView(data){
|
|
let retval = {
|
|
top:"",
|
|
bottom:""
|
|
}
|
|
|
|
if(data.is_wanted == 1){
|
|
let btn = ``;
|
|
if(this.allowFinishmanhunt()){
|
|
btn = `<button onclick="finishManhunt('${this.name}','${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>${getTranslation("reason")}: </strong>${data.is_wanted_reason}</p>
|
|
<p></p>
|
|
<p>${getTranslation("is_wanted_at_sight")}</p>
|
|
<div class="card-actions justify-start">
|
|
${btn}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
static TableDataCreate(row, key){
|
|
if(key == "state"){
|
|
if(row[key] == true){
|
|
return `<td><div class="badge badge-error font-bold">${getTranslation("tag_is_wanted")}</div></td>`;
|
|
}
|
|
else{
|
|
return `<td></td>`;
|
|
}
|
|
}
|
|
else if(key == "id"){
|
|
let isWantedButton = ``;
|
|
|
|
if(this.allowSetManhunt()){
|
|
isWantedButton = Form.getIsWantedButton(row[key], this.name, row.state == "1");
|
|
}
|
|
|
|
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 == "owner"){
|
|
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")}
|
|
];
|
|
}
|
|
|
|
filesOptions = [...filesOptions, ...data.extraData.files];
|
|
|
|
return {
|
|
"serialno": {
|
|
"val" : data.serialno ?? ""
|
|
,"type" : "text"
|
|
,"mandatory":true
|
|
}
|
|
,"owner": {
|
|
"val" : data.owner_id ?? "-1"
|
|
,"type" : "searchdropdown"
|
|
,"mandatory":false
|
|
,options:filesOptions
|
|
}
|
|
,"weapontype": {
|
|
"val" : data.weapontype ?? ""
|
|
,"type" : "text"
|
|
,"mandatory":false
|
|
}
|
|
,"weaponmodel": {
|
|
"val" : data.weaponmodel ?? ""
|
|
,"type" : "text"
|
|
,"mandatory":false
|
|
}
|
|
,"-": {
|
|
"type" : "divider"
|
|
}
|
|
,"others": {
|
|
"val" : data.others ?? ""
|
|
,"type" : "textarea"
|
|
,"isRow": true
|
|
,"mandatory":false
|
|
,autogrow: true
|
|
,rows:3
|
|
}
|
|
,"is_wanted": {
|
|
"val" : (data.is_wanted ?? false ? 1 : 0)
|
|
,"type" : (this.allowSetManhunt() ? "dropdown" : "hidden")
|
|
,"isRow": true
|
|
,"mandatory":false
|
|
,hideInViewMode:true
|
|
,"options":System.GetBooleanOptions()
|
|
}
|
|
,"is_wanted_reason": {
|
|
"val" : data.is_wanted_reason ?? ""
|
|
,"type" : (this.allowSetManhunt() ? "text" : "hidden")
|
|
,"isRow": true
|
|
,hideInViewMode:true
|
|
,"mandatory":false
|
|
}
|
|
}
|
|
}
|
|
} |