felicity-lims/felicity/templates/static/assets/StockItem-f0492cc2.js
2024-11-17 19:39:30 +02:00

1 line
6.2 KiB
JavaScript

import{d as T,bt as U,K as E,r as i,q as x,x as u,g as e,C as o,e as r,v as d,as as k,j as p,_ as b,M as V}from"./index-e62f5c21.js";import{d as A,e as L}from"./inventory.mutations-a0cda30e.js";const z=p(()=>b(()=>import("./FelModal-44636049.js"),["assets/FelModal-44636049.js","assets/index-e62f5c21.js","assets/index-332ec99e.css","assets/FelModal-780aeea9.css"])),O=p(()=>b(()=>import("./FelDrawer-74dbd7a4.js"),["assets/FelDrawer-74dbd7a4.js","assets/index-e62f5c21.js","assets/index-332ec99e.css"])),F=p(()=>b(()=>import("./StockItemDetail-b2348915.js"),["assets/StockItemDetail-b2348915.js","assets/index-e62f5c21.js","assets/index-332ec99e.css","assets/inventory.mutations-a0cda30e.js"])),j=T({name:"stock-item",setup(t,N){const l=U();E();const{withClientMutation:h}=V();let c=i(!1),y=i(""),s=x({});const m=i(!0);let v=x({first:50,after:"",text:"",sortBy:["-uid"]});l.fetchAllDependencies(),l.fetchItems(v);const w=u(()=>l.getStockItems),I=u(()=>l.getHazards),S=u(()=>l.getCategories);function _(){const a={...s};h(A,{payload:a},"createStockItem").then(n=>l.addItem(n))}function D(){const a={name:s.name,description:s.description,hazardUid:s.hazardUid,categoryUid:s.categoryUid};h(L,{uid:s.uid,payload:a},"updateStockItem").then(n=>l.updateItem(n))}function C(a,n){m.value=a,y.value=(a?"CREATE":"EDIT")+" STOCK ITEM",c.value=!0,a?Object.assign(s,{}):Object.assign(s,{...n})}function M(){m.value===!0&&_(),m.value===!1&&D(),c.value=!1}let f=i(!1),g=i();return{form:s,FormManager:C,saveForm:M,stockItems:w,showModal:c,formTitle:y,hazards:I,categories:S,openDrawer:f,viewStockItem:a=>{g.value=a,f.value=!0},stockItem:g}},render(){return e("div",{class:"container w-full my-4"},[e("hr",null,null),e("button",{onClick:()=>this.FormManager(!0,null),class:"px-2 py-1 border-sky-800 border text-sky-800 rounded-sm transition duration-300 hover:bg-sky-800 hover:text-white focus:outline-none"},[o("Add Stock Item")]),e("hr",null,null),e("div",{class:"overflow-x-auto mt-4"},[e("div",{class:"align-middle inline-block min-w-full shadow overflow-hidden bg-white shadow-dashboard px-2 pt-1 rounded-bl-lg rounded-br-lg"},[e("table",{class:"min-w-full"},[e("thead",null,[e("tr",null,[e("th",{class:"px-1 py-1 border-b-2 border-gray-300 text-left text-sm leading-4 text-gray-800 tracking-wider"},[o("Item Name")]),e("th",{class:"px-1 py-1 border-b-2 border-gray-300 text-left text-sm leading-4 text-gray-800 tracking-wider"},[o("Category")]),e("th",{class:"px-1 py-1 border-b-2 border-gray-300 text-left text-sm leading-4 text-gray-800 tracking-wider"},[o("Hazard")]),e("th",{class:"px-1 py-1 border-b-2 border-gray-300 text-left text-sm leading-4 text-gray-800 tracking-wider"},[o("Description")]),e("th",{class:"px-1 py-1 border-b-2 border-gray-300"},null)])]),e("tbody",{class:"bg-white"},[this.stockItems?.map(t=>e("tr",{key:t?.uid},[e("td",{class:"px-1 py-1 whitespace-no-wrap border-b border-gray-500"},[e("div",{class:"flex items-center"},[e("div",{class:"text-sm leading-5 text-gray-800"},[t?.name])])]),e("td",{class:"px-1 py-1 whitespace-no-wrap border-b border-gray-500"},[e("div",{class:"text-sm leading-5 text-sky-800"},[t?.category?.name])]),e("td",{class:"px-1 py-1 whitespace-no-wrap border-b border-gray-500"},[e("div",{class:"text-sm leading-5 text-sky-800"},[t?.hazard?.name])]),e("td",{class:"px-1 py-1 whitespace-no-wrap border-b border-gray-500"},[e("div",{class:"text-sm leading-5 text-sky-800"},[t?.description])]),e("td",{class:"px-1 py-1 whitespace-no-wrap text-right border-b border-gray-500 text-sm leading-5"},[e("button",{onClick:()=>this.FormManager(!1,t),class:"px-2 py-1 mr-2 border-sky-800 border text-sky-800 rounded-sm transition duration-300 hover:bg-sky-800 hover:text-white focus:outline-none"},[o("Edit")]),e("button",{onClick:()=>this.viewStockItem(t),class:"px-2 py-1 mr-2 border-sky-800 border text-sky-800 rounded-sm transition duration-300 hover:bg-sky-800 hover:text-white focus:outline-none"},[o("View")])])]))])])])]),e(O,{show:this.openDrawer,onClose:()=>this.openDrawer=!1},{header:()=>"Stock Item Detail",body:()=>e(F,{stockItem:this.stockItem},null),footer:()=>[e("div",null,null)]}),this.showModal?e(z,{onClose:()=>this.showModal=!1,contentWidth:"w-1/4"},{header:()=>e("h3",null,[this.formTitle]),body:()=>e("form",{action:"post",class:"p-1"},[e("div",{class:"grid grid-cols-2 gap-x-4 mb-4"},[e("label",{class:"block col-span-2 mb-2"},[e("span",{class:"text-gray-700"},[o("Stock Item Name")]),r(e("input",{class:"form-input mt-1 block w-full","onUpdate:modelValue":t=>this.form.name=t,placeholder:"Name ..."},null),[[d,this.form.name]])]),e("label",{class:"block col-span-1 mb-2"},[e("span",{class:"text-gray-700"},[o("Min Level")]),r(e("input",{class:"form-input mt-1 block w-full",type:"number","onUpdate:modelValue":t=>this.form.minimumLevel=t},null),[[d,this.form.minimumLevel]])]),e("label",{class:"block col-span-1 mb-2"},[e("span",{class:"text-gray-700"},[o("Max Level")]),r(e("input",{class:"form-input mt-1 block w-full",type:"number","onUpdate:modelValue":t=>this.form.maximumLevel=t},null),[[d,this.form.maximumLevel]])]),e("label",{class:"block col-span-2 mb-2"},[e("span",{class:"text-gray-700"},[o("Description")]),r(e("textarea",{cols:"2",class:"form-input mt-1 block w-full","onUpdate:modelValue":t=>this.form.description=t,placeholder:"Description ..."},null),[[d,this.form.description]])]),e("label",{class:"block col-span-1 mb-2"},[e("span",{class:"text-gray-700"},[o("Hazard")]),r(e("select",{class:"form-select block w-full mt-1","onUpdate:modelValue":t=>this.form.hazardUid=t},[e("option",null,null),this.hazards.map(t=>e("option",{key:t.uid,value:t?.uid},[t.name]))]),[[k,this.form.hazardUid]])]),e("label",{class:"block col-span-1 mb-2"},[e("span",{class:"text-gray-700"},[o("Category")]),r(e("select",{class:"form-select block w-full mt-1","onUpdate:modelValue":t=>this.form.categoryUid=t},[e("option",null,null),this.categories.map(t=>e("option",{key:t.uid,value:t?.uid},[t.name]))]),[[k,this.form.categoryUid]])])]),e("hr",null,null),e("button",{type:"button",onClick:()=>this.saveForm(),class:"-mb-4 w-full border border-sky-800 bg-sky-800 text-white rounded-sm px-4 py-2 m-2 transition-colors duration-500 ease select-none hover:bg-sky-800 focus:outline-none focus:shadow-outline"},[o("Save Form")])])}):null])}});export{j as StockItem,j as default};