class RegVehicleImpounded{
constructor(){
this.name = "regvehicleimpounded";
}
static allowView(){
return userrights.has("regvehicles.view");
}
static allowAddNew(){
return false;
}
static allowEdit(){
return userrights.has("regvehicles.edit");
}
static allowDelete(){
return userrights.has("regvehicles.delete") && !sync.isActive("regvehicle");
}
static allowFinishmanhunt(){
return userrights.has("manhunt.finish");
}
static allowSetManhunt(){
return userrights.has("manhunt.add");
}
static GetColumns(){
return ["plate","veh_type","veh_model","owner","mot","state","id"]
}
static GetExtraForView(data){
let retval = {
top:"",
bottom:""
}
if(data.is_wanted == 1){
let btn = ``;
if(this.allowFinishmanhunt()){
btn = ``
}
retval.top = `
${getTranslation("vehicle_wanted")}
${getTranslation("reason")}: ${data.is_wanted_reason}
${getTranslation("is_wanted_at_sight")}
${btn}
`
}
return retval;
}
static TableDataCreate(row, key){
if(key == "state"){
let badges = ""
if(row["Impounded"] == 1){
badges += `${getTranslation("tag_impounded")}
`;
}
if(row[key] == "1"){
badges += `${getTranslation("tag_is_wanted")}
`;
}
return `
${badges}
| `;
}
else if(key == "id"){
let isWantedButton = ``;
if(this.allowSetManhunt()){
isWantedButton = Form.getIsWantedButton(row[key], this.name, row.state == "1");
}
return `
${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())}
| `;
}
else if(key == "owner"){
let val = row[key];
if(val == ""){
val = getTranslation("unknown");
}
return `
${val}
| `;
}
else if(key == "mot"){
if(row[key] == ""){
return ` | `;
}
if(new Date(row[key]) < new Date()){
return `
${System.formatDate(row[key])}
| `
;
}
else{
return `
${System.formatDate(row[key])}
| `
;
}
}
else{
return `${row[key]} | `;
}
}
static GetEdit(data={}, readMode = false){
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];
if(!readMode && UseMotDateFromMyMechanicMDT){
return {
"plate": {
"val" : data.plate ?? ""
,"type" : "text"
,"mandatory":true
}
,"owner": {
"val" : data.owner ?? "-1"
,"type" : "searchdropdown"
,"mandatory":false
,options:filesOptions
}
,"veh_type": {
"val" : data.veh_type ?? ""
,"type" : "text"
,"mandatory":false
,isRow:true
}
,"veh_model": {
"val" : data.veh_model ?? ""
,"type" : "text"
,"mandatory":false
}
,"color": {
"val" : data.color ?? ""
,"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
}
}
}
else{
return {
"plate": {
"val" : data.plate ?? ""
,"type" : "text"
,"mandatory":true
}
,"owner": {
"val" : data.owner ?? "-1"
,"type" : "searchdropdown"
,"mandatory":false
,options:filesOptions
}
,"veh_type": {
"val" : data.veh_type ?? ""
,"type" : "text"
,"mandatory":false
}
,"mot": {
"val" : data.mot ?? ""
,"type" : "date"
,"mandatory":false
}
,"veh_model": {
"val" : data.veh_model ?? ""
,"type" : "text"
,"mandatory":false
}
,"color": {
"val" : data.color ?? ""
,"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
}
}
}
}
}