Main/resources/[tools]/unlimited-spectre/html/assets/VehicleCreate.ec46f0b2.js
2025-06-07 08:51:21 +02:00

1 line
7.6 KiB
JavaScript

import{_ as q,o as p,X as h,a7 as i,a as o,w as n,a6 as V,ab as v,a5 as d,U as c,a9 as m,Y as $,Z as C,W as w}from"./app-014d9ed9.js";import{Q as f}from"./QForm.8d79ab03.js";import{Q as S}from"./QSelect.d7ce3d4c.js";import{Q as U}from"./QTooltip.9d840032.js";import{Q as k}from"./QMarkupTable.ba6854cc.js";import{B as Q}from"./BasicDialog.9dd9de92.js";import"./externalHosting.js";import"./QItemLabel.b6dd3adb.js";import"./position-engine.65ebcb34.js";import"./selection.2a17b691.js";import"./rtl.b51694b1.js";const N={name:"VehicleCreate",data(){return{defaults:["name","brand","model","price","category","categorylabel","hash","shop"],pendingSave:!1,vehicle:{name:"",brand:"",model:"",price:0,category:"",categoryLabel:"",hash:"",shop:[]},customVars:[]}},methods:{isNumeric(e){return typeof e!="string"?!1:!isNaN(e)&&!isNaN(parseFloat(e))},isBoolean(e){return e==="true"||(e==="false"?!1:e)},addCustomVar(){this.customVars.push({name:"",value:""})},removeVar(e){const t=this.customVars.indexOf(e);t>-1&&this.$q.dialog({component:Q,componentProps:{title:this.$i18n.t("components.devVehicle.deleteHeader"),message:this.$i18n.t("components.devVehicle.deleteCustomVarMsg",{name:e.name})},cancel:!0,persistent:!0}).onOk(()=>{this.customVars.splice(t,1)})},trySave(){this.$refs.vehDefaults.validate().then(e=>{if(!e){this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t("components.devVehicle.msg.error.missingFields")});return}this.$refs.customVarForm.validate().then(t=>{if(!t){this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t("components.devVehicle.msg.error.uniqueVars")});return}this.customVars.forEach(r=>{!r.name||(this.vehicle[r.name]=this.isNumeric(r.value)?Number(r.value):this.isBoolean(r.value))}),this.pendingSave=!0,this.$axios.post("/api/dev-vehicles/create",this.vehicle).then(r=>{if(this.pendingSave=!1,!r.data.resCode){const s=r.data.resMsg;this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t(`components.devVehicle.msg.error.${s}`,{name:this.vehicle.model})});return}this.$q.notify({message:this.$i18n.t("general.success"),position:"top",color:"green",icon:"fas fa-check",caption:this.$i18n.t("general.saved")}),this.$router.push({name:"dev-vehicle-list"})}).catch(()=>{})})})}}},B={class:"row"},_={class:"col-12"},L={class:"q-ma-sm row"},F={class:"text-h6"},M={class:"col-12"},D={class:"q-ma-sm row"},x={class:"row"},z={class:"text-h6"},T={class:"text-caption text-sub"},E={class:"q-ml-auto"},O={style:{width:"30px"},class:"text-right vertical-middle"},j={class:"col-12"},H={class:"q-ma-sm row justify-end"};function I(e,t,r,b,s,u){return p(),h("div",B,[i("div",_,[i("div",L,[o(V,{class:"bg-secondary full-width row"},{default:n(()=>[o(d,{class:"col-12"},{default:n(()=>[i("div",F,c(e.$t("components.devVehicleCreate.new"))+": ",1)]),_:1}),o(d,{class:"col-12 col-md-6"},{default:n(()=>[o(f,{ref:"vehDefaults"},{default:n(()=>[o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",modelValue:s.vehicle.model,"onUpdate:modelValue":t[0]||(t[0]=l=>s.vehicle.model=l),onChange:t[1]||(t[1]=l=>{s.vehicle.model=l.toLowerCase()}),"lazy-rules":"",rules:[l=>l&&l.length>0||e.$t("rules.required"),l=>l&&!/\s/.test(l)||e.$t("rules.noSpace")],label:e.$t("components.devVehicle.model")},null,8,["input-style","modelValue","rules","label"]),o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",disable:"",class:"q-mt-md",modelValue:s.vehicle.model,"onUpdate:modelValue":t[2]||(t[2]=l=>s.vehicle.model=l),label:e.$t("components.devVehicle.hash")},null,8,["input-style","modelValue","label"]),o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:s.vehicle.name,"onUpdate:modelValue":t[3]||(t[3]=l=>s.vehicle.name=l),label:e.$t("components.devVehicle.name")},null,8,["input-style","modelValue","label"]),o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:s.vehicle.brand,"onUpdate:modelValue":t[4]||(t[4]=l=>s.vehicle.brand=l),label:e.$t("components.devVehicle.brand")},null,8,["input-style","modelValue","label"])]),_:1},512)]),_:1}),o(d,{class:"col-12 col-md-6"},{default:n(()=>[o(f,{ref:"vehShop"},{default:n(()=>[o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",modelValue:s.vehicle.category,"onUpdate:modelValue":t[5]||(t[5]=l=>s.vehicle.category=l),label:e.$t("components.devVehicle.category")},null,8,["input-style","modelValue","label"]),o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:s.vehicle.categoryLabel,"onUpdate:modelValue":t[6]||(t[6]=l=>s.vehicle.categoryLabel=l),label:e.$t("components.devVehicle.categoryLabel")},null,8,["input-style","modelValue","label"]),o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:s.vehicle.price,"onUpdate:modelValue":t[7]||(t[7]=l=>s.vehicle.price=l),modelModifiers:{number:!0},type:"number",label:e.$t("components.devVehicle.price")},null,8,["input-style","modelValue","label"]),o(S,{ref:"accept",label:e.$t("components.devVehicle.shop"),color:"primary","label-color":"primary",filled:"",multiple:"",modelValue:s.vehicle.shop,"onUpdate:modelValue":t[8]||(t[8]=l=>s.vehicle.shop=l),"popup-content-class":"bg-secondary text-main","use-input":"","use-chips":"","hide-dropdown-icon":"","input-debounce":"0","new-value-mode":"add-unique","input-class":"text-main",class:"q-mt-md"},null,8,["label","modelValue"])]),_:1},512)]),_:1})]),_:1})])]),i("div",M,[i("div",D,[o(V,{class:"bg-secondary full-width row"},{default:n(()=>[o(d,{class:"col-12"},{default:n(()=>[i("div",x,[i("div",null,[i("div",z,c(e.$t("components.devVehicle.customVariables")),1),i("div",T,c(e.$t("components.devVehicle.customVarSub")),1)]),i("div",E,[o(v,{"text-color":"main",color:"primary",label:e.$t("components.devVehicle.addCustomVar"),onClick:u.addCustomVar},null,8,["label","onClick"])])])]),_:1}),o(d,{class:"col-12"},{default:n(()=>[o(f,{ref:"customVarForm"},{default:n(()=>[o(k,{class:"bg-secondary text-main",flat:"",square:"",separator:"none"},{default:n(()=>[i("tbody",null,[(p(!0),h($,null,C(s.customVars,(l,y)=>(p(),h("tr",{key:`${y}-customVar`},[i("td",null,[o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",modelValue:l.name,"onUpdate:modelValue":a=>l.name=a,label:e.$t("components.devVehicle.customVarName"),"lazy-rules":"",rules:[a=>a&&a.length>0||e.$t("rules.required"),a=>a&&!/\s/.test(a)||e.$t("rules.noSpace"),a=>a&&s.customVars.filter(g=>g.name===a).length<=1||e.$t("rules.unique"),a=>a&&!s.defaults.includes(a.toLowerCase())||e.$t("rules.defaults")]},null,8,["input-style","modelValue","onUpdate:modelValue","label","rules"])]),i("td",null,[o(m,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-field--with-bottom",modelValue:l.value,"onUpdate:modelValue":a=>l.value=a,label:e.$t("components.devVehicle.customVarValue")},null,8,["input-style","modelValue","onUpdate:modelValue","label"])]),i("td",O,[o(v,{"text-color":"main",class:"text-red-6",dense:"",flat:"",icon:"fas fa-trash",size:"xs",onClick:a=>u.removeVar(l)},{default:n(()=>[o(U,null,{default:n(()=>[w(c(e.$t("general.delete")),1)]),_:1})]),_:2},1032,["onClick"])])]))),128))])]),_:1})]),_:1},512)]),_:1})]),_:1})])]),i("div",j,[i("div",H,[o(v,{"text-color":"main",loading:s.pendingSave,color:"primary",onClick:u.trySave,label:e.$t("general.create"),class:"q-mr-sm"},null,8,["loading","onClick","label"])])])])}const le=q(N,[["render",I]]);export{le as default};