class RegVehicle{ constructor(){ this.name = "regvehicle"; } static allowView(){ return userrights.has("regvehicles.view"); } static allowAddNew(){ return userrights.has("regvehicles.edit") && !sync.isActive("regvehicle"); } 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}
` } if(data.extraData.mot_data !== undefined && data.extraData.mot_data !== null && showLastMotDetailFromMyMechanicMDT){ let cardContent = ""; if(data.extraData.mot_data.length > 0){ let row = data.extraData.mot_data[0]; let contentHtml = ``; if(row.note !== undefined && row.note !== null && row.note.replace(/ /g, "") != ""){ contentHtml = `

${row.note.replace(/\n/g,"
")}

`; } cardContent = `

${System.buildEmployeeName(row.creator)} - ${System.formatTimestamp(row.createddate)}

${getTranslation("passed")}: ${getTranslation(row.passed == 1 ? "yes": "no")}

${getTranslation("new_mot")}: ${System.formatDate(row.new_mot) }

${getTranslation("old_mot")}: ${System.formatDate(row.old_mot) }

${contentHtml}
${getTranslation("mot.lights")} ${getTranslation("mot.brakes_tyres")} ${getTranslation("mot.windows")} ${getTranslation("mot.others")}
${getTranslation("headlights")} ${getTranslation("front_brakes")} ${getTranslation("windscreen")} ${getTranslation("horn")}
${getTranslation("rear_lights")} ${getTranslation("rear_brakes")} ${getTranslation("rear_window")} ${getTranslation("exhaust_system")}
${getTranslation("indicators")} ${getTranslation("front_tyres")} ${getTranslation("side_windows")} ${getTranslation("engine")}
${getTranslation("rear_tyres")} ${getTranslation("bodywork")}
`; } else{ cardContent = `

${getTranslation("no_data_found")}

` } retval.bottom += `
${getTranslation("regvehicle_mot.overview")}
${cardContent}
`; } if(data.extraData.part_acceptance !== undefined && data.extraData.part_acceptance !== null && showPartAcceptanceFromMyMechanicMDT){ let cardCols = 2; if(data.extraData.part_acceptance.length == 0){ cardCols = 1; } retval.bottom += `
${getTranslation("regvehicle_part_acceptance.overview")}
`; if(data.extraData.part_acceptance.length > 0){ let i=0; for(const row of data.extraData.part_acceptance){ if(i < 9999){ let temp = `

${System.buildEmployeeName(row.creator)} - ${System.formatTimestamp(row.createddate)}

${row.content.replace(/\n/g,"
")}

${(row["_acceptance_name"] ?? "").replace(/\n/g,"
")}

`; retval.bottom += temp; } i++; } } else{ retval.bottom+= `

${getTranslation("no_data_found")}

`; } retval.bottom += `
`; } 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_id ?? "-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_id ?? "-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 } } } } }