forked from Simnation/Main
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
import{_ as D,R as I,P as N,o as p,X as f,a7 as s,a as l,w as d,a6 as y,ab as b,c as V,V as $,r as E,a5 as u,W as j,U as m,a9 as g,aT as _,Y as C,Z as k,S as O,bG as U,bH as B}from"./app-014d9ed9.js";import{Q as q}from"./QTooltip.9d840032.js";import{Q as x}from"./QMarkupTable.ba6854cc.js";import{Q}from"./QForm.8d79ab03.js";import{d as M}from"./utils.9ce591f3.js";import{B as v}from"./BasicDialog.9dd9de92.js";import{S as J,m as T}from"./move.a5bc0ce3.js";import"./externalHosting.js";import"./position-engine.65ebcb34.js";import"./selection.2a17b691.js";const P={name:"Job",data(){return{RESOURCE:I,ACTION:N,defaults:["name","grades","label","defaultduty","offdutypay"],customVars:[],sortable:null,pendingSave:!1,pendingDelete:!1,job:{},jobGrades:[]}},methods:{can:M,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,o){e>-1&&this.$q.dialog({component:v,componentProps:{title:this.$i18n.t("components.job.deleteHeader"),message:this.$i18n.t("components.job.deleteCustomVarMsg",{name:o.name})},cancel:!0,persistent:!0}).onOk(()=>{delete this.job[o.oldName],this.customVars.splice(e,1)})},removeNode(e){e.parentElement!==null&&e.parentElement.removeChild(e)},insertNodeAt(e,o,i){const r=i===0?e.children[0]:e.children[i-1].nextSibling;e.insertBefore(o,r)},buildJobGrade(e){let o=[];for(const[i,r]of Object.entries(e))o.push({name:r.name,payment:r.payment,isboss:r.isboss?r.isboss:!1});return o},updateBoss(){},addGrade(){this.jobGrades.push({name:"",payment:0,isboss:!1})},removeGrade(e){const o=this.jobGrades.indexOf(e);o>-1&&this.$q.dialog({component:v,componentProps:{title:this.$i18n.t("components.job.deleteHeader"),message:this.$i18n.t("components.job.deleteGradeMsg",{name:e.name})},cancel:!0,persistent:!0}).onOk(()=>{this.jobGrades.splice(o,1)})},trySave(){this.$refs.customVarForm.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.job.msg.error.uniqueVars")});return}this.customVars.forEach(i=>{!i.name||(i.oldName=i.name,this.job[i.name]=this.isNumeric(i.value)?Number(i.value):this.isBoolean(i.value))});let o={};for(const[i,r]of Object.entries(this.jobGrades)){if(!r.isboss&&!r.name&&!r.payment)continue;const t=Object.keys(o).length;r.isboss?o[t]={name:r.name,payment:r.payment,isboss:!0}:o[t]={name:r.name,payment:r.payment}}if(Object.keys(o).length===0){this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t("components.job.msg.error.gradeNeeded")});return}this.pendingSave=!0,this.job.grades=o,this.$axios.patch(`/api/jobs/save/${this.$route.params.jobId}`,this.job).then(i=>{if(this.pendingSave=!1,!i.data.resCode){const t=i.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.job.msg.error.${t}`,{name:this.job.name})});return}Object.keys(o).length!==this.jobGrades.length&&(this.jobGrades=this.buildJobGrade(this.job.grades)),this.$q.notify({message:this.$i18n.t("general.success"),position:"top",color:"green",icon:"fas fa-check",caption:this.$i18n.t("general.saved")})}).catch(i=>{})})},tryDelete(){this.pendingDelete=!0,this.$q.dialog({component:v,componentProps:{title:this.$i18n.t("components.job.deleteHeader"),message:this.$i18n.t("components.job.deleteMsg",{name:this.$route.params.jobId})},cancel:!0,persistent:!0}).onOk(()=>{this.$axios.delete(`/api/jobs/delete/${this.$route.params.jobId}`).then(e=>{if(this.pendingDelete=!1,!e.data.resCode){const i=e.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.job.msg.error.${i}`,{name:this.$route.params.jobId})});return}this.$q.notify({message:this.$i18n.t("general.success"),position:"top",color:"green",icon:"fas fa-check",caption:this.$i18n.t("general.deleted")}),this.$router.push({name:"dev-job-list"})}).catch(e=>{})}).onCancel(()=>{this.pendingDelete=!1})}},mounted(){this.$axios.get(`/api/jobs/${this.$route.params.jobId}`).then(e=>{const o=e.data.job;if(!o){this.$q.notify({message:e.data.msg,position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:"Error"});return}this.job=o,this.jobGrades=this.buildJobGrade(this.job.grades);for(const[t,c]of Object.entries(o))this.defaults.includes(t.toLowerCase())||this.customVars.push({name:t,value:c,oldName:t});const i=this.$el.querySelector(".q-table > draggable"),r=this;this.sortable=J.create(i,{handle:".drag-handle",animation:150,onEnd(t){t.oldIndex!==t.newIndex&&(r.removeNode(t.item),r.insertNodeAt(t.from,t.item,t.oldIndex),T(r.jobGrades,t.oldIndex,t.newIndex))}})}).catch(e=>{console.error(e)})},beforeUnmount(){this.sortable.destroy()}},w=e=>(U("data-v-cb255579"),e=e(),B(),e),R={class:"row"},A={class:"col-12"},F={class:"q-ma-sm row"},H={class:"text-h6"},L={class:"text-primary"},z={class:"col-12"},Y={class:"q-ma-sm row"},W={class:"row"},X={class:"text-h6"},Z={class:"text-caption text-sub"},K={class:"q-ml-auto"},ee={style:{width:"30px"},class:"text-right vertical-middle"},te={class:"col-12"},se={class:"q-ma-sm row"},oe={class:"row"},le={class:"text-h6"},ae={class:"text-caption text-sub"},ne={class:"q-ml-auto"},ie=w(()=>s("th",{class:"text-left",style:{width:"30px"}},null,-1)),re={class:"text-left",style:{"min-width":"280px"}},de={class:"text-center",style:{"min-width":"150px"}},ce={class:"text-center",style:{width:"30px"}},me=w(()=>s("th",{class:"text-right",style:{width:"30px"}},null,-1)),ue={class:"text-left"},pe={class:"text-left"},be={class:"text-center vertical-middle"},he={class:"text-right vertical-middle"},fe={class:"col-12"},ge={class:"q-ma-sm row justify-end"};function ye(e,o,i,r,t,c){const G=E("draggable");return p(),f("div",R,[s("div",A,[s("div",F,[l(y,{class:"bg-secondary full-width row"},{default:d(()=>[l(u,{class:"col-12"},{default:d(()=>[s("div",H,[j(m(e.$t("components.job.edit"))+": ",1),s("span",L,m(e.$route.params.jobId),1)])]),_:1}),l(u,{class:"col-12 col-md-6"},{default:d(()=>[l(g,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",modelValue:t.job.label,"onUpdate:modelValue":o[0]||(o[0]=a=>t.job.label=a),label:e.$t("components.job.label")},null,8,["input-style","modelValue","label"])]),_:1}),l(u,{class:"col-12 col-md-3"},{default:d(()=>[l(_,{modelValue:t.job.defaultDuty,"onUpdate:modelValue":o[1]||(o[1]=a=>t.job.defaultDuty=a),label:e.$t("components.job.defaultDuty")},null,8,["modelValue","label"])]),_:1}),l(u,{class:"col-12 col-md-3"},{default:d(()=>[l(_,{modelValue:t.job.offDutyPay,"onUpdate:modelValue":o[2]||(o[2]=a=>t.job.offDutyPay=a),label:e.$t("components.job.offDutyPay")},null,8,["modelValue","label"])]),_:1})]),_:1})])]),s("div",z,[s("div",Y,[l(y,{class:"bg-secondary full-width row"},{default:d(()=>[l(u,{class:"col-12"},{default:d(()=>[s("div",W,[s("div",null,[s("div",X,m(e.$t("components.job.customVariables")),1),s("div",Z,m(e.$t("components.job.customVarSub")),1)]),s("div",K,[l(b,{"text-color":"main",color:"primary",label:e.$t("components.job.addCustomVar"),onClick:c.addCustomVar},null,8,["label","onClick"])])])]),_:1}),l(u,{class:"col-12"},{default:d(()=>[l(Q,{ref:"customVarForm"},{default:d(()=>[l(x,{class:"bg-secondary text-main",flat:"",square:"",separator:"none"},{default:d(()=>[s("tbody",null,[(p(!0),f(C,null,k(t.customVars,(a,h)=>(p(),f("tr",{key:`${h}-customVar`},[s("td",null,[l(g,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",modelValue:a.name,"onUpdate:modelValue":n=>a.name=n,label:e.$t("components.job.customVarName"),"lazy-rules":"",rules:[n=>n&&n.length>0||e.$t("rules.required"),n=>n&&!/\s/.test(n)||e.$t("rules.noSpace"),n=>n&&t.customVars.filter(S=>S.name===n).length<=1||e.$t("rules.unique"),n=>n&&!t.defaults.includes(n.toLowerCase())||e.$t("rules.defaults")]},null,8,["input-style","modelValue","onUpdate:modelValue","label","rules"])]),s("td",null,[l(g,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-field--with-bottom",modelValue:a.value,"onUpdate:modelValue":n=>a.value=n,label:e.$t("components.job.customVarValue")},null,8,["input-style","modelValue","onUpdate:modelValue","label"])]),s("td",ee,[l(b,{"text-color":"main",class:"text-red-6",dense:"",flat:"",icon:"fas fa-trash",size:"xs",onClick:n=>c.removeVar(h,a)},{default:d(()=>[l(q,null,{default:d(()=>[j(m(e.$t("general.delete")),1)]),_:1})]),_:2},1032,["onClick"])])]))),128))])]),_:1})]),_:1},512)]),_:1})]),_:1})])]),s("div",te,[s("div",se,[l(y,{class:"bg-secondary full-width row"},{default:d(()=>[l(u,{class:"col-12"},{default:d(()=>[s("div",oe,[s("div",null,[s("div",le,m(e.$t("components.job.grades")),1),s("div",ae,m(e.$t("components.job.gradesSub")),1)]),s("div",ne,[l(b,{"text-color":"main",color:"primary",label:e.$t("components.job.addGrade"),onClick:c.addGrade},null,8,["label","onClick"])])])]),_:1}),l(u,{class:"col-12"},{default:d(()=>[l(x,{class:"bg-secondary text-main",flat:"",square:"",separator:"none"},{default:d(()=>[s("thead",null,[s("tr",null,[ie,s("th",re,m(e.$t("components.job.headers.name")),1),s("th",de,m(e.$t("components.job.headers.payment")),1),s("th",ce,m(e.$t("components.job.headers.isboss")),1),me])]),l(G,{modelValue:t.jobGrades,"onUpdate:modelValue":o[3]||(o[3]=a=>t.jobGrades=a),style:{display:"table-row-group"},tag:"tbody"},{default:d(()=>[(p(!0),f(C,null,k(t.jobGrades,(a,h)=>(p(),f("tr",{class:"grade-table",key:`${a.isboss}-${h}`},[s("td",null,[l(O,{name:"fas fa-bars",class:"drag-handle"})]),s("td",ue,[l(g,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",label:e.$t("components.job.headers.name"),modelValue:a.name,"onUpdate:modelValue":n=>a.name=n},null,8,["input-style","label","modelValue","onUpdate:modelValue"])]),s("td",pe,[l(g,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",type:"number",label:e.$t("components.job.headers.payment"),modelValue:a.payment,"onUpdate:modelValue":n=>a.payment=n,modelModifiers:{number:!0}},null,8,["input-style","label","modelValue","onUpdate:modelValue"])]),s("td",be,[l(_,{onClick:n=>c.updateBoss(a,h),modelValue:a.isboss,"onUpdate:modelValue":n=>a.isboss=n},null,8,["onClick","modelValue","onUpdate:modelValue"])]),s("td",he,[l(b,{"text-color":"main",class:"text-red-6",dense:"",flat:"",icon:"fas fa-trash",size:"xs",onClick:n=>c.removeGrade(a)},{default:d(()=>[l(q,null,{default:d(()=>[j(m(e.$t("general.delete")),1)]),_:1})]),_:2},1032,["onClick"])])]))),128))]),_:1},8,["modelValue"])]),_:1})]),_:1})]),_:1})])]),s("div",fe,[s("div",ge,[l(b,{"text-color":"main",disable:t.pendingDelete||t.pendingSave,color:"primary",onClick:o[4]||(o[4]=a=>e.$router.push({name:"dev-job-list"})),label:e.$t("general.back"),class:"q-mr-auto"},null,8,["disable","label"]),c.can(t.ACTION.DEV.JOB.MODIFY,t.RESOURCE.DEV)?(p(),V(b,{key:0,"text-color":"main",loading:t.pendingSave,disable:t.pendingDelete,color:"primary",onClick:c.trySave,label:e.$t("general.save"),class:"q-mr-sm"},null,8,["loading","disable","onClick","label"])):$("",!0),c.can(t.ACTION.DEV.JOB.DELETE,t.RESOURCE.DEV)?(p(),V(b,{key:1,"text-color":"main",loading:t.pendingDelete,disable:t.pendingSave,color:"negative",onClick:c.tryDelete,label:e.$t("general.delete")},null,8,["loading","disable","onClick","label"])):$("",!0)])])])}const Ge=D(P,[["render",ye],["__scopeId","data-v-cb255579"]]);export{Ge as default};
|