@gisce/react-ooui 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,5 +33,5 @@
33
33
  background-color: ${an.colorPrimaryBg};
34
34
  }
35
35
  `,dn=Pe.default.createContext(null),ya=({children:t,initialView:r})=>{const[n,s]=l.useState(r),[o,i]=l.useState(0),[a,c]=l.useState(!1);return e.jsx(dn.Provider,{value:{currentView:n,setCurrentView:s,itemIndex:o,setItemIndex:i,manualTriggerChange:a,setManualTriggerChange:c},children:t})},{getValueForOperator:un}=se.graphProcessor,Dt=.7,Vt=30,fn=t=>{const{model:r,domain:n,context:s,colorCondition:o,totalDomain:i,showPercent:a=!1,icon:c,suffix:d,field:f,operator:h,manualIds:p}=t,[g,v]=l.useState(!1),[m,y]=l.useState(),[C,w]=l.useState(),[E,_]=l.useState(),[S,I]=l.useState(0),[D,N]=l.useState(0),[b,x]=l.useState(),[O,T]=l.useState(),[H,F]=l.useState();l.useEffect(()=>{L()},[r,o]);async function A({domain:V,isTotal:M}){if(M)return await k({domain:V});if(f&&h){const K=p||await W.getHandler().searchAllIds({params:V,model:r,context:s}),q=await W.getHandler().readObjects({model:r,ids:K,fieldsToRetrieve:[f],context:s});return un({values:q.map(z=>z[f]),operator:h})}else return p?p.length:await W.getHandler().searchCount({model:r,params:V,context:s})}async function k({domain:V}){if(f&&h){const M=await W.getHandler().searchAllIds({params:V,model:r,context:s}),K=await W.getHandler().readObjects({model:r,ids:M,fieldsToRetrieve:[f],context:s});return un({values:K.map(q=>q[f]),operator:h})}else return await W.getHandler().searchCount({model:r,params:V,context:s})}async function L(){v(!0);let V,M;try{const K=await A({domain:n,isTotal:!1});if(y(K),i){const q=await W.getHandler().evalDomain({domain:i,values:{},context:s});V=await A({domain:q,isTotal:!0}),_(V)}if(V?(M=Math.round(K/V*100*100)/100,w(M)):w(0),o){const q=await W.getHandler().parseCondition({condition:o,values:{value:K,percent:M},context:s});x(q)}if(c)if(c.indexOf(":")!==-1){const q=await W.getHandler().parseCondition({condition:c,values:{value:K,percent:M},context:s});T(q)}else T(c)}catch(K){F(JSON.stringify(K))}v(!1)}return H?e.jsx(u.Alert,{className:"mt-10",message:H,type:"error",banner:!0}):g?e.jsx("div",{style:{padding:"1rem"},children:e.jsx(B.LoadingOutlined,{style:{height:"12px"}})}):e.jsx(Ht.default,{bounds:!0,onResize:V=>{var M,K;I((M=V.bounds)==null?void 0:M.height),N((K=V.bounds)==null?void 0:K.width)},children:({measureRef:V})=>a?e.jsx(wa,{value:m,total:E,percent:C,measureRef:V,height:S,width:D,color:b,icon:O,suffix:d}):e.jsx(va,{value:m,total:E,measureRef:V,height:S,width:D,color:b,icon:O,suffix:d})})};function hn(t,r){const s=document.createElement("canvas").getContext("2d");return s.font=r||getComputedStyle(document.body).font,s.measureText(t).width}function va({measureRef:t,width:r,height:n,total:s,value:o,color:i,icon:a,suffix:c}){let d=n*Dt<Vt?Vt:n*Dt;const f=o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0});let h=s?`${f}/${s}`:`${f}`;c&&(h+=" "+c);let p=hn(h,`bold ${Math.floor(d*1.03)}px sans-serif`);a&&(p=p*2),p>=r*.85&&(d=r*.85/p*d);const g=a&&qe(a);return e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden"},children:e.jsxs(Kt.default,{style:{fontSize:d,margin:0,color:i},children:[g&&e.jsx(g,{style:{fontSize:d*.7}}),g?` ${h}`:h]})})}function wa({measureRef:t,height:r,width:n,percent:s,total:o,value:i,color:a,icon:c,suffix:d}){const f=r*.65;let h=f*Dt<Vt?Vt:f*Dt;const p=i==null?void 0:i.toLocaleString("es-ES",{useGrouping:!0});let g=o?`${p}/${o==null?void 0:o.toLocaleString("es-ES",{useGrouping:!0})}`:`${p}`;d&&(g+=" "+d);const v=`${s==null?void 0:s.toLocaleString("es-ES",{useGrouping:!0})}%`;let m=hn(v,`bold ${Math.floor(h*1.03)}px sans-serif`);c&&(m=m*1.5);const y=c&&qe(c);return(m>=n*.85||h*2<f)&&(h=n*.85/m*h),e.jsx("div",{ref:t,style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flexDirection:"column",padding:"0.2rem"},children:e.jsxs(u.Row,{align:"middle",children:[y&&e.jsx(u.Col,{style:{fontSize:h*1,color:a,paddingRight:"10px"},children:e.jsx(y,{})}),e.jsxs(u.Col,{children:[e.jsx(Kt.default,{style:{fontSize:h*.8,margin:0,color:a},children:y?` ${s}%`:`${s}%`}),e.jsx(Kt.default,{style:{fontSize:h*.4,margin:0,color:a,textAlign:"center"},children:g})]})]})})}const tr=t=>r=>{const n=r.value.toLocaleString("es-ES",{useGrouping:!0});return{name:t==="pie"?r.x:r.type,value:n}},kt=t=>{if(typeof t=="string"&&Ca(t))return parseFloat(t).toLocaleString("es-ES",{useGrouping:!0});if(ba(t))return t.toLocaleString("es-ES",{useGrouping:!0});if(Sa(t)){const r=xa(t);return r===null?t:ct(t,Et.input[r]).format(Et.output[r])}else return t},Ca=t=>/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(t),ba=t=>typeof t=="number"&&!isNaN(t),pn={default:{padding:"auto",xAxis:{tickCount:5,label:{formatter:kt}},yAxis:{label:{formatter:kt}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:tr("default")}},pie:{appendPadding:10,radius:.9,label:{type:"inner",offset:"-30%",content:({percent:t})=>`${(t*100).toFixed(0)}%`,style:{fontSize:14,textAlign:"center"}},legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:tr("pie")},interactions:[{type:"element-active"}]},barGrouped:{isGroup:!0,legend:{maxWidthRatio:.5,maxItemWidth:1e3},tooltip:{formatter:tr("barGrouped")},xAxis:{label:{formatter:kt}},yAxis:{label:{formatter:kt}},label:{position:"middle",layout:[{type:"interval-adjust-position"},{type:"interval-hide-overlap"},{type:"adjust-color"}]}}};function Sa(t){return typeof t!="string"||t===void 0?!1:new Date(t).toString()!=="Invalid Date"}const Et={input:{hours:"YYYY-MM-DD HH:mm",days:"YYYY-MM-DD",weeks:"YYYY-[W]WW",months:"YYYY-MM",years:"YYYY"},output:{hours:"DD/MM/YYYY HH:mm",days:"DD/MM/YYYY",weeks:"[W]WW/YYYY",months:"MM/YYYY",years:"YYYY"}};function xa(t){for(const r in Et.input)if(ct(t,Et.input[r],!0).isValid())return r;return null}const{processGraphData:Ta}=se.graphProcessor,{getFieldsToRetrieve:Fa}=se.graphFieldUtils,Oa=t=>{const{model:r,domain:n=[],context:s={},xml:o,limit:i,uninformedString:a,manualIds:c}=t,[d,f]=l.useState(!1),[h,p]=l.useState(),[g,v]=l.useState(),[m,y]=l.useState(),[C,w]=l.useState("line");return Qe.default(()=>{(async()=>{f(!0),p(void 0);const E=se.parseGraph(o);w(E.type||"line");const _=Fa({ooui:E});let S,I;try{({values:S,fields:I}=await Da({model:r,domain:n,context:s,limit:i,order:E.timerange?E.x.name:null,fields:_,manualIds:c}))}catch(D){p("Error fetching graph data values: "+JSON.stringify(D)),f(!1);return}try{if(!S||!I){p("No values or fields returned"),f(!1);return}y(S);const D=Ta({ooui:E,values:S,fields:I,options:{uninformedString:a}});v(D)}catch(D){p("Error processing graph data: "+D),f(!1);return}f(!1)})()},[o,r,i,s,n]),{loading:d,error:h,type:C,values:g,evaluatedEntries:m}};async function _a({model:t,context:r,fields:n}){return await W.getHandler().getFields({model:t,context:r,fields:n})}async function Da({fields:t,model:r,domain:n,context:s,order:o,limit:i,manualIds:a}){const c=await _a({model:r,context:s,fields:t});if(a){let f=await W.getHandler().readObjects({model:r,ids:a,fieldsToRetrieve:t,context:s});return o&&(f=[...f].sort((h,p)=>h[o]-p[o])),{values:f,fields:c}}return{values:await W.getHandler().search({model:r,params:n,fields:t,context:s,limit:i,order:o}),fields:c}}const Va={line:Bt.Line,bar:Bt.Column,pie:Bt.Pie},ka=t=>{var w;const{model:r,domain:n,context:s,xml:o,limit:i,manualIds:a}=t,{t:c}=l.useContext(ge),{error:d,loading:f,values:h,type:p,evaluatedEntries:g}=Oa({model:r,xml:o,limit:i,domain:n,context:s,uninformedString:c("uninformed"),manualIds:a});if(d)return e.jsx(u.Alert,{message:d,type:"error",banner:!0});if(f)return e.jsx(u.Spin,{});if(!h)return e.jsx(u.Alert,{message:"No data to display",type:"info"});const{data:v,isGroup:m,isStack:y}=h,C=Va[p];return C?e.jsxs("div",{style:{padding:"1rem"},children:[e.jsx("p",{style:{textAlign:"right"},children:`${c("totalRegisters")} ${(w=g==null?void 0:g.length)==null?void 0:w.toLocaleString("es-ES",{useGrouping:!0})}`}),e.jsx(C,{...Ea({type:p,data:v,isGroup:m,isStack:y})})]}):e.jsx(e.Fragment,{children:`Unknown graph type: ${p}`})};function Ea(t){const{type:r,data:n,isGroup:s,isStack:o}=t;let i=pn[r];return i||(i=pn.default),i.data=n,r==="pie"?(i.colorField="x",i.angleField="value"):(i.xField="x",i.yField="value",i.seriesField="type",i.isGroup=s,o&&(i.isStack=!0,i.groupField="stacked")),i}const Ia=(t,r)=>{const{view_id:n,model:s,context:o,domain:i,limit:a,manualIds:c}=t,[d,f]=l.useState(!1),[h,p]=l.useState(),[g,v]=l.useState(),m=l.useContext(Be),{setGraphIsLoading:y=void 0}=m||{};l.useImperativeHandle(r,()=>({refresh:()=>{C()}})),l.useEffect(()=>{C()},[n]);async function C(){f(!0),y==null||y(!0);try{const w=await W.getHandler().getView({model:s,id:n,type:"graph",context:o});v(w.arch);const E=se.parseGraph(w.arch);p(E)}catch(w){return console.error(w),e.jsx(e.Fragment,{children:JSON.stringify(w)})}f(!1),y==null||y(!1)}if(d)return e.jsx("div",{style:{width:"100%",display:"flex",height:"20%",justifyContent:"center",alignContent:"center",padding:"1rem"},children:e.jsx(B.LoadingOutlined,{style:{height:"12px"}})});if(!h)return null;switch(h.type){case"indicatorField":case"indicator":{const w=h,E=w.type==="indicatorField"?{field:w.field,operator:w.operator}:{};return e.jsx(fn,{showPercent:w.showPercent,totalDomain:w.totalDomain,colorCondition:w.color,model:s,context:o,domain:i,icon:w.icon,suffix:w.suffix,manualIds:c,...E})}case"line":case"bar":case"pie":return e.jsx(ka,{model:s,context:o,domain:i,xml:g,limit:a,manualIds:c});default:return e.jsx(e.Fragment,{children:`Graph ${h.type} not implemented`})}},It=l.forwardRef(Ia),{confirm:Ma}=u.Modal,Aa=({onOk:t,lang:r})=>{Ma({title:Se("removeItems",r),icon:e.jsx(B.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmRemove",r),okText:Se("yesConfirmRemove",r),onOk:t,cancelText:Se("cancel",r)})},{confirm:$a}=u.Modal,La=({onOk:t,lang:r})=>{$a({title:Se("unlinkItems",r),icon:e.jsx(B.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmUnlink",r),okText:Se("yesConfirmUnlink",r),onOk:t,cancelText:Se("cancel",r)})},{useToken:Na}=u.theme,Pa=t=>{const{title:r,readOnly:n,onCreateItem:s,onToggleViewMode:o,mode:i,onDelete:a,totalItems:c,currentItemIndex:d,onPreviousItem:f,onNextItem:h,isMany2Many:p,onSearchItem:g,selectedRowKeys:v,showCreateButton:m,showToggleButton:y}=t,{token:C}=Na();function w(){return e.jsx("div",{className:"inline-block w-3"})}function E(){return e.jsx("div",{className:"flex flex-grow h-8 text-white",style:{borderRadius:C.borderRadius,backgroundColor:C.colorPrimaryActive},children:e.jsx("div",{className:"flex flex-col items-center justify-center h-full",children:e.jsx("span",{className:"pl-2 font-bold",children:r})})})}function _(){return e.jsx(Le,{tooltip:p?"Unlink":"Delete",icon:p?e.jsx(B.ApiOutlined,{}):e.jsx(B.DeleteOutlined,{}),onClick:a,disabled:c===0||n||i!=="form"&&v.length===0})}function S(){let D="_";return c===0?D="_":D=(d+1).toString(),e.jsxs("span",{className:"pl-1 pr-1",children:["(",D,"/",c,")"]})}function I(){return e.jsxs(e.Fragment,{children:[w(),e.jsx(Le,{tooltip:"Previous item",icon:e.jsx(B.LeftOutlined,{}),onClick:f}),S(),e.jsx(Le,{tooltip:"Next item",icon:e.jsx(B.RightOutlined,{}),onClick:h})]})}return e.jsxs("div",{className:"flex mb-2",children:[E(),e.jsxs("div",{className:"flex-none h-8 pl-2",children:[i!=="graph"&&m&&e.jsx(Le,{tooltip:"Create new item",icon:e.jsx(B.FileAddOutlined,{}),disabled:n,onClick:s}),p&&m&&e.jsx(Le,{tooltip:"Search existing item",icon:e.jsx(B.SearchOutlined,{}),disabled:n,onClick:g}),i!=="graph"&&w(),i!=="graph"&&_(),i==="form"&&I(),w(),y&&e.jsx(Le,{tooltip:"Toggle view mode",icon:e.jsx(B.AlignLeftOutlined,{}),onClick:o})]})]})},Ba={form:se.Form,tree:se.Tree,graph:It};function Ha(t){const r=t.map(s=>s.id);return t.filter((s,o)=>{const{id:i}=s;return!r.includes(i,o+1)})}const Ka=t=>{var Ge;const{value:r,onChange:n,ooui:s,views:o}=t,{items:i=[]}=r||{},{currentView:a,setCurrentView:c,itemIndex:d,setItemIndex:f}=l.useContext(dn),h=l.useContext(_e),{activeId:p,getFields:g,getValues:v,getContext:m,domain:y}=h||{},{lang:C,t:w}=l.useContext(ge),[E,_]=l.useState(!1),[S,I]=l.useState(!1),[D,N]=l.useState(),[b,x]=l.useState(!1),[O,T]=l.useState(!1),[H,F]=l.useState(),[A,k]=l.useState([]),[L,V]=l.useState(!1),M=l.useRef([]),[K,q]=l.useState(),z=l.useRef(),[Y,Z]=l.useState(void 0),{readOnly:J,relation:$,context:P,domain:ee}=s,le=s.type==="many2many",{id:ce}=s,re=i.filter(Q=>(Q.values||Q.treeValues)&&Q.operation!=="pendingRemove"),X=l.useRef();l.useEffect(()=>{if(X.current!==a){X.current=a,ve();return}ve()},[i,a]);const ve=l.useCallback(()=>{(a==="form"&&i.some(Q=>!Q.values)||a==="tree"&&i.some(Q=>!Q.treeValues))&&ke()},[i,a]);l.useEffect(()=>{oe()},[y]);const Ce=Q=>{var de,Te;n==null||n({fields:((de=o.get("form"))==null?void 0:de.fields)||((Te=o.get("tree"))==null?void 0:Te.fields),items:Ha(Q)})},ke=async()=>{await fe(),d>re.length-1&&d!==0&&f(0)},fe=async Q=>{var de,Te,ie;I(!0),_(!1),N(void 0);try{const[we,pe]=await Ut({treeView:{arch:(de=o.get("tree"))==null?void 0:de.arch,fields:(Te=o.get("tree"))==null?void 0:Te.fields},formView:{fields:((ie=o.get("form"))==null?void 0:ie.fields)||{}},model:$,items:i,context:{...m==null?void 0:m(),...P},currentView:Q||a});return z.current||(z.current=we.map($e=>$e.id)),(a||Q)==="tree"&&pe&&Z(pe),Ce(we),we}catch(we){N(we)}finally{I(!1)}};async function oe(){ee&&(M.current=await W.getHandler().evalDomain({domain:ee,values:st({fields:g(),values:v()}),fields:g(),context:m()})),y&&y.length>0&&(M.current=M.current.concat(se.transformDomainForChildWidget({domain:y,widgetFieldName:ce})))}const be=()=>{const Q=Array.from(o.keys()),de=Q[(Q.indexOf(a)+1)%Q.length];a==="form"?Ve(()=>{c(de)}):c(de)},ye=()=>{d>0&&(a==="form"?Ve(()=>{f(d-1)}):f(d-1))},xe=()=>{const Q=re.length;d<Q-1&&(a==="form"?Ve(()=>{f(d+1)}):f(d+1))},Ee=async()=>{const Q=re[d].id,de=(await W.getHandler().readObjects({model:$,ids:[Q],fields:o.get("form").fields,context:{...m==null?void 0:m(),...P}}))[0],Te=(await W.getHandler().readObjects({model:$,ids:[Q],fields:o.get("tree").fields,context:{...m==null?void 0:m(),...P}}))[0],ie=i.map(we=>we.id===Q?{...we,operation:"original",values:de,treeValues:Te}:we);Ce(ie)},Ve=Q=>{E?yt({lang:C,onOk:()=>{Ee(),Q(),_(!1)}}):Q()},He=()=>{if(le){La({lang:C,onOk:()=>{a==="form"?ae():he()}});return}Aa({lang:C,onOk:()=>{a==="form"?ae():he()}})},Ie=async()=>{const{inv_field:Q}=s;let de;Q&&p&&(de={[Q]:p}),a==="form"?Ve(()=>{V(!0),F({defaultValues:de}),x(!0)}):(V(!0),F({defaultValues:de}),x(!0))},R=async()=>{a==="form"?Ve(()=>{T(!0)}):T(!0)},ae=async()=>{I(!0),_(!1),N(void 0);try{if(re[d].id>0){const Q=i.map(de=>de.id===re[d].id?{...de,operation:"pendingRemove"}:de);Ce(Q)}else Ce(i.filter(Q=>Q.id!==re[d].id))}catch(Q){N(Q)}f(0),I(!1)},he=async()=>{const Q=re.filter(de=>A.includes(de.id));I(!0),_(!1),N(void 0);try{const de=Q.map(ie=>ie.id),Te=i.filter(ie=>!(de.includes(ie.id)&&ie.id<0)).map(ie=>de.includes(ie.id)?{...ie,operation:"pendingRemove"}:ie);Ce(Te)}catch(de){N(de)}f(0),I(!1)},Oe=(Q,de,Te)=>{let ie;if(Q)ie=i.map(we=>we.id===Q?{id:Q,operation:Q>0?"pendingUpdate":"pendingCreate",values:{...Te,id:Q},treeValues:{...Te,id:Q}}:we);else{const we=qs(i);ie=i.concat({id:we,operation:"pendingCreate",values:{...Te,id:we},treeValues:{...Te,id:we}})}Ce(ie),L||x(!1)},ue=async Q=>{const{id:de}=Q;let Te=i;const ie=i.find(we=>we.id===de);(ie==null?void 0:ie.values)===void 0&&(Te=await fe("form")),F(Te.find(we=>we.id===de)),V(!1),x(!0)},Ae=async Q=>{I(!0);let de=i;const Te=Q.filter(ie=>!i.find(we=>we.id===ie));try{for(const ie of Te){const we=(await W.getHandler().readObjects({model:$,ids:[ie],fields:o.get("form").fields,context:{...m==null?void 0:m(),...P}}))[0],pe=(await W.getHandler().readObjects({model:$,ids:[ie],fields:o.get("tree").fields,context:{...m==null?void 0:m(),...P}}))[0];de.push({id:ie,operation:"pendingLink",values:we,treeValues:pe})}Ce(de)}catch(ie){N(ie)}finally{I(!1)}};function De(){const Q=Ba[a];if(a==="graph")return se.parseGraph(o.get("graph").arch).string;{const de=new Q(o.get(a).fields);return de.parse(o.get(a).arch),de.string}}const Ze=()=>{var de,Te,ie,we;if(a==="form")return re.length===0?w("noCurrentEntries"):a!==X.current&&i.some(pe=>!pe.values)?e.jsx(u.Spin,{}):e.jsx(at,{formView:o.get("form"),values:(de=re[d])==null?void 0:de.values,parentContext:{...m==null?void 0:m(),...P},model:$,id:(Te=re[d])==null?void 0:Te.id,submitMode:"values",onFieldsChange:pe=>{var je;const $e=(je=re[d])==null?void 0:je.id,Ue=i.map(Xe=>Xe.id===$e?{...Xe,operation:Xe.operation==="original"?"pendingUpdate":Xe.operation,values:{...pe,id:$e},treeValues:{...pe,id:$e}}:Xe);Ce(Ue),_(!0)},readOnly:J});let Q=[];if(re.some(pe=>pe.treeValues)&&(Q=K?nt({resultsToSort:re.map(pe=>pe.treeValues),sorter:K,fields:{...o.get("tree").fields,...((ie=o.get("form"))==null?void 0:ie.fields)||{}}}):re.map(pe=>pe.treeValues)),a==="tree")return e.jsx(Ct,{total:re.length,limit:re.length,treeView:o.get("tree"),results:Q,loading:S,onRowClicked:((we=o.get("form"))==null?void 0:we.fields)!==void 0?ue:void 0,showPagination:!1,rowSelection:{selectedRowKeys:A,onChange:k},sorter:K,onChangeSort:q,context:{...m==null?void 0:m(),...P},colorsForResults:Y});if(a==="graph"){const pe=[[`${s.inv_field}`,"=",p]];return e.jsx(It,{view_id:o.get("graph").view_id,model:s.relation,domain:pe,context:{...m==null?void 0:m(),...P},limit:0})}};if(D)return e.jsx(u.Alert,{className:"mt-10",message:D,type:"error",banner:!0});const Ke=L;return S?e.jsx(u.Spin,{}):e.jsxs(e.Fragment,{children:[e.jsx(Pa,{mode:a,title:De(),readOnly:J,isMany2Many:le,formHasChanges:E,totalItems:re.length,currentItemIndex:d,onDelete:He,onCreateItem:Ie,onToggleViewMode:be,onPreviousItem:ye,onNextItem:xe,onSearchItem:R,selectedRowKeys:A,showCreateButton:((Ge=o.get("form"))==null?void 0:Ge.fields)!==void 0,showToggleButton:o.size>1}),Ze(),e.jsx(lt,{formView:o.get("form"),model:$,id:H==null?void 0:H.id,submitMode:"values",values:H==null?void 0:H.values,defaultValues:H==null?void 0:H.defaultValues,visible:b,onSubmitSucceed:Oe,parentContext:{...m==null?void 0:m(),...P},onCancel:()=>{V(!1),x(!1)},readOnly:J,mustClearAfterSave:Ke}),e.jsx(er,{domain:M.current,model:$,context:{...m==null?void 0:m(),...P},visible:O,onSelectValues:async Q=>{T(!1),Ae(Q)},onCloseModal:()=>{T(!1)}})]})},gn=t=>{const{ooui:r}=t,{mode:n,relation:s,views:o,required:i,context:a}=r;let c;const[d,f]=l.useState(!0),[h,p]=l.useState(),[g,v]=l.useState(new Map),m=l.useContext(_e),{getContext:y}=m||{};Qe.default(()=>{w()},[r]);const C=async _=>o&&o[_]?o[_]:await W.getHandler().getView({model:s,type:_,context:{...y==null?void 0:y(),...a}}),w=async()=>{f(!0),p(void 0);try{if(n&&n.length>0){for(const _ of n){const S=await C(_);g.set(_,S)}v(g)}else{const _=await C("form"),S=await C("tree");g.set("form",_),g.set("tree",S),v(g)}}catch(_){p(JSON.stringify(_))}finally{f(!1)}};if(n&&n.length>0?c=n[0]:c="tree",d)return e.jsx(u.Spin,{});if(h)return e.jsx(u.Alert,{className:"mt-10",message:h,type:"error",banner:!0});const E=async(_,S)=>{if(!S)throw new Error;if(!S.items)throw new Error;if(!Array.isArray(S.items))throw new Error;if(S.items.length===0)throw new Error};return e.jsx(ya,{initialView:c,children:e.jsx(me,{required:i,type:"array",validator:E,...t,children:e.jsx(Ka,{ooui:r,views:g})})})},{useToken:Wa}=u.theme,mn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"number",...t,children:e.jsx(qa,{ooui:r})})},qa=t=>{const{ooui:r,value:n,onChange:s}=t,{id:o,readOnly:i,required:a}=r,{token:c}=Wa(),d=a&&!i?{backgroundColor:c.colorPrimaryBg}:void 0,f=l.useRef(),[h,p]=l.useState(),g=l.useContext(_e),{elementHasLostFocus:v}=g||{};l.useEffect(()=>{p(Qr(n))},[n]);const m=w=>{s==null||s(w)};function y(w){f.current=w.target.value,p(w.target.value)}async function C(){m(ji(h)),await new Promise(w=>setTimeout(w,300)),v==null||v()}return e.jsx(u.Input,{value:h,disabled:i,className:"w-full",style:d,id:o,placeholder:"00:00",onChange:y,onBlur:C})};function rr(t){const{ooui:r,showLabel:n=!0,responsiveBehaviour:s}=t,o=qe(r.icon||"");return e.jsx(e.Fragment,{children:(r.label||o)&&n?e.jsx(hr.FieldSet,{label:r.label,icon:o,children:e.jsx(Jt,{container:r.container,responsiveBehaviour:s})}):e.jsx(Jt,{container:r.container,responsiveBehaviour:s})})}const{TabPane:Ya}=u.Tabs;function yn(t){const{ooui:r,responsiveBehaviour:n}=t,s=r.pages;function o(i){if(i){const a=qe(i);return a&&e.jsx(a,{})}}return e.jsx(u.Tabs,{defaultActiveKey:"1",tabPosition:r.tabPosition,children:s.filter(i=>!i.invisible).map(i=>e.jsx(Ya,{tab:e.jsxs(e.Fragment,{children:[o(i.icon)," ",i.label]}),children:e.jsx(rr,{ooui:i,showLabel:!1,responsiveBehaviour:n})},i.label))})}const{useToken:Ga}=u.theme,{TextArea:nr}=u.Input,vn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o,height:i,translatable:a}=r,{token:c}=Ga(),d=o&&!s?{backgroundColor:c.colorPrimaryBg}:void 0,f=l.useContext(_e),{elementHasLostFocus:h}=f||{};return e.jsx(me,{required:o,...t,children:a?e.jsx(Ua,{field:n,height:i,requiredStyle:d}):e.jsx(nr,{disabled:s||a,style:{height:i?i+"px":"100%",...d},rows:4,onBlur:h})})},Ua=({value:t,field:r,requiredStyle:n,onChange:s,height:o})=>{const i=l.useContext(_e),{activeId:a,activeModel:c,fetchValues:d,formHasChanges:f,elementHasLostFocus:h}=i||{},[p,g]=l.useState(!1),{t:v}=l.useContext(ge);return a?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:()=>{if(f!=null&&f()){ze(v("saveBeforeTranslate"));return}p||g(!0)},children:e.jsx(nr,{value:t,onChange:m=>{s==null||s(m.target.value)},style:{height:o?o+"px":"100%",cursor:"pointer",...n},id:r,disabled:!0,rows:4,onBlur:h})}),e.jsx(Fr,{id:a,model:c,field:r,visible:p,onCloseModal:()=>{g(!1)},onSubmitSucceed:()=>{g(!1),d==null||d()}})]}):e.jsxs(e.Fragment,{children:[e.jsx(u.Row,{gutter:8,wrap:!1,children:e.jsx(nr,{value:t,onChange:m=>{s==null||s(m.target.value)},style:{height:o?o+"px":"100%",...n},id:r,rows:4,onBlur:h})}),e.jsx(u.Row,{justify:"end",style:{paddingTop:5},children:e.jsx(Le,{tooltip:v("translate"),icon:e.jsx(B.TranslationOutlined,{}),onClick:async()=>{f!=null&&f()?ze(v("saveBeforeTranslate")):ze(v("enterTextBeforeTranslate"))},children:v("translate")})})]})},wn=t=>{const{ooui:r}=t,{label:n,icon:s}=r,o=qe(s||"");return e.jsx(u.Divider,{orientation:"left",className:"text-sm",children:(o||n)&&e.jsxs(u.Space,{children:[o?e.jsx(o,{}):null,n]})})},ja=({model:t,context:r,locale:n,selectedRegistersToExport:s,domain:o,limit:i,onClose:a})=>{const c=l.useRef({}),d=l.useRef(new Map),f=l.useCallback(async C=>{if(C.selectedKeys===void 0||C.selectedKeys.length===0){ze(Se("selectAtLeastOneField",n));return}let w=o;C.registersAmount==="selected"&&(s==null?void 0:s.length)!==0&&(w=[["id","in",s==null?void 0:s.map(S=>S.id)]]);const{datas:E}=await W.getHandler().exportData({model:t,fields:Ra({keys:C.selectedKeys,fields:c.current}),domain:w,limit:C.registersAmount==="all"?0:i,context:r,format:C.exportType});a(),await new Promise(S=>setTimeout(S,200));const _=await tt(E);Tt(E,_.mime)},[n,t,o,i,r,a]),h=l.useCallback(async()=>{const C=await W.getHandler().getFields({model:t,context:r,fields:[]});return c.current["/"]=C,Cn({fields:C})},[t,r,c]),p=l.useCallback(async C=>{const E=sr(C,c.current)[or(C)],_=E.relation,S=await W.getHandler().getFields({model:_,context:r,fields:[]});for(const[I,D]of Object.entries(S))S[I].string=Ja({parentTitle:E.string,title:D.string});return c.current[C]=S,Cn({fields:S,parentKey:C})},[c.current,t,r]),g=l.useCallback(async()=>{const C=await Za({model:t,context:r}),w=await Qa({predefinedExports:C,fields:c.current,onGetFieldChilds:p});return{predefinedExports:C.map(_=>({..._,fields:_.fields.map(S=>{const I=or(S.key),N=sr(S.key,c.current)[I];return{key:S.key,title:N.string}})})),keysWithChilds:w}},[c.current]),v=l.useCallback(async C=>{const w=await y("ir.exports"),E=await y("ir.exports.line"),_=await W.getHandler().create({model:"ir.exports",values:{name:C.name,resource:t},fields:w,context:r});return await Promise.all(C.fields.map(async S=>await W.getHandler().create({model:"ir.exports.line",values:{name:S.key,export_id:_},fields:E,context:r}))),{...C,id:_}},[]),m=l.useCallback(async C=>{await W.getHandler().delete({model:"ir.exports",ids:[C.id]})},[]),y=l.useCallback(async C=>{if(d.current.has(C))return d.current.get(C);const w=W.getHandler().getFields({model:C,context:r,fields:[]});d.current.set(C,w)},[d,r]);return{onGetFields:h,onGetFieldChilds:p,onExport:f,onGetPredefinedExports:g,onSavePredefinedExport:v,onRemovePredefinedExport:m}},Cn=({fields:t,parentKey:r})=>{const n=[];for(const s of Object.keys(t)){const o=t[s];if(o.relation&&o.is_function===!0)continue;const i=bn(o);n.push({key:za({key:s,parentKey:r}),title:o.string,tooltip:o.help,required:o.required,isLeaf:!i})}return n},bn=t=>t.type==="many2one"||t.type==="one2many"||t.type==="many2many",za=({parentKey:t,key:r})=>`${t?t+"/":""}${r}`,bt=t=>t.indexOf("/")===-1?t:t.split("/").slice(0,-1).join("/"),or=t=>{if(t.indexOf("/")===-1)return t;const r=t.split("/");return r[r.length-1]},sr=(t,r)=>t.indexOf("/")===-1?r["/"]:r[bt(t)],Ja=({title:t,parentTitle:r})=>`${r?r+" \u2192 ":""}${t}`,Za=async({model:t,context:r})=>{const n=await W.getHandler().search({model:"ir.exports",params:[["resource","=",t]],context:r}),s=n.flatMap(i=>i.export_fields),o=await W.getHandler().readObjects({model:"ir.exports.line",ids:s,context:r});return n.map(i=>({id:i.id,name:i.name,fields:i.export_fields.map(a=>({key:o.find(d=>d.id===a).name}))}))},Xa=({fields:t,keys:r})=>el([...new Set(r.filter(n=>{var s,o,i;if(n.indexOf("/")===-1)return!((s=t["/"])!=null&&s[n]);{const a=bt(n);console.log({key:n,parentKey:a,fields:t});const c=(o=t==null?void 0:t[bt(n)])==null?void 0:o[n];return console.log({exists:c}),!((i=t==null?void 0:t[bt(n)])!=null&&i[n])}}).map(n=>bt(n)))]),Qa=async({predefinedExports:t,fields:r,onGetFieldChilds:n})=>{const s=t.flatMap(a=>a.fields.map(c=>c.key)),o=Xa({fields:r,keys:s}),i=[];for(const a of o)i.push({key:a,childs:await n(a)});return i},Ra=({keys:t,fields:r})=>t.map(n=>{const s=or(n),i=sr(n,r)[s];return bn(i)?`${n}/id`:n}),el=t=>{const r=new Map,n=[];for(const s of t){const o=s.split("/");let i="";for(const a of o){const c=i?`${i}/${a}`:a;r.has(c)||(n.push(c),r.set(c,!0)),i=c}}return n.sort((s,o)=>{const i=s.split("/").length,a=o.split("/").length;return i-a}),n},Sn=t=>{const{visible:r,locale:n,onClose:s,model:o,context:i,selectedRegistersToExport:a,totalRegisters:c,domain:d,limit:f,visibleRegisters:h}=t,{onExport:p,onGetFieldChilds:g,onGetFields:v,onGetPredefinedExports:m,onSavePredefinedExport:y,onRemovePredefinedExport:C}=ja({model:o,context:i,domain:d,limit:f,selectedRegistersToExport:a,onClose:s,locale:n});return e.jsx(hr.ExportModal,{visible:r,locale:n,onSucceed:p,onCancel:s,selectedRegistersToExport:a&&a.length&&a.length>0?a.length:void 0,totalRegisters:c,onGetFieldChilds:g,onGetFields:v,visibleRegisters:h,onGetPredefinedExports:m,onSavePredefinedExport:y,onRemovePredefinedExport:C})},xn=t=>{const{ooui:r}=t;return e.jsx(nn,{ooui:r})},Tn=t=>{const{ooui:r}=t;return e.jsx(nn,{ooui:r,showTime:!0})},Fn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(tl,{ooui:r})})},tl=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,selectionValues:i,readOnly:a}=s,c=r==null?void 0:r.split(","),[d,f]=l.useState([]),[h,p]=l.useState();return l.useEffect(()=>{if(!r){p(void 0),f([]);return}const g=r&&c&&c[0],v=r&&c&&c[1]&&parseInt(c[1]);f([v,void 0]),p(g)},[r]),e.jsxs(u.Row,{gutter:8,wrap:!1,children:[e.jsx(u.Col,{flex:"1",children:e.jsx(Or,{ooui:new se.Selection({name:"model_selection",selection:i,readonly:a,required:o}),onChange:g=>{p(g);let v=d[0]||0;g!==h&&(f([]),v=0);const m=`${g},${v}`;m!==r&&(n==null||n(m))},value:h})}),e.jsx(u.Col,{flex:"3",children:e.jsx(cn,{ooui:new se.Many2one({name:"object_value",relation:h,readonly:a,required:o}),value:d,onChange:g=>{f(g);const v=`${h},${g[0]||0}`;v!==r&&(n==null||n(v))}})})]})},{useToken:rl}=u.theme,On=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(nl,{ooui:r})})},nl=t=>{const{ooui:r,value:n,onChange:s}=t,{readOnly:o,required:i,filenameField:a}=r,{token:c}=rl(),d=i&&!o?{backgroundColor:c.colorPrimaryBg}:void 0,f=l.useRef(null),{setFieldValue:h,getFieldValue:p}=l.useContext(_e)||{},{t:g}=l.useContext(ge),v=n?Ps(n):"",m=_=>{s==null||s(_)};async function y(){const _=await tt(n),S=`data:${_==null?void 0:_.mime};base64,${n}`,I=document.createElement("a"),D=p(a),N=p("name");I.href=S,I.download=D||N,I.click()}async function C(){const _=await tt(n);Tt(n,_.mime)}async function w(_){_.stopPropagation(),_.preventDefault();const S=_.target.files[0],I=await Br(S);m(I),a&&h(a,S.name)}function E(){h(a,void 0),m(void 0)}return e.jsxs(u.Row,{gutter:8,children:[e.jsxs(u.Col,{style:{paddingBottom:5},children:[e.jsx("input",{type:"file",id:"file",ref:f,style:{display:"none"},onChange:w}),e.jsx(u.Input,{type:"text",disabled:!0,style:d,value:v})]}),e.jsx(u.Col,{children:e.jsxs(u.Space,{children:[e.jsx(u.Button,{icon:e.jsx(B.FolderOpenOutlined,{}),disabled:o,onClick:()=>{f.current.click()},children:"Select"}),e.jsx(u.Button,{icon:e.jsx(B.EyeOutlined,{}),disabled:!n,onClick:C,children:g("open")}),e.jsx(Le,{tooltip:g("download"),disabled:!n,onClick:y,icon:e.jsx(B.DownloadOutlined,{})}),e.jsx(Le,{tooltip:g("clear"),disabled:o||!n,onClick:E,icon:e.jsx(B.ClearOutlined,{})})]})})]})},ir={tree:e.jsx(B.TableOutlined,{}),form:e.jsx(B.FormOutlined,{}),graph:e.jsx(B.AreaChartOutlined,{}),calendar:e.jsx(B.CalendarOutlined,{})};function _n(t){return t?(ir==null?void 0:ir[t.type])||e.jsx(B.FormOutlined,{}):e.jsx(B.FormOutlined,{})}function ar(t){const{currentView:r,availableViews:n,onChangeView:s,disabled:o=!1,formHasChanges:i=!1,previousView:a}=t,{t:c,lang:d}=l.useContext(ge);function f(){const g=n.map((v,m)=>e.jsx(u.Menu.Item,{children:e.jsxs(u.Row,{wrap:!1,children:[e.jsx(u.Col,{flex:"none",style:{paddingRight:20},children:_n(v)}),e.jsx(u.Col,{flex:"auto",style:{paddingRight:20},children:v.type.charAt(0).toUpperCase()+v.type.slice(1)}),e.jsx(u.Col,{flex:"none",children:e.jsx(B.CheckOutlined,{style:{opacity:r.view_id===v.view_id?1:0}})})]})},v.view_id||m));return e.jsx(u.Menu,{onClick:p,children:e.jsx(u.Menu.ItemGroup,{title:c("viewAs"),children:g})})}function h(g){if(i){yt({lang:d,onOk:()=>{g()}});return}g()}function p(g){h(()=>{const v=n.find(m=>m.view_id===parseInt(g.key));s(v)})}return e.jsxs("div",{style:{display:"flex"},children:[e.jsx(Le,{tooltip:a?c("viewAs")+" "+c(a.type):"",icon:_n(a),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:()=>{p({key:a==null?void 0:a.view_id})},disabled:o||n.length===1}),e.jsx(u.Dropdown,{overlay:f(),disabled:o||n.length===1,children:e.jsx(u.Button,{style:{width:25,borderTopLeftRadius:0,borderBottomLeftRadius:0},icon:e.jsx(B.DownOutlined,{style:{fontSize:"0.5em"}}),onClick:g=>g.preventDefault()})})]})}function dt(t){const{icon:r,tooltip:n,items:s=[],onItemClick:o,label:i,disabled:a=!1}=t;function c(){const f=s==null?void 0:s.map((h,p)=>h.name==="divider"?e.jsx(u.Menu.Divider,{},"divider"+p):e.jsx(u.Menu.Item,{children:h.name},h.id));return e.jsx(u.Menu,{onClick:d,children:e.jsx(u.Menu.ItemGroup,{title:n,children:f})})}function d(f){const h=s.find(p=>isNaN(f.key)?p.id===f.key:p.id===parseInt(f.key));o(h)}return e.jsx(u.Dropdown,{overlay:c(),disabled:a||!s||s.length===0,children:e.jsxs(u.Button,{children:[r," ",i," ",e.jsx(B.DownOutlined,{})]})})}function Ne(t){const{onClick:r,disabled:n=!1,loading:s=!1,tooltip:o,icon:i,label:a,type:c="default"}=t,d=s?e.jsx(B.LoadingOutlined,{}):i;return e.jsxs(Le,{type:c,tooltip:o,onClick:r,disabled:n,children:[d,a]})}function Dn(t){const{disabled:r=!1}=t,{formHasChanges:n,onNewClicked:s}=l.useContext(Be),{t:o,lang:i}=l.useContext(ge),a=()=>{if(n){yt({lang:i,onOk:()=>{s()}});return}s()};return e.jsx(Ne,{icon:e.jsx(B.FileAddOutlined,{}),tooltip:o("new"),onClick:a,disabled:r})}const{confirm:ol}=u.Modal,sl=({onOk:t,onCancel:r,lang:n})=>{ol({title:Se("unsavedChanges",n),icon:e.jsx(B.ExclamationCircleOutlined,{}),centered:!0,content:Se("confirmRefreshWithoutSave",n),okText:Se("discardAndRefresh",n),cancelText:Se("cancel",n),onOk:t,onCancel:r})};async function Vn(t,r,n){const s=(await W.getHandler().getLogInfo({model:t,ids:[r]}))[0],{create_date:o,create_uid:i,id:a,write_date:c,write_uid:d}=s;ze(e.jsxs("div",{children:["ID: "+a," ",e.jsx("br",{}),n("createdBy")+": "+i[1]," ",e.jsx("br",{}),n("creationDate")+": "+o," ",e.jsx("br",{}),n("lastUpdatedBy")+": "+d[1]," ",e.jsx("br",{}),n("lastUpdatedDate")+": "+c]}))}const il=t=>{const{numberOfAttachments:r,disabled:n}=t,{t:s,lang:o}=l.useContext(ge),[i,a]=l.useState(!1),c=e.jsxs(u.Button,{disabled:n,children:[e.jsx(B.LinkOutlined,{}),`(${r})`,e.jsx(B.DownOutlined,{style:{fontSize:12}})]});return n?c:e.jsx(u.Popover,{onVisibleChange:d=>a(d),visible:i,placement:"bottom",content:al(t,a,o),title:s("attachments"),arrowContent:null,children:c})},al=(t,r,n)=>{const{attachments:s=[],loading:o,onAddNewAttachment:i,onopenAttachmentLink:a,onOpenAttachmentDetail:c,onListAllAttachments:d}=t;return o?e.jsx(u.Spin,{style:{padding:20}}):e.jsxs(e.Fragment,{children:[e.jsxs("a",{style:{display:"block",paddingBottom:5},href:"#",onClick:()=>{r(!1),d()},children:[e.jsx(B.TableOutlined,{})," ",Se("listAllAttachments",n)]}),e.jsxs("a",{style:{display:"block"},href:"#",onClick:()=>{r(!1),i()},children:[e.jsx(B.FileAddOutlined,{})," ",Se("addNewAttachment",n)]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("li",{className:"ant-dropdown-menu-item-divider"}),s.map(f=>{const h=f.link?B.LinkOutlined:B.DownloadOutlined;return e.jsxs(u.Row,{style:{paddingTop:4,paddingBottom:4},wrap:!1,align:"middle",children:[e.jsx(u.Col,{flex:"auto",children:f.name}),e.jsx(u.Col,{flex:"25px",style:{textAlign:"center"},children:(f.datas_fname||f.link)&&e.jsx(u.Tooltip,{title:f.link?Se("openAttachmentLink",n):Se("download",n),children:e.jsx(h,{style:{cursor:"pointer"},onClick:()=>{r(!1),a(f)}})})}),e.jsx(u.Col,{flex:"25px",style:{textAlign:"center"},children:e.jsx(u.Tooltip,{title:Se("openAttachment",n),children:e.jsx(B.FormOutlined,{style:{cursor:"pointer"},onClick:()=>{r(!1),c(f)}})})})]},f.id)})]})]})};function ll(t){const{attachments:r,disabled:n=!1,onAddNewAttachment:s,onListAllAttachments:o,onViewAttachmentDetails:i}=t,{formRef:a}=l.useContext(Be),[c,d]=l.useState(!1),[f,h]=l.useState([]),[p,g]=l.useState(!1),{t:v}=l.useContext(ge),m=l.useCallback(async()=>{d(!0);try{const w=await W.getHandler().readObjects({model:"ir.attachment",ids:r.map(E=>E.id),fieldsToRetrieve:["name","datas_fname","link"],context:a.current.getContext()});h(w.map(E=>({id:E.id,name:E.name,datas_fname:E.datas_fname,link:E.link})))}catch(w){Me(w)}d(!1)},r),y=l.useCallback(async w=>{if(w.link){window.open(w.link);return}g(!0);let E;try{E=(await W.getHandler().readObjects({model:"ir.attachment",ids:[w.id],context:a.current.getContext()}))[0]}catch(_){Me(_)}if(g(!1),!!E)if(E.datas){const _=await tt(E.datas);Tt(E.datas,_.mime)}else i(E)},[]),C=l.useCallback(async w=>{i(w)},[]);return l.useEffect(()=>{m()},[m]),e.jsxs(e.Fragment,{children:[e.jsx(il,{numberOfAttachments:r.length,attachments:f,disabled:n,loading:c,onAddNewAttachment:s,onListAllAttachments:o,onopenAttachmentLink:y,onOpenAttachmentDetail:C}),e.jsx(u.Modal,{title:v("downloadingAttachment"),open:p,footer:null,closable:!1,centered:!0,maskClosable:!1,children:e.jsx(u.Spin,{})})]})}function kn({toolbar:t}){const{availableViews:r,currentView:n,setCurrentView:s,onFormSave:o,formHasChanges:i,formIsSaving:a,currentId:c,results:d,setCurrentItemIndex:f,currentItemIndex:h,setCurrentId:p,currentModel:g,setRemovingItem:v,removingItem:m,duplicatingItem:y,setDuplicatingItem:C,setResults:w,formIsLoading:E,attachments:_,formRef:S,setFormHasChanges:I,previousView:D,setPreviousView:N,goToResourceId:b}=l.useContext(Be),{t:x,lang:O}=l.useContext(ge),T=l.useContext(it),{processAction:H}=T||{},F=l.useContext(Ye),{openRelate:A,openDefaultActionForModel:k}=F||{};function L($){if(i){sl({lang:O,onOk:()=>{$()}});return}$()}function V($){if(i){yt({lang:O,onOk:()=>{$()}});return}$()}function M(){d&&d.length>h+1?(f==null||f(h+1),p==null||p(d[h+1].id)):d&&h+1===d.length&&(f==null||f(0),p==null||p(d[0].id))}function K(){d&&h>0?(f==null||f(h-1),p==null||p(d[h-1].id)):d&&h===0&&(f==null||f(d.length-1),p==null||p(d[d.length-1].id))}function q(){et({confirmMessage:x("confirmRemoveItem"),lang:O,onOk:()=>{z()}})}async function z(){try{v==null||v(!0),await W.getHandler().delete({model:g,ids:[c]});const $=d==null?void 0:d.filter(ee=>ee.id!==c);w==null||w($);let P=0;h>0&&h<=d.length-1&&(P=h-1),$!=null&&$[P]?(p==null||p($==null?void 0:$[P].id),f==null||f(P)):(p==null||p(void 0),f==null||f(void 0))}catch($){_t(JSON.stringify($))}finally{v==null||v(!1)}}async function Y(){try{C==null||C(!0);const $=await W.getHandler().duplicate({id:c,model:g,context:S.current.getContext()});$&&await(b==null?void 0:b($))}catch($){_t(JSON.stringify($))}finally{C==null||C(!1)}}const Z=a||m||E||y;function J($){H==null||H({actionData:$,values:S.current.getValues(),fields:S.current.getFields(),context:S.current.getContext(),onRefreshParentValues:()=>{S.current.fetchValues()}})}return n?e.jsxs(u.Space,{wrap:!0,children:[E&&e.jsxs(e.Fragment,{children:[e.jsx(u.Spin,{}),ut(),ut()]}),e.jsx(Dn,{disabled:a||E||m||y}),e.jsx(Ne,{icon:e.jsx(B.SaveOutlined,{}),tooltip:x("save"),disabled:!i||Z,loading:a,onClick:o}),e.jsx(Ne,{icon:e.jsx(B.CopyOutlined,{}),tooltip:x("duplicate"),disabled:i||a||c===void 0||y||E,loading:y,onClick:Y}),e.jsx(Ne,{icon:e.jsx(B.DeleteOutlined,{}),tooltip:x("delete"),disabled:a||c===void 0||m||y||E,loading:m,onClick:q}),ut(),e.jsx(Ne,{icon:e.jsx(B.InfoCircleOutlined,{}),tooltip:x("showLogs"),disabled:a||c===void 0||m||y||E,loading:!1,onClick:()=>{Vn(g,c,x)}}),e.jsx(Ne,{icon:e.jsx(B.ReloadOutlined,{}),tooltip:x("refresh"),disabled:a||c===void 0||m||y||E,loading:!1,onClick:()=>{L(()=>{S.current.fetchValues()})}}),ut(),e.jsx(ar,{currentView:n,previousView:D,availableViews:r,onChangeView:$=>{N==null||N(n),I==null||I(!1),s==null||s($)},disabled:Z,formHasChanges:i}),ut(),e.jsxs(u.Space,{children:[e.jsx(Ne,{icon:e.jsx(B.LeftOutlined,{}),tooltip:x("previous"),disabled:Z,loading:!1,onClick:()=>{V(K)}}),e.jsx(Ne,{icon:e.jsx(B.RightOutlined,{}),tooltip:x("next"),disabled:Z,loading:!1,onClick:()=>{V(M)}})]}),ut(),e.jsx(dt,{icon:e.jsx(B.ThunderboltOutlined,{}),disabled:Z,tooltip:x("actions"),items:t==null?void 0:t.action,onItemClick:async $=>{!$||!(await ft({onFormSave:o})).succeed||J($)}}),e.jsx(dt,{icon:e.jsx(B.PrinterOutlined,{}),disabled:Z,tooltip:x("reports"),items:t==null?void 0:t.print,onItemClick:async $=>{if(!$)return;const P=await ft({onFormSave:o});!P.succeed||J({...$,datas:{...$.datas||{},ids:[P.currentId]}})}}),e.jsx(dt,{icon:e.jsx(B.EnterOutlined,{}),disabled:Z,tooltip:x("related"),items:t==null?void 0:t.relate,onItemClick:async $=>{!$||!(await ft({onFormSave:o})).succeed||A({relateData:$,values:S.current.getValues(),fields:S.current.getFields(),action_id:$.id,action_type:$.type})}}),e.jsx(ll,{disabled:Z,attachments:_,onAddNewAttachment:async()=>{const $=await ft({onFormSave:o});if(!$.succeed)return;const P=$.currentId,ee=g;k({model:"ir.attachment",values:{selection_associated_object:`${ee},${P}`},forced_values:{res_model:ee,res_id:P},initialViewType:"form"})},onListAllAttachments:async()=>{const $=await ft({onFormSave:o});if(!$.succeed)return;const P=$.currentId;k({model:"ir.attachment",domain:[["res_model","=",`${g}`],["res_id","=",`${P}`]],initialViewType:"tree"})},onViewAttachmentDetails:async $=>{!(await ft({onFormSave:o})).succeed||k({model:"ir.attachment",res_id:$.id,initialViewType:"form"})}})]}):null}function ut(){return e.jsx("div",{className:"inline-block w-2"})}async function ft({onFormSave:t}){const r=await(t==null?void 0:t());return r!=null&&r.succeed?{succeed:!0,currentId:r.id}:{succeed:!1,currentId:void 0}}const{useToken:cl}=u.theme,En=t=>{const{ooui:r,value:n,onChange:s,valueValidator:o,linkPrefix:i=""}=t,{id:a,readOnly:c,required:d}=r,{token:f}=cl(),h=d&&!c?{backgroundColor:f.colorPrimaryBg}:void 0,p=l.useContext(_e),{elementHasLostFocus:g}=p||{},[v,m]=l.useState(!1),[y,C]=l.useState(!1);l.useEffect(()=>{c&&!v&&C(!1),!n&&!c&&(m(!0),C(!0))},[v,c]);const w=E=>{s==null||s(E.target.value)};return e.jsxs(u.Row,{gutter:8,wrap:!1,align:"middle",children:[c?null:e.jsx(u.Col,{flex:"32px",children:v?e.jsx(u.Button,{icon:e.jsx(B.CheckOutlined,{}),onClick:()=>{o(n)&&(m(!1),C(!1))},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1}):e.jsx(u.Button,{icon:e.jsx(B.EditOutlined,{}),onClick:()=>{m(!0),C(!0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1})}),e.jsx(u.Col,{flex:"auto",children:y?e.jsx(u.Input,{style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,...h},id:a,onChange:w,value:n,onBlur:()=>{o(n)&&(m(!1),C(!1),g==null||g())}}):e.jsx("a",{href:`${i}${n}`,style:{color:f.colorPrimary,paddingRight:15},target:"_blank",children:n})})]})},In=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(En,{ooui:r,valueValidator:s=>s?co.default(s):!1})})},Mn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,...t,children:e.jsx(En,{ooui:r,linkPrefix:"mailto:",valueValidator:s=>s?uo.default(s):!1})})},dl=t=>{const{visible:r,onIdSubmitted:n,onCancel:s,isSearching:o}=t,{t:i}=l.useContext(ge);function a(c){n(c.id)}return e.jsx(u.Modal,{title:i("goToResourceId"),centered:!0,open:r,footer:null,destroyOnClose:!0,onCancel:s,maskClosable:!1,children:e.jsxs(u.Form,{layout:"vertical",onFinish:a,autoComplete:"off",children:[e.jsx(u.Form.Item,{name:"id",label:i("searchId"),rules:[{required:!0,type:"number"}],children:e.jsx(u.InputNumber,{style:{width:"100%"},autoFocus:!0})}),e.jsx(u.Row,{align:"middle",justify:"end",children:e.jsx(u.Col,{children:e.jsxs(u.Space,{children:[e.jsx(u.Button,{icon:e.jsx(B.CloseOutlined,{}),htmlType:"button",onClick:s,disabled:o,children:i("cancel")}),e.jsx(u.Button,{loading:o,style:{marginLeft:15},icon:e.jsx(B.CheckOutlined,{}),htmlType:"submit",type:"primary",disabled:o,children:i("ok")})]})})})]})})},{useToken:ul}=u.theme;function An(t){const{badgeNumber:r=0,...n}=t,{token:s}=ul();return e.jsxs("div",{style:{position:"relative"},children:[r>0&&e.jsx("div",{style:{position:"absolute",left:-10,top:-10,zIndex:2},children:e.jsx("span",{style:{display:"inline-block",minWidth:"22px",padding:"2px",borderRadius:"50%",fontSize:"12px",textAlign:"center",background:s.colorPrimaryHover,color:s.colorPrimaryBg},children:r})}),e.jsx(Le,{...n,style:{width:46,zIndex:0}})]})}function fl({refreshGraph:t}){const{t:r}=l.useContext(ge),{availableViews:n,currentView:s,setCurrentView:o,searchParams:i,searchVisible:a,setSearchVisible:c,graphIsLoading:d,previousView:f,setPreviousView:h}=l.useContext(Be);return e.jsxs(u.Space,{wrap:!0,children:[e.jsx(An,{icon:e.jsx(B.FilterOutlined,{style:{color:a?"white":void 0}}),tooltip:r("advanced_search"),type:a?"primary":"default",onClick:()=>{c==null||c(!a)},disabled:d,badgeNumber:i==null?void 0:i.length}),e.jsx(Ne,{icon:e.jsx(B.ReloadOutlined,{}),tooltip:r("refresh"),disabled:d,loading:!1,onClick:()=>{t()}}),e.jsx(ar,{currentView:s,availableViews:n,onChangeView:p=>{h==null||h(s),o==null||o(p)},disabled:!1,previousView:f})]})}const{useToken:hl}=u.theme,{Title:pl,Text:Mt}=u.Typography;function At(t){const{title:r,children:n}=t,{title:s,currentView:o,currentId:i,currentItemIndex:a,results:c,totalItems:d,selectedRowItems:f}=l.useContext(Be),{t:h}=l.useContext(ge),{token:p}=hl();function g(){if((o==null?void 0:o.type)==="form")return i?d===0?e.jsxs(e.Fragment,{children:[h("editingDocument")," (id:"," ",e.jsx(Mt,{copyable:{icon:e.jsx(B.CopyOutlined,{style:{color:"red"}})},children:i}),")"]}):e.jsxs(e.Fragment,{children:[h("register")," ",a===void 0?1:a+1," /"," ",c.length," ",h("of")," ",d," - ",h("editingDocument")," (id:"," ",e.jsx(Mt,{copyable:!0,children:i}),")"]}):"";if((o==null?void 0:o.type)==="tree"&&f){if(f.length===1)return e.jsxs(e.Fragment,{children:["1 ",h("selectedRegisters")," - (id:"," ",e.jsx(Mt,{copyable:!0,children:f[0].id}),")"]});if(f.length>1)return e.jsxs(e.Fragment,{children:[f.length," ",h("selectedRegisters"),e.jsx(Mt,{copyable:{text:f.map(v=>v.id).join(", ")}})]})}return null}return e.jsxs("div",{style:{position:"sticky",top:80,zIndex:3},children:[e.jsxs(u.Row,{className:"shadow-md",style:{padding:"1em",borderRadius:p.borderRadius,backgroundColor:p.colorPrimaryBg},align:"middle",children:[e.jsxs(u.Col,{flex:2,children:[e.jsx(pl,{level:3,style:{marginBottom:0},children:r||s}),g()]}),e.jsx(u.Col,{flex:3,children:e.jsx(u.Row,{justify:"end",children:n})})]}),e.jsx("div",{className:"pb-5"})]})}const gl=t=>{const{viewData:r,visible:n,model:s,context:o,domain:i,formView:a,treeView:c}=t,d=l.useRef(),f=l.useContext(Be),{setResults:h=void 0,setCurrentItemIndex:p=void 0,currentId:g=void 0,results:v=void 0,setSelectedRowItems:m=void 0,setSearchParams:y=void 0,searchVisible:C=!0,setSearchVisible:w=void 0,sorter:E=void 0,setSorter:_=void 0,setTotalItems:S=void 0,setSearchTreeNameSearch:I=void 0,setTreeIsLoading:D=void 0,limit:N,setLimit:b,searchParams:x,searchValues:O,setSearchValues:T,currentView:H}=f||{},[F,A]=l.useState(!0);l.useEffect(()=>{var q;(q=d.current)==null||q.refresh()},[x]),l.useEffect(()=>{r.view_id!==H.view_id&&A(!0)},[H]);const{clear:k,searchFilterLoading:L,searchError:V,offset:M,tableRefreshing:K}=zr({model:s,setSearchTreeNameSearch:I,setSelectedRowItems:m,searchParams:x,setSearchValues:T,setSearchParams:y,setSearchVisible:w,setTreeIsLoading:D,context:o,formView:a,treeView:c,sorter:E,setSorter:_,setCurrentItemIndex:p,setResultsActionView:h,resultsActionView:v,domain:i,currentId:g,setActionViewTotalItems:S,limit:N,setLimit:b});return!n||!r?null:e.jsxs(e.Fragment,{children:[e.jsx(At,{title:r.name,children:e.jsx(fl,{refreshGraph:()=>{d.current.refresh()}})}),e.jsx(Xt,{fields:{...c.fields,...a.fields},searchFields:Wr([a.search_fields,c.search_fields]),formXml:a.arch,limit:N,onClear:k,offset:M,isSearching:L,onSubmit:q=>{A(!1),y==null||y(q.params),w==null||w(!1)},searchError:V,searchVisible:C,searchValues:O,showLimitOptions:!1}),K?e.jsx(u.Spin,{}):e.jsx(It,{ref:d,view_id:r.view_id,model:s,context:o,domain:Ot(x||[],i),limit:F?N:void 0,manualIds:F?v==null?void 0:v.map(q=>q.id):void 0})]})},ml=t=>{const{visible:r,formRef:n,model:s,currentId:o,domain:i,formView:a,context:c,defaultValues:d,forcedValues:f,results:h,setResults:p,setCurrentItemIndex:g}=t;return r?e.jsxs(e.Fragment,{children:[e.jsx(At,{children:e.jsx(kn,{toolbar:a==null?void 0:a.toolbar})}),e.jsx(at,{rootForm:!0,ref:n,model:s,defaultValues:d,forcedValues:f,formView:a,actionDomain:i,id:o,parentContext:c,onSubmitSucceed:(v,m)=>{h.findIndex(C=>C.id===v)===-1&&(h.push(m),p(h),g(h.length-1))}})]}):null};function yl(t){const{onSearch:r,disabled:n=!1,searchText:s}=t,{t:o}=l.useContext(ge),[i]=u.Form.useForm(),[a,c]=l.useState(!1);function d(h){r(h.search)}l.useEffect(()=>{i.setFieldsValue({search:s})},[s]);function f(){c(!1),i.setFieldsValue({search:void 0}),r(void 0)}return e.jsx(u.Form,{form:i,onFinish:d,autoComplete:"off",children:e.jsxs(u.Row,{align:"middle",justify:"end",children:[e.jsx(u.Col,{children:e.jsx(u.Form.Item,{name:"search",noStyle:!0,children:e.jsx(u.Input,{autoFocus:!0,disabled:n,onChange:h=>{c(h.target.value.length>0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},suffix:(a||s&&s.length>0)&&e.jsx(u.Tooltip,{title:o("clear"),children:e.jsx(B.CloseCircleFilled,{style:{color:"rgba(0,0,0,.45)"},onClick:f})})})})}),e.jsx(u.Col,{children:e.jsx(u.Button,{htmlType:"submit",disabled:n,style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},children:o("search")})})]})})}const $n=Pe.default.createContext({previewFeatures:!1});function vl(t){var Z;const{availableViews:r,currentView:n,setCurrentView:s,selectedRowItems:o,setRemovingItem:i,removingItem:a,duplicatingItem:c,setDuplicatingItem:d,currentModel:f,searchTreeRef:h,setCurrentId:p,setCurrentItemIndex:g,searchParams:v,searchVisible:m,setSearchVisible:y,setSearchTreeNameSearch:C,searchTreeNameSearch:w,treeIsLoading:E,setPreviousView:_,previousView:S,results:I,limit:D,totalItems:N}=l.useContext(Be),{parentContext:b={},treeExpandable:x,toolbar:O}=t,{previewFeatures:T}=l.useContext($n),{t:H,lang:F}=l.useContext(ge),A=l.useContext(it),{processAction:k}=A||{},[L,V]=l.useState(!1),M=w!==void 0&&w.trim().length>0;function K(){et({confirmMessage:H("confirmRemove"),lang:F,onOk:()=>{q()}})}async function q(){var J;try{i==null||i(!0),await W.getHandler().delete({model:f,ids:o.map($=>$.id)}),p==null||p(void 0),g==null||g(void 0),(J=h==null?void 0:h.current)==null||J.refreshResults()}catch($){Me($)}finally{i==null||i(!1)}}async function z(){var J;try{d==null||d(!0);const $=o[0].id;await W.getHandler().duplicate({id:$,model:f,context:{...b}})&&((J=h==null?void 0:h.current)==null||J.refreshResults())}catch($){Me($)}finally{d==null||d(!1)}}function Y(J){k==null||k({actionData:J,values:{active_id:o==null?void 0:o.map($=>$.id)[0],active_ids:o==null?void 0:o.map($=>$.id)},fields:{},context:{...b,active_id:o==null?void 0:o.map($=>$.id)[0],active_ids:o==null?void 0:o.map($=>$.id)},onRefreshParentValues:()=>{var $;($=h==null?void 0:h.current)==null||$.refreshResults()}})}return e.jsxs(u.Space,{wrap:!0,children:[x?null:e.jsxs(e.Fragment,{children:[e.jsx(yl,{disabled:c||a||E,searchText:w,onSearch:J=>{J&&J.trim().length>0?C==null||C(J):C==null||C(void 0)}}),!x&&e.jsx(An,{icon:e.jsx(B.FilterOutlined,{style:{color:m?"white":void 0}}),tooltip:H("advanced_search"),type:m?"primary":"default",onClick:()=>{y==null||y(!m)},disabled:c||a||E,badgeNumber:v==null?void 0:v.length}),St(),e.jsx(Dn,{disabled:E}),e.jsx(Ne,{icon:e.jsx(B.CopyOutlined,{}),tooltip:H("duplicate"),disabled:!o||(o==null?void 0:o.length)!==1||c||E,loading:c,onClick:z}),e.jsx(Ne,{icon:e.jsx(B.DeleteOutlined,{}),tooltip:H("delete"),disabled:!(o&&(o==null?void 0:o.length)>0)||E,loading:a,onClick:K}),St()]}),e.jsx(Ne,{icon:e.jsx(B.InfoCircleOutlined,{}),tooltip:H("showLogs"),disabled:!(o&&(o==null?void 0:o.length)>0)||E,loading:!1,onClick:()=>{Vn(f,o[0].id,H)}}),e.jsx(Ne,{icon:e.jsx(B.ReloadOutlined,{}),tooltip:H("refresh"),disabled:c||a||E,loading:!1,onClick:()=>{var J;(J=h==null?void 0:h.current)==null||J.refreshResults()}}),!x&&e.jsxs(e.Fragment,{children:[St(),e.jsx(ar,{currentView:n,availableViews:r,onChangeView:J=>{_==null||_(n),s==null||s(J)},previousView:S,disabled:E})]}),St(),e.jsx(dt,{icon:e.jsx(B.ThunderboltOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||E,tooltip:H("actions"),items:O==null?void 0:O.action,onItemClick:J=>{!J||Y(J)}}),e.jsx(dt,{icon:e.jsx(B.PrinterOutlined,{}),disabled:!(o&&(o==null?void 0:o.length)>0)||E,tooltip:H("reports"),items:O==null?void 0:O.print,onItemClick:J=>{!J||Y({...J,datas:{...J.datas||{},ids:o.map($=>$.id)}})}}),T&&e.jsxs(e.Fragment,{children:[St(),e.jsx(dt,{icon:e.jsx(vr.default,{component:()=>e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-database-export",width:"1em",height:"1em",viewBox:"0 0 24 24",strokeWidth:"1.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),e.jsx("ellipse",{cx:"12",cy:"6",rx:"8",ry:"3"}),e.jsx("path",{d:"M4 6v6c0 1.657 3.582 3 8 3a19.84 19.84 0 0 0 3.302 -.267m4.698 -2.733v-6"}),e.jsx("path",{d:"M4 12v6c0 1.599 3.335 2.905 7.538 2.995m8.462 -6.995v-2m-6 7h7m-3 -3l3 3l-3 3"})]})}),tooltip:H("export"),items:[{id:"print_screen",name:H("printScreen")},{id:"export",name:H("advancedExport")}],onItemClick:J=>{if(J.id==="print_screen"){let $=(o==null?void 0:o.map(P=>P.id))||[];$.length===0&&($=(I==null?void 0:I.map(P=>P.id))||[]),Y({id:-1,model:f,report_name:"printscreen.list",type:"ir.actions.report.xml",datas:{model:f,ids:$}});return}V(!0)},disabled:c||a||E||M}),e.jsx(Sn,{visible:L,locale:F,onClose:()=>V(!1),model:f,domain:Ot(((Z=h==null?void 0:h.current)==null?void 0:Z.getDomain())||[],v||[]),limit:D,totalRegisters:N||0,selectedRegistersToExport:o,visibleRegisters:(I==null?void 0:I.length)||0,context:b})]})]})}function St(){return e.jsx("div",{className:"inline-block w-2"})}const wl=t=>{const{visible:r,searchTreeRef:n,model:s,context:o,formView:i,treeView:a,domain:c,setCurrentItemIndex:d,results:f,setCurrentId:h,setCurrentView:p,availableViews:g,searchTreeNameSearch:v}=t,{currentView:m,setPreviousView:y}=l.useContext(Be);return r?e.jsxs(e.Fragment,{children:[e.jsx(At,{children:e.jsx(vl,{toolbar:a==null?void 0:a.toolbar,parentContext:o,treeExpandable:(a==null?void 0:a.isExpandable)||!1})}),e.jsx(Rt,{ref:n,rootTree:!0,model:s,parentContext:o,nameSearch:v,formView:i,treeView:a,domain:c,onRowClicked:C=>{const{id:w}=C;h(w);const E=f.findIndex(S=>S.id===w);y==null||y(m),d(E);const _=g.find(S=>S.type==="form");p(_)}})]}):null},lr=Pe.default.createContext(null),Cl=t=>{const[r,n]=l.useState(!1),[s,o]=l.useState(!1),{children:i,dashboardRef:a,openAction:c}=t;return e.jsx(lr.Provider,{value:{isLoading:r,setIsLoading:n,dashboardRef:a,openAction:c,moveItemsEnabled:s,setMoveItemsEnabled:o},children:i})};function bl(){const{isLoading:t,dashboardRef:r,moveItemsEnabled:n,setMoveItemsEnabled:s}=l.useContext(lr),{t:o}=l.useContext(ge);return e.jsxs(u.Space,{wrap:!0,children:[e.jsx(Ne,{icon:e.jsx(B.BorderOuterOutlined,{style:{color:n?"white":void 0}}),type:n?"primary":"default",tooltip:o("moveDashboard"),disabled:t,loading:!1,onClick:()=>{s(!n)}}),Sl(),e.jsx(Ne,{icon:e.jsx(B.SettingOutlined,{}),tooltip:o("configDashboard"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.configDashboard()}}),e.jsx(Ne,{icon:e.jsx(B.ReloadOutlined,{}),tooltip:o("refresh"),disabled:t,loading:!1,onClick:()=>{r==null||r.current.refresh()}})]})}function Sl(){return e.jsx("div",{className:"inline-block w-2"})}const xl=t=>{const{dashboardData:r}=t,n=l.useRef(),s=l.useContext(Ye),{openShortcut:o}=s||{};return r?e.jsxs(Cl,{dashboardRef:n,openAction:i=>{o(i)},children:[e.jsx(At,{children:e.jsx(bl,{})}),e.jsx(Bn,{ref:n,model:r.model,id:r.id,context:r==null?void 0:r.context,configAction:r==null?void 0:r.configAction})]}):null};function Tl(t,r){const{domain:n,model:s,context:o,views:i,title:a,setCanWeClose:c,tabKey:d,initialView:f,formDefaultValues:h,formForcedValues:p={},res_id:g=!1,action_id:v,action_type:m,treeExpandable:y=!1,limit:C}=t,[w,E]=l.useState(),[_,S]=l.useState([]),[I,D]=l.useState(!0),N=g||void 0,[b,x]=l.useState(N),[O,T]=l.useState([]),[H,F]=l.useState(),[A,k]=l.useState([]),[L,V]=l.useState(),[M,K]=l.useState(0),[q,z]=l.useState(!1),[Y,Z]=l.useState(!1),[J,$]=l.useState(),{t:P}=l.useContext(ge),ee=l.useRef(),le=l.useRef(),ce=l.useContext(Ye),{setCurrentView:re,setCurrentId:X,tabs:ve,activeKey:Ce,openAction:ke,onRemoveTab:fe}=ce||{};so.useHotkeys("ctrl+g,command+g",R=>{R.preventDefault(),Ee()},[Ce,ve,w,H,A]);function oe(R){x(R),X==null||X(R)}function be(R){E(R),re==null||re(R)}l.useImperativeHandle(r,()=>({canWeClose:xe}));const ye=async()=>{D(!0);const R=[];for(const he of i){const[Oe,ue]=he;let Ae;try{ue!=="dashboard"&&(Ae=await W.getHandler().getView({model:s,type:ue,id:Oe,context:o}))}catch(De){console.error(`${s} - ${ue}\xA0- ${JSON.stringify(De,null,2)}`);continue}switch(ue){case"dashboard":{const De=i.find(Ke=>{const[,Ge]=Ke;return Ge==="form"});let Ze;De&&(Ze={action_id:v,action_type:m,name:a,res_id:o.active_id,res_model:s,view_id:De[0],view_type:De[1]}),R.push({type:"dashboard",id:o.active_id,model:s,context:o,configAction:Ze});break}case"form":{R.push({...Ae,type:ue});break}case"tree":{R.push({...Ae,isExpandable:y,type:ue});break}case"graph":{R.push({...Ae,type:ue});break}}}let ae;!f&&R.find(he=>he.type==="tree")?ae=R.find(Oe=>Oe.type==="tree"):f?ae=R.find(Oe=>f.id?Oe.type===f.type&&Oe.view_id===f.id:Oe.type===f.type):ae=R.find(Oe=>Oe.type==="form"),ae||(Me(`Error determining the first view to show for model ${s}.
36
- Please, make sure the view ids on the fields_view_get responses are the same as the ones defined in the action`),fe==null||fe(d)),be(ae),S(R),D(!1)};c({tabKey:d,canWeClose:xe}),l.useEffect(()=>{const R=_.find(he=>he.type==="tree"),ae=_.find(he=>f.id?he.type===f.type&&he.view_id===f.id:he.type===f.type);be(ae||R),g?X==null||X(N):(oe(void 0),F(void 0)),ye()},[s,i,g]),l.useEffect(()=>{Ce===d&&(X==null||X(b),re==null||re(w))},[ve,Ce]);async function xe(){return w&&w.type==="form"?await ee.current.cancelUnsavedChanges():!0}async function Ee(){Ce===d&&(w.type==="form"&&!await ee.current.cancelUnsavedChanges()||z(!0))}async function Ve(R){var ue;Z(!0);const ae=A.findIndex(Ae=>Ae.id===R);let he;if(ae===-1){try{he=(ue=await W.getHandler().readObjects({model:s,ids:[R],context:o}))==null?void 0:ue[0]}catch{}if(!he){Z(!1),z(!1),ze(P("idNotFound"));return}}else he=A[ae];Z(!1),z(!1);const Oe=i.find(Ae=>Ae[1]==="form");ke({domain:[],context:o,model:s,views:i,title:a,target:"current",initialView:{id:Oe==null?void 0:Oe[0],type:"form"},action_id:v,action_type:m,res_id:R})}function He(){return _.map(R=>{switch(R.type){case"form":return e.jsx(ml,{formRef:ee,currentId:b,visible:w.type===R.type&&w.view_id===R.view_id,formView:R,model:s,context:o,domain:n,defaultValues:h,forcedValues:p,results:A,setResults:k,setCurrentItemIndex:F},`${R.type}-${R.view_id}`);case"tree":return e.jsx(wl,{visible:w.type===R.type&&w.view_id===R.view_id,limit:C,model:s,context:o,domain:n,formView:_.find(ae=>ae.type==="form"),treeView:R,searchTreeRef:le,searchTreeNameSearch:J,availableViews:_,results:A,setCurrentItemIndex:F,setCurrentId:oe,setCurrentView:be},`${R.type}-${R.view_id}`);case"graph":return e.jsx(gl,{visible:w.type===R.type&&w.view_id===R.view_id,viewData:R,model:s,context:o,domain:n,treeView:_.find(ae=>ae.type==="tree"),formView:_.find(ae=>ae.type==="form")},`${R.type}-${R.view_id}`);case"dashboard":return e.jsx(xl,{dashboardData:R},`${R.type}-${R.view_id}`)}})}function Ie(){if(b===void 0&&w.type==="form")ee.current.clearAndReload();else{oe(void 0);const R=_.find(ae=>ae.type==="form");be(R)}}return I?e.jsx(u.Spin,{}):w?e.jsxs(xi,{title:a,currentView:w,setCurrentView:be,availableViews:_,formRef:ee,searchTreeRef:le,onNewClicked:Ie,currentId:b,setCurrentId:oe,setCurrentItemIndex:F,currentItemIndex:H,results:A,setResults:k,currentModel:s,sorter:L,setSorter:V,totalItems:M,setTotalItems:K,selectedRowItems:O,setSelectedRowItems:T,setSearchTreeNameSearch:$,searchTreeNameSearch:J,goToResourceId:Ve,limit:C,children:[He(),e.jsx(dl,{visible:q,onIdSubmitted:Ve,isSearching:Y,onCancel:()=>{z(!1)}})]}):null}const Ln=l.forwardRef(Tl);async function Fl({actionId:t,rootContext:r={},globalValues:n={}}){const s="ir.actions.act_window",o=`${s},${t}`,i=await W.getHandler().getActionData({action:o,context:r}),a=se.parseContext({context:i.context,values:n,fields:{}}),c=i.domain?await W.getHandler().evalDomain({domain:i.domain,values:n,context:{...r,...a}}):[],{res_model:d,views:f,name:h,limit:p,view_type:g}=i,v=g==="tree",m=[];for(const E of f){const[_,S]=E;if(_)m.push(E);else{const{view_id:I}=await W.getHandler().getView({model:d,type:S,id:_,context:{...r,...a}});m.push([I,S])}}const[y,C]=m[0],w={id:y,type:C};return{title:h,actionId:t,actionType:s,key:gr.v4(),views:f,model:d,context:{...r,...a},domain:c,initialView:w,limit:p,treeExpandable:v}}const vc="",Ol=pr.WidthProvider(pr.Responsive),Nn=t=>{const{children:r=[],onPositionItemsChanged:n}=t,s=Pe.default.Children.map(r,o=>{const{parms:i,id:a}=o.props;return e.jsx("div",{"data-grid":i,children:o},a)});return e.jsx(Ol,{className:"layout",cols:{lg:12,md:10,sm:6,xs:4,xxs:2},draggableHandle:".draggable-head",rowHeight:30,onLayoutChange:o=>{n==null||n(o.map(i=>({id:parseInt(i.i.replace(".$",""),10),x:i.x,y:i.y,w:i.w,h:i.h})))},children:s})},{useToken:_l}=u.theme,{Text:Dl}=u.Typography,Pn=t=>{const{title:r,children:n,action:s,openAction:o}=t,{token:i}=_l();return e.jsxs("div",{className:"shadow-md",style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid #eee",backgroundColor:"white",borderRadius:i.borderRadius},children:[e.jsxs(u.Row,{align:"middle",style:{borderBottom:"1px solid #ddd",backgroundColor:i.colorPrimaryBg},wrap:!1,children:[e.jsx(u.Col,{flex:"auto",className:"draggable-head",style:{fontWeight:"bold",padding:"0.5rem",cursor:"grab",overflow:"hidden"},children:e.jsx(Dl,{ellipsis:!0,children:r})}),s&&e.jsx(u.Col,{flex:"25px",style:{padding:"0.5rem"},children:e.jsx(u.Row,{justify:"end",align:"middle",children:e.jsx(B.ExportOutlined,{style:{cursor:"pointer"},onClick:()=>{o==null||o(s)}})})})]}),n]})},Vl=80;function kl(t){const{action:r,model:n,view_id:s,onRowClicked:o,domain:i=[],visible:a=!0,parentContext:c={}}=t,[d,f]=l.useState(!1),[h,p]=l.useState(!1),[g,v]=l.useState(),[m,y]=l.useState(),[C,w]=l.useState(),[E,_]=l.useState(1),[S,I]=l.useState(0),D=l.useRef(Vl),N=l.useRef([]),[b,x]=l.useState(0),[O,T]=l.useState([]),[H,F]=l.useState(void 0),[A,k]=l.useState(),[L,V]=l.useState(),[M,K]=l.useState(),[q,z]=l.useState(!1),Y=l.useRef([]),Z=X=>{z(!0),_(X),I((X-1)*D.current)},J=async()=>{const X=Y.current.length>0?Y.current:i,ve=Ot(N.current,X),{colors:Ce}=rt(m),{totalItems:ke,results:fe,attrsEvaluated:oe}=await W.getHandler().searchForTree({params:ve,limit:D.current,offset:S,model:g,fields:m.fields,context:c,attrs:Ce&&{colors:Ce}}),be=await ke;x(be),F(Ft(oe));const ye=nt({resultsToSort:fe,sorter:A,fields:{...m.fields,...C.fields}});T(ye)},$=async()=>{try{z(!0),await J()}catch(X){V(JSON.stringify(X))}finally{z(!1)}};l.useEffect(()=>{!h||a&&$()},[E,S,h,a]);const P=async X=>{p(!1),f(!0),K(void 0);try{X==="action"?await ee():await le(),p(!0)}catch(ve){K(ve)}finally{f(!1)}},ee=async()=>{const X=await W.getHandler().getViewsForAction({action:r,context:c});Y.current=X.domain,w(X.views.get("form")),y(X.views.get("tree")),v(X.model),D.current=X.limit},le=async()=>{v(n);const X=await W.getHandler().getView({model:n,type:"form",context:c});w(X);const ve=await W.getHandler().getView({model:n,type:"tree",id:s,context:c});y(ve)};l.useEffect(()=>{r?P("action"):n&&P("model")},[r,n]);const ce=X=>{const{id:ve}=X;o({id:ve,model:g,treeView:m})},re=()=>!m||!C?null:e.jsxs("div",{style:{overflowY:"scroll"},children:[L&&e.jsx(u.Alert,{className:"mt-10",message:L,type:"error",banner:!0}),e.jsx(Ct,{showPagination:!1,total:b,limit:D.current,page:E,treeView:m,results:O,onRequestPageChange:Z,loading:q,onRowClicked:ce,colorsForResults:H,sorter:A,onChangeSort:X=>{k==null||k(X);const ve=nt({resultsToSort:O,sorter:X,fields:{...m.fields,...C.fields}});T(ve)},context:c})]});return M?e.jsx(u.Alert,{className:"mt-10",message:M,type:"error",banner:!0}):d?e.jsx(u.Spin,{style:{padding:"2rem"}}):re()}const El=t=>{const{model:r}=t,[n,s]=l.useState();l.useEffect(()=>{o()},[r]);async function o(){const i=await W.getHandler().search({params:[],model:r,limit:1});i.length>0&&s(i[0].id)}return e.jsx("div",{style:{padding:"0.5rem",overflowY:"scroll"},children:e.jsx(at,{...t,model:r,id:n,readOnly:!0})})},cr="line_ids";function Il(t,r){const{model:n,context:s={},id:o,configAction:i}=t,[a,c]=l.useState([]),[d,f]=l.useState(!1),[h,p]=l.useState(),{setIsLoading:g,openAction:v,moveItemsEnabled:m}=l.useContext(lr),y=l.useRef(),C=l.useRef();l.useEffect(()=>{w()},[n,o,s]),l.useImperativeHandle(r,()=>({refresh:()=>{w()},configDashboard:N}));async function w(){f(!0),g(!0),p(void 0);try{const b=await E(),x=await S(b),O=b.fields[cr].relation,T=x[cr].items;C.current=b.fields;const H=await _({items:T,model:O,context:s}),F=await I(H);c(F),f(!1),g(!1)}catch(b){p(JSON.stringify(b))}}async function E(){return await W.getHandler().getView({model:n,type:"form",context:s})}async function _({items:b,model:x,context:O}){y.current=(await W.getHandler().getView({model:x,type:"form",context:O})).fields;const[T]=await Ut({treeView:{fields:y.current},formView:{fields:y.current},model:x,items:b,context:O,currentView:"form"});return T}async function S(b){return(await W.getHandler().readObjects({model:n,ids:[o],fields:b.fields,context:s}))[0]}async function I(b){const x=[];for(const O of b){const{values:T}=O;if(T.action_id&&T.action_id.length>0){const H=parseInt(T.action_id[0],10),F=await Fl({actionId:H,rootContext:s});x.push({...O,actionData:F})}}return x}async function D(b){if(!m)return;const x=b.filter(F=>{const A=a.find(L=>L.id===F.id);if(!A)return!1;if(!A.position)return!0;const k={...JSON.parse(A.position.replace(/'/g,'"')),id:A.id};return JSON.stringify(F)!==JSON.stringify(k)});if(x.length===0)return;const T=a.filter(F=>x.map(A=>A.id).includes(F.id)).map(F=>{const A={...x.find(k=>k.id===F.id)};return delete A.id,{...F},{...F,operation:"pendingUpdate",values:{...F.values,position:JSON.stringify(A).replace(/"/g,"'")}}}),H={fields:y.current,items:T};await W.getHandler().update({model:n,id:o,values:{[cr]:H},fields:C.current,context:s})}async function N(){v(i)}return h?(console.log(h),e.jsx(u.Alert,{className:"mt-10 mb-20",message:h,type:"error",banner:!0})):d?e.jsx(B.LoadingOutlined,{}):e.jsx(Nn,{onPositionItemsChanged:D,children:a.map((b,x)=>{const{actionData:O,values:T}=b,{position:H,id:F}=T,{actionId:A,actionType:k,key:L,title:V,views:M,model:K,context:q,domain:z,initialView:Y,limit:Z}=O;let J={};try{J=JSON.parse(H.replace(/'/g,'"'))}catch{J={x:x*2,y:0,w:2,h:3}}let $=null;if((Y==null?void 0:Y.type)==="graph")$=e.jsx(It,{view_id:M.filter(le=>le[1]==="graph")[0][0],model:K,context:q,domain:z,limit:Z});else if((Y==null?void 0:Y.type)==="form")$=e.jsx(El,{model:K,actionDomain:z});else if((Y==null?void 0:Y.type)==="tree")$=e.jsx(kl,{model:K,domain:z,view_id:M.filter(le=>le[1]==="tree")[0][0],onRowClicked:le=>{const ce=M.find(re=>{const[,X]=re;return X==="form"});if(ce){const[re,X]=ce,{actionId:ve,actionType:Ce,title:ke,model:fe}=O,oe={action_id:ve,action_type:Ce,name:ke,res_id:le.id,res_model:fe,view_id:re,view_type:X};v(oe)}}});else if(Y!==void 0){const le=Y&&Array.isArray(Y.id)?{...Y,id:Y.id[0]}:Y;$=e.jsx(Ln,{action_id:A,action_type:k,tabKey:L,title:V,views:M,model:K,context:q,domain:z,setCanWeClose:()=>{},initialView:le,limit:Z})}let P;const ee=M.find(le=>{const[,ce]=le;return ce==="tree"});if(ee){const[le,ce]=ee,{actionId:re,actionType:X,title:ve,model:Ce}=O;P={action_id:re,action_type:X,name:ve,res_id:!1,res_model:Ce,view_id:le,view_type:ce}}return e.jsx(Pn,{id:F,title:V,parms:J,action:P,openAction:v,children:$},F)})})}const Bn=l.forwardRef(Il),Hn=t=>e.jsx(me,{...t,children:e.jsx(Ml,{...t})}),Ml=t=>{const{ooui:r,value:n}=t;if(!n)return null;const s=r.colors==="auto"?zt(n):r.colors[n];return e.jsx(u.Tag,{color:s,children:r.selectionValues.get(n)})},Kn=t=>{const{ooui:r}=t;return e.jsx(me,{type:"array",...t,children:e.jsx(Al,{ooui:r})})},Al=t=>{const{value:r,ooui:n,onChange:s}=t,{items:o=[]}=r||{},i=o.filter(b=>b.operation!=="pendingRemove").map(b=>b.id),[a,c]=l.useState([]),[d,f]=l.useState(),[h,p]=l.useState(!1),{relation:g,context:v,readOnly:m,field:y,columns:C}=n,w=l.useContext(_e),{getContext:E}=w||{};Qe.default(()=>{S()},[o]);const _=b=>{s==null||s({items:b})};async function S(){p(!0);let b=[];if(n.domain){const x=await W.getHandler().evalDomain({domain:n.domain,values:st({fields:w==null?void 0:w.getFields(),values:w.getPlainValues()}),fields:w==null?void 0:w.getFields(),context:w.getContext()});b=[...b,...x]}try{const O=(await W.getHandler().search({model:g,params:b,fields:[y],context:{...E==null?void 0:E(),...v}})).map(T=>{const H=T[y];let F=H;return Array.isArray(H)&&(F=H[1]),{label:F,value:T.id}});c(O)}catch(x){f(x)}finally{p(!1)}if(d)return e.jsx(u.Alert,{className:"mt-10",message:d,type:"error",banner:!0})}const I=()=>{N(a.map(b=>b.value))},D=()=>{N([])},N=b=>{const x=o.map(T=>b.includes(T.id)?T.operation=="pendingRemove"?{...T,operation:"original"}:T:{id:T.id,operation:"pendingRemove"}),O=x.map(T=>T.id);b.filter(T=>!O.includes(T)).map(T=>{x.push({id:T,operation:"pendingLink"})}),_(x)};return h&&a.length===0?e.jsx(u.Spin,{}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(u.Checkbox.Group,{value:a.length?i:[],disabled:m,onChange:N,style:{width:"100%"},children:e.jsx(u.Row,{children:a.map(b=>e.jsx(u.Col,{span:Math.floor(24/C),children:e.jsx(u.Checkbox,{value:b.value,children:b.label})}))})}),!m&&e.jsxs(u.Space,{children:[e.jsx(u.Button,{onClick:I,disabled:i.length==a.length,children:"Check all"}),e.jsx(u.Button,{onClick:D,disabled:i.length===0,children:"Uncheck all"})]})]})})},Wn=t=>e.jsx(me,{...t,children:e.jsx($l,{...t})}),$l=t=>{const{value:r,ooui:n}=t;return e.jsx("div",{style:{height:n.height?n.height+"px":"100%",overflow:"auto"},children:e.jsx(fo.default,{children:r,className:"ant-typography"})})},qn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(Ll,{...t})})},Ll=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,direction:a}=r,c=Array.from(o.entries()),d=c&&c.length&&c.map(f=>{const[h,p]=f;return e.jsx(u.Radio,{value:h,children:p},h)});return e.jsx(u.Radio.Group,{disabled:i,onChange:n,value:s,children:e.jsx(u.Space,{direction:a,children:d})})},Yn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o}=r;return e.jsx(me,{...t,valuePropName:"checked",children:e.jsx(Nl,{id:n,readOnly:s,required:o})})},Nl=t=>{const{required:r,readOnly:n,...s}=t;return e.jsx("div",{className:"flex flex-row",children:e.jsx(u.Switch,{disabled:n,...s})})},Gn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(Pl,{...t})})},Pl=t=>{const{ooui:r,value:n}=t,{selectionValues:s,errorField:o}=r,i=l.useContext(_e),a=Array.from(s.entries()),c=a.map(h=>h[0]).indexOf(n);let d="process",f="";return o&&(f=i.getFieldValue(o),f&&(d="error")),e.jsx(u.Steps,{current:c,status:d,children:a.map((h,p)=>e.jsx(u.Steps.Step,{title:h[1],description:p===c&&d==="error"?f:null}))})},Un=t=>{const{ooui:r}=t,{lang:n,height:s}=r,o=l.useContext(_e),{elementHasLostFocus:i}=o||{},a=c=>{c.onDidBlurEditorWidget(i)};return e.jsx(me,{...t,children:e.jsx(ho.default,{defaultLanguage:n||"",height:s||300,onMount:a})})},{Content:Bl}=u.Layout,{Title:Hl}=u.Typography;function Kl(){const{t}=l.useContext(ge);return e.jsx(Bl,{className:"m-5 select-none",children:e.jsx(Hl,{level:5,children:t("welcome")})})}function Wl(t,r){const{children:n,globalValues:s={},rootContext:o={},lang:i}=t,[a,c]=l.useState("welcome"),[d,f]=l.useState([{title:Se("welcome",i),key:"welcome",closable:!0,content:e.jsx(Kl,{})}]),h=l.useRef(new Map),p=l.useRef();l.useImperativeHandle(r,()=>({retrieveAndOpenAction:m,openShortcut:w}));function g(S){if(S===a){const I=d.findIndex(D=>D.key===S);d[I-1]&&c(d[I-1].key),d[I+1]&&c(d[I+1].key)}f(d.filter(I=>I.key!==S)),h.current.delete(S)}function v({tabKey:S,canWeClose:I}){h.current.set(S,I)}async function m({action:S,values:I,forced_values:D,initialViewType:N,res_id:b,domain:x=[]}){const O=await W.getHandler().getActionData({action:S,context:o});if(O.type==="ir.actions.wizard"){Me("Action type not supported");return}const[T,H]=S.split(","),F=parseInt(H),A=se.parseContext({context:O.context,values:s,fields:{}}),k=O.domain?await W.getHandler().evalDomain({domain:O.domain,values:s,context:{...o,...A}}):[],{res_model:L,views:V,name:M,target:K,view_type:q,limit:z}=O,Y=q==="tree",Z=[];for(const $ of V){const[P,ee]=$;if(P)Z.push($);else if(ee==="dashboard")Z.push([void 0,"dashboard"]);else{const{view_id:le}=await W.getHandler().getView({model:L,type:ee,id:P,context:{...o,...A}});Z.push([le,ee])}}let J;if(N){const[$,P]=Z.find(([ee,le])=>le===N);J={id:$,type:P}}else{const[$,P]=Z[0];J={id:$,type:P}}_({domain:[...k,...x],context:{...o,...A},model:L,views:Z,title:M,target:K,initialView:J,action_type:T,action_id:F,values:I,forced_values:D,res_id:b,treeExpandable:Y,limit:z})}function y({title:S,content:I,key:D,action:N}){let b=[...d];d.length===1&&d[0].key==="welcome"&&(b=[...d.filter(x=>x.key!=="welcome")]),f([...b,{title:S,key:D,closable:!0,content:I,action:N}]),c(D)}async function C({relateData:S,fields:I,values:D,action_id:N,action_type:b}){const{res_model:x,context:O,domain:T,views:H,target:F,string:A,limit:k}=S,[L,V]=H[0],M={id:L,type:V},K=se.parseContext({context:O,values:{...D,...s},fields:I}),q=T?await W.getHandler().evalDomain({domain:T,values:st({fields:I,values:{...D,...s}}),fields:I,context:{...o,...K}}):[];_({model:x,target:F,views:H,context:{...o,...K},domain:q,title:A,initialView:M,action_id:N,action_type:b,limit:k})}async function w(S){const{action_id:I,action_type:D,res_id:N,view_id:b}=S,x=`${D},${I}`,O=await W.getHandler().getActionData({action:x,context:o}),T=se.parseContext({context:O.context,values:s,fields:{}}),H=O.domain?await W.getHandler().evalDomain({domain:O.domain,values:s,context:{...o,...T}}):[],{res_model:F,views:A,name:k,target:L,view_type:V,limit:M}=O,K=V==="tree",q=[];for(const J of A){const[$,P]=J;if($)q.push(J);else if(P==="dashboard")q.push([void 0,"dashboard"]);else{const{view_id:ee}=await W.getHandler().getView({model:F,type:P,id:$,context:{...o,...T}});q.push([ee,P])}}let z,Y;if(b==null){const J=q.find($=>$[0]===void 0);z=void 0,Y=J[1]}else[z,Y]=q.find(J=>J[0]===void 0?!1:J[0]===b);const Z={id:z,type:Y};_({domain:H,context:{...o,...T},model:F,views:q,title:k,target:L,initialView:Z,action_id:I,action_type:D,res_id:N,treeExpandable:K,limit:M})}async function E({model:S,values:I,forced_values:D,initialViewType:N,res_id:b,domain:x}){const O=await W.getHandler().getActionStringForModel(S);await m({action:O,values:I,forced_values:D,initialViewType:N,res_id:b,domain:x})}async function _({domain:S,context:I,model:D,views:N,title:b,target:x,initialView:O,action_id:T,action_type:H,res_id:F,values:A,forced_values:k,treeExpandable:L=!1,limit:V}){const M=gr.v4();if(x!=="current"){const K=await W.getHandler().getView({model:D,type:"form",id:O.type==="form"?O.id:void 0,context:{...o,...I}});p.current.openActionModal({domain:S,model:D,formView:K,context:{...o,...I},actionData:{action_id:T,action_type:H,res_id:F,view_id:K.view_id}})}else{const K=O&&Array.isArray(O.id)?{...O,id:O.id[0]}:O;y({title:b,action:{id:T,type:H},content:e.jsx(Ln,{action_id:T,action_type:H,tabKey:M,title:b,views:N,model:D,context:{...o,...I},domain:S,setCanWeClose:v,initialView:K,res_id:F,formDefaultValues:A,formForcedValues:k,treeExpandable:L,limit:V}),key:M})}}return e.jsx(wo,{lang:i,children:e.jsx(Ti,{openShortcut:w,openAction:_,openRelate:C,openDefaultActionForModel:E,tabs:d,activeKey:a,onRemoveTab:async S=>{const I=h.current.get(S);(await(I==null?void 0:I())||a==="welcome")&&g(S)},onChangeTab:S=>{c(S)},children:e.jsx(Zr,{ref:p,globalValues:s,children:n})})})}const ql=l.forwardRef(Wl),{useToken:Yl}=u.theme;function Gl(t){const{label:r,onClose:n,tabKey:s,isActive:o,onSelected:i}=t,{token:a}=Yl(),c=o?a.colorBgContainer:a.colorPrimaryBg;return e.jsxs("div",{onClick:()=>{!o&&i(s)},style:{cursor:"pointer",height:40,paddingTop:7,paddingBottom:5,paddingLeft:10,paddingRight:10,backgroundColor:c,display:"inline-flex",flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center",borderTopLeftRadius:a.borderRadius,borderTopRightRadius:a.borderRadius,marginLeft:2},children:[e.jsx("div",{style:{color:o?a.colorPrimaryActive:a.colorPrimaryBorder,userSelect:"none",height:40,display:"flex",justifyContent:"center",alignItems:"center",paddingLeft:5,paddingRight:5,marginBottom:2},children:r}),e.jsx("div",{style:{paddingLeft:5,height:40,display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(B.CloseOutlined,{style:{color:o?a.colorPrimaryActive:a.colorPrimaryBorder},onClick:d=>{d.stopPropagation(),n(s)}})})]})}function Ul(){const t=l.useContext(Ye),{activeKey:r,tabs:n,onRemoveTab:s,onChangeTab:o}=t||{};return e.jsx(e.Fragment,{children:n.map(i=>e.jsx(Gl,{tabKey:i.key,label:i.title,onClose:s,isActive:r===i.key,onSelected:o},i.key))})}function jl(t){const{tab:r}=t,n=l.useContext(Ye),{activeKey:s}=n||{},o={display:"none"};return e.jsx("div",{style:r.key!==s?o:void 0,children:r.content})}const zl=Pe.default.memo(jl,()=>!0);function Jl(){const t=l.useContext(Ye),{tabs:r}=t||{},n=(r==null?void 0:r.map(s=>e.jsx(zl,{tab:s},s.key)))||null;return e.jsx(e.Fragment,{children:n})}const{useToken:Zl}=u.theme,Xl=t=>{const{onRetrieveShortcuts:r,onCheckIsFavourite:n,onAddFavourite:s,onRemoveFavourite:o}=t,[i,a]=l.useState(!1),[c,d]=l.useState(!1),[f,h]=l.useState([]),[p,g]=l.useState(!0),[v,m]=l.useState(),{t:y}=l.useContext(ge)||{},{token:C}=Zl(),w=l.useContext(Ye),{openShortcut:E,tabs:_,activeKey:S,currentView:I,currentId:D,openDefaultActionForModel:N}=w||{};l.useEffect(()=>{b()},[]),l.useEffect(()=>{T()},[_,S,I,D]);async function b(){try{g(!0);const L=await r();h(L)}catch(L){Me(L)}finally{g(!1)}}function x(L){const{key:V}=L,M=f.find(K=>K.id===Number(V));(M==null?void 0:M.action_type)!=="ir.actions.wizard"&&(M&&E(M),d(!1))}function O(L){L&&b(),d(L)}async function T(){if(!I)return;const L=_.find(Y=>Y.key===S),{id:V,type:M}=(L==null?void 0:L.action)||{};if(!V||!M){a(!1);return}const K=I.view_id;let q=!1;I.type==="form"&&(q=D||!1);const z=await n({action_id:V,action_type:M,view_id:K,res_id:q});z!==!1&&m(z),a(z!==!1)}async function H(){d(!1),N==null||N({model:"ir.ui.view_sc"})}const F=e.jsxs(u.Menu,{onClick:x,children:[e.jsxs("div",{style:{width:300,padding:5,display:"flex"},children:[e.jsx("div",{style:{paddingLeft:15,color:"#ccc"},children:y==null?void 0:y("favorites").toUpperCase()}),e.jsx("div",{style:{flexGrow:1,paddingLeft:10},children:e.jsx(u.Tooltip,{title:y==null?void 0:y("edit_favorites"),children:e.jsx(B.EditOutlined,{style:{color:C.colorPrimary,cursor:"pointer"},onClick:H})})})]}),e.jsx(u.Menu.Divider,{}),p?e.jsx(u.Spin,{style:{padding:"1rem"}}):f.length>0?e.jsx(e.Fragment,{children:f.map(L=>e.jsx(u.Menu.Item,{children:e.jsx(A,{title:L.name,type:L.view_type})},L.id))}):e.jsx("div",{style:{width:300,padding:5,paddingLeft:15},children:y==null?void 0:y("no_favorites")})]});function A({title:L,type:V}){const M=V==="tree"?e.jsx(B.TableOutlined,{}):e.jsx(B.FormOutlined,{});return e.jsxs(u.Row,{wrap:!1,children:[e.jsx(u.Col,{flex:"none",style:{paddingRight:20},children:M}),e.jsx(u.Col,{flex:"auto",children:L})]})}async function k(){if(i&&v)await o(v);else{if(!I)return;const L=_.find(z=>z.key===S),{id:V,type:M}=(L==null?void 0:L.action)||{},K=I.view_id;let q=!1;if(!V||!M){a(!1);return}I.type==="form"&&(q=D||!1),await s({action_id:V,action_type:M,view_id:K,res_id:q})}await b(),a(!i)}return e.jsxs(e.Fragment,{children:[e.jsx(u.Button,{type:i?"primary":"default",icon:i?e.jsx(B.StarFilled,{style:{color:"white"}}):e.jsx(B.StarOutlined,{}),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:k}),e.jsx(u.Dropdown,{overlay:F,onVisibleChange:O,open:c,children:e.jsx(u.Button,{style:{width:25,borderTopLeftRadius:0,borderBottomLeftRadius:0},icon:e.jsx(B.DownOutlined,{style:{fontSize:"0.5em"}}),onClick:L=>L.preventDefault()})})]})};G.ActionBar=kn,G.Binary=On,G.Boolean=Dr,G.Button=Wt,G.ButtonGroup=Sr,G.Char=qt,G.CodeEditor=Un,G.ConfigContext=$n,G.ConnectionProvider=W,G.ContentRootProvider=Zr,G.CurrentTabContent=Jl,G.Dashboard=Bn,G.DashboardGrid=Nn,G.DashboardGridItem=Pn,G.Date=xn,G.DateTime=Tn,G.Email=Mn,G.ExportModal=Sn,G.FavouriteButton=Xl,G.Float=Zt,G.FloatTime=mn,G.Form=at,G.FormModal=lt,G.GraphIndicator=fn,G.Group=rr,G.Image=Hr,G.Integer=wt,G.Label=pt,G.Many2one=ln,G.Markdown=Wn,G.MultiCheckbox=Kn,G.Notebook=yn,G.One2many=gn,G.ProgressBar=Rr,G.Radio=qn,G.Reference=Fn,G.RootView=ql,G.SearchFilter=Xt,G.SearchModal=er,G.SearchTree=Rt,G.Selection=Yt,G.Separator=wn,G.Steps=Gn,G.Switch=Yn,G.TabSelector=Ul,G.Tag=Hn,G.Tags=Yr,G.Text=vn,G.Tree=Ct,G.Url=In,G.iconMapper=qe,G.showConfirmDialog=et,Object.defineProperties(G,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
36
+ Please, make sure the view ids on the fields_view_get responses are the same as the ones defined in the action`),fe==null||fe(d)),be(ae),S(R),D(!1)};c({tabKey:d,canWeClose:xe}),l.useEffect(()=>{const R=_.find(he=>he.type==="tree"),ae=_.find(he=>f.id?he.type===f.type&&he.view_id===f.id:he.type===f.type);be(ae||R),g?X==null||X(N):(oe(void 0),F(void 0)),ye()},[s,i,g]),l.useEffect(()=>{Ce===d&&(X==null||X(b),re==null||re(w))},[ve,Ce]);async function xe(){return w&&w.type==="form"?await ee.current.cancelUnsavedChanges():!0}async function Ee(){Ce===d&&(w.type==="form"&&!await ee.current.cancelUnsavedChanges()||z(!0))}async function Ve(R){var ue;Z(!0);const ae=A.findIndex(Ae=>Ae.id===R);let he;if(ae===-1){try{he=(ue=await W.getHandler().readObjects({model:s,ids:[R],context:o}))==null?void 0:ue[0]}catch{}if(!he){Z(!1),z(!1),ze(P("idNotFound"));return}}else he=A[ae];Z(!1),z(!1);const Oe=i.find(Ae=>Ae[1]==="form");ke({domain:[],context:o,model:s,views:i,title:a,target:"current",initialView:{id:Oe==null?void 0:Oe[0],type:"form"},action_id:v,action_type:m,res_id:R})}function He(){return _.map(R=>{switch(R.type){case"form":return e.jsx(ml,{formRef:ee,currentId:b,visible:w.type===R.type&&w.view_id===R.view_id,formView:R,model:s,context:o,domain:n,defaultValues:h,forcedValues:p,results:A,setResults:k,setCurrentItemIndex:F},`${R.type}-${R.view_id}`);case"tree":return e.jsx(wl,{visible:w.type===R.type&&w.view_id===R.view_id,limit:C,model:s,context:o,domain:n,formView:_.find(ae=>ae.type==="form"),treeView:R,searchTreeRef:le,searchTreeNameSearch:J,availableViews:_,results:A,setCurrentItemIndex:F,setCurrentId:oe,setCurrentView:be},`${R.type}-${R.view_id}`);case"graph":return e.jsx(gl,{visible:w.type===R.type&&w.view_id===R.view_id,viewData:R,model:s,context:o,domain:n,treeView:_.find(ae=>ae.type==="tree"),formView:_.find(ae=>ae.type==="form")},`${R.type}-${R.view_id}`);case"dashboard":return e.jsx(xl,{dashboardData:R},`${R.type}-${R.view_id}`)}})}function Ie(){if(b===void 0&&w.type==="form")ee.current.clearAndReload();else{oe(void 0);const R=_.find(ae=>ae.type==="form");be(R)}}return I?e.jsx(u.Spin,{}):w?e.jsxs(xi,{title:a,currentView:w,setCurrentView:be,availableViews:_,formRef:ee,searchTreeRef:le,onNewClicked:Ie,currentId:b,setCurrentId:oe,setCurrentItemIndex:F,currentItemIndex:H,results:A,setResults:k,currentModel:s,sorter:L,setSorter:V,totalItems:M,setTotalItems:K,selectedRowItems:O,setSelectedRowItems:T,setSearchTreeNameSearch:$,searchTreeNameSearch:J,goToResourceId:Ve,limit:C,children:[He(),e.jsx(dl,{visible:q,onIdSubmitted:Ve,isSearching:Y,onCancel:()=>{z(!1)}})]}):null}const Ln=l.forwardRef(Tl);async function Fl({actionId:t,rootContext:r={},globalValues:n={}}){const s="ir.actions.act_window",o=`${s},${t}`,i=await W.getHandler().getActionData({action:o,context:r}),a=se.parseContext({context:i.context,values:n,fields:{}}),c=i.domain?await W.getHandler().evalDomain({domain:i.domain,values:n,context:{...r,...a}}):[],{res_model:d,views:f,name:h,limit:p,view_type:g}=i,v=g==="tree",m=[];for(const E of f){const[_,S]=E;if(_)m.push(E);else{const{view_id:I}=await W.getHandler().getView({model:d,type:S,id:_,context:{...r,...a}});m.push([I,S])}}const[y,C]=m[0],w={id:y,type:C};return{title:h,actionId:t,actionType:s,key:gr.v4(),views:f,model:d,context:{...r,...a},domain:c,initialView:w,limit:p,treeExpandable:v}}const vc="",Ol=pr.WidthProvider(pr.Responsive),Nn=t=>{const{children:r=[],onPositionItemsChanged:n}=t,s=Pe.default.Children.map(r,o=>{const{parms:i,id:a}=o.props;return e.jsx("div",{"data-grid":i,children:o},a)});return e.jsx(Ol,{className:"layout",cols:{lg:12,md:10,sm:6,xs:4,xxs:2},draggableHandle:".draggable-head",rowHeight:30,onLayoutChange:o=>{n==null||n(o.map(i=>({id:parseInt(i.i.replace(".$",""),10),x:i.x,y:i.y,w:i.w,h:i.h})))},children:s})},{useToken:_l}=u.theme,{Text:Dl}=u.Typography,Pn=t=>{const{title:r,children:n,action:s,openAction:o}=t,{token:i}=_l();return e.jsxs("div",{className:"shadow-md",style:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid #eee",backgroundColor:"white",borderRadius:i.borderRadius},children:[e.jsxs(u.Row,{align:"middle",style:{borderBottom:"1px solid #ddd",backgroundColor:i.colorPrimaryBg},wrap:!1,children:[e.jsx(u.Col,{flex:"auto",className:"draggable-head",style:{fontWeight:"bold",padding:"0.5rem",cursor:"grab",overflow:"hidden"},children:e.jsx(Dl,{ellipsis:!0,children:r})}),s&&e.jsx(u.Col,{flex:"25px",style:{padding:"0.5rem"},children:e.jsx(u.Row,{justify:"end",align:"middle",children:e.jsx(B.ExportOutlined,{style:{cursor:"pointer"},onClick:()=>{o==null||o(s)}})})})]}),n]})},Vl=80;function kl(t){const{action:r,model:n,view_id:s,onRowClicked:o,domain:i=[],visible:a=!0,parentContext:c={}}=t,[d,f]=l.useState(!1),[h,p]=l.useState(!1),[g,v]=l.useState(),[m,y]=l.useState(),[C,w]=l.useState(),[E,_]=l.useState(1),[S,I]=l.useState(0),D=l.useRef(Vl),N=l.useRef([]),[b,x]=l.useState(0),[O,T]=l.useState([]),[H,F]=l.useState(void 0),[A,k]=l.useState(),[L,V]=l.useState(),[M,K]=l.useState(),[q,z]=l.useState(!1),Y=l.useRef([]),Z=X=>{z(!0),_(X),I((X-1)*D.current)},J=async()=>{const X=Y.current.length>0?Y.current:i,ve=Ot(N.current,X),{colors:Ce}=rt(m),{totalItems:ke,results:fe,attrsEvaluated:oe}=await W.getHandler().searchForTree({params:ve,limit:D.current,offset:S,model:g,fields:m.fields,context:c,attrs:Ce&&{colors:Ce}}),be=await ke;x(be),F(Ft(oe));const ye=nt({resultsToSort:fe,sorter:A,fields:{...m.fields,...C.fields}});T(ye)},$=async()=>{try{z(!0),await J()}catch(X){V(JSON.stringify(X))}finally{z(!1)}};l.useEffect(()=>{!h||a&&$()},[E,S,h,a]);const P=async X=>{p(!1),f(!0),K(void 0);try{X==="action"?await ee():await le(),p(!0)}catch(ve){K(ve)}finally{f(!1)}},ee=async()=>{const X=await W.getHandler().getViewsForAction({action:r,context:c});Y.current=X.domain,w(X.views.get("form")),y(X.views.get("tree")),v(X.model),D.current=X.limit},le=async()=>{v(n);const X=await W.getHandler().getView({model:n,type:"form",context:c});w(X);const ve=await W.getHandler().getView({model:n,type:"tree",id:s,context:c});y(ve)};l.useEffect(()=>{r?P("action"):n&&P("model")},[r,n]);const ce=X=>{const{id:ve}=X;o({id:ve,model:g,treeView:m})},re=()=>!m||!C?null:e.jsxs("div",{style:{overflowY:"scroll"},children:[L&&e.jsx(u.Alert,{className:"mt-10",message:L,type:"error",banner:!0}),e.jsx(Ct,{showPagination:!1,total:b,limit:D.current,page:E,treeView:m,results:O,onRequestPageChange:Z,loading:q,onRowClicked:ce,colorsForResults:H,sorter:A,onChangeSort:X=>{k==null||k(X);const ve=nt({resultsToSort:O,sorter:X,fields:{...m.fields,...C.fields}});T(ve)},context:c})]});return M?e.jsx(u.Alert,{className:"mt-10",message:M,type:"error",banner:!0}):d?e.jsx(u.Spin,{style:{padding:"2rem"}}):re()}const El=t=>{const{model:r}=t,[n,s]=l.useState();l.useEffect(()=>{o()},[r]);async function o(){const i=await W.getHandler().search({params:[],model:r,limit:1});i.length>0&&s(i[0].id)}return e.jsx("div",{style:{padding:"0.5rem",overflowY:"scroll"},children:e.jsx(at,{...t,model:r,id:n,readOnly:!0})})},cr="line_ids";function Il(t,r){const{model:n,context:s={},id:o,configAction:i}=t,[a,c]=l.useState([]),[d,f]=l.useState(!1),[h,p]=l.useState(),{setIsLoading:g,openAction:v,moveItemsEnabled:m}=l.useContext(lr),y=l.useRef(),C=l.useRef();l.useEffect(()=>{w()},[n,o,s]),l.useImperativeHandle(r,()=>({refresh:()=>{w()},configDashboard:N}));async function w(){f(!0),g(!0),p(void 0);try{const b=await E(),x=await S(b),O=b.fields[cr].relation,T=x[cr].items;C.current=b.fields;const H=await _({items:T,model:O,context:s}),F=await I(H);c(F),f(!1),g(!1)}catch(b){p(JSON.stringify(b))}}async function E(){return await W.getHandler().getView({model:n,type:"form",context:s})}async function _({items:b,model:x,context:O}){y.current=(await W.getHandler().getView({model:x,type:"form",context:O})).fields;const[T]=await Ut({treeView:{fields:y.current},formView:{fields:y.current},model:x,items:b,context:O,currentView:"form"});return T}async function S(b){return(await W.getHandler().readObjects({model:n,ids:[o],fields:b.fields,context:s}))[0]}async function I(b){const x=[];for(const O of b){const{values:T}=O;if(T.action_id&&T.action_id.length>0){const H=parseInt(T.action_id[0],10),F=await Fl({actionId:H,rootContext:s});x.push({...O,actionData:F})}}return x}async function D(b){if(!m)return;const x=b.filter(F=>{const A=a.find(L=>L.id===F.id);if(!A)return!1;if(!A.position)return!0;const k={...JSON.parse(A.position.replace(/'/g,'"')),id:A.id};return JSON.stringify(F)!==JSON.stringify(k)});if(x.length===0)return;const T=a.filter(F=>x.map(A=>A.id).includes(F.id)).map(F=>{const A={...x.find(k=>k.id===F.id)};return delete A.id,{...F},{...F,operation:"pendingUpdate",values:{...F.values,position:JSON.stringify(A).replace(/"/g,"'")}}}),H={fields:y.current,items:T};await W.getHandler().update({model:n,id:o,values:{[cr]:H},fields:C.current,context:s})}async function N(){v(i)}return h?(console.log(h),e.jsx(u.Alert,{className:"mt-10 mb-20",message:h,type:"error",banner:!0})):d?e.jsx(B.LoadingOutlined,{}):e.jsx(Nn,{onPositionItemsChanged:D,children:a.map((b,x)=>{const{actionData:O,values:T}=b,{position:H,id:F}=T,{actionId:A,actionType:k,key:L,title:V,views:M,model:K,context:q,domain:z,initialView:Y,limit:Z}=O;let J={};try{J=JSON.parse(H.replace(/'/g,'"'))}catch{J={x:x*2,y:0,w:2,h:3}}let $=null;if((Y==null?void 0:Y.type)==="graph")$=e.jsx(It,{view_id:M.filter(le=>le[1]==="graph")[0][0],model:K,context:q,domain:z,limit:Z});else if((Y==null?void 0:Y.type)==="form")$=e.jsx(El,{model:K,actionDomain:z});else if((Y==null?void 0:Y.type)==="tree")$=e.jsx(kl,{model:K,domain:z,view_id:M.filter(le=>le[1]==="tree")[0][0],onRowClicked:le=>{const ce=M.find(re=>{const[,X]=re;return X==="form"});if(ce){const[re,X]=ce,{actionId:ve,actionType:Ce,title:ke,model:fe}=O,oe={action_id:ve,action_type:Ce,name:ke,res_id:le.id,res_model:fe,view_id:re,view_type:X};v(oe)}}});else if(Y!==void 0){const le=Y&&Array.isArray(Y.id)?{...Y,id:Y.id[0]}:Y;$=e.jsx(Ln,{action_id:A,action_type:k,tabKey:L,title:V,views:M,model:K,context:q,domain:z,setCanWeClose:()=>{},initialView:le,limit:Z})}let P;const ee=M.find(le=>{const[,ce]=le;return ce==="tree"});if(ee){const[le,ce]=ee,{actionId:re,actionType:X,title:ve,model:Ce}=O;P={action_id:re,action_type:X,name:ve,res_id:!1,res_model:Ce,view_id:le,view_type:ce}}return e.jsx(Pn,{id:F,title:V,parms:J,action:P,openAction:v,children:$},F)})})}const Bn=l.forwardRef(Il),Hn=t=>e.jsx(me,{...t,children:e.jsx(Ml,{...t})}),Ml=t=>{const{ooui:r,value:n}=t;if(!n)return null;const s=r.colors==="auto"?zt(n):r.colors[n];return e.jsx(u.Tag,{color:s,children:r.selectionValues.get(n)})},Kn=t=>{const{ooui:r}=t;return e.jsx(me,{type:"array",...t,children:e.jsx(Al,{ooui:r})})},Al=t=>{const{value:r,ooui:n,onChange:s}=t,{items:o=[]}=r||{},i=o.filter(b=>b.operation!=="pendingRemove").map(b=>b.id),[a,c]=l.useState([]),[d,f]=l.useState(),[h,p]=l.useState(!1),{relation:g,context:v,readOnly:m,field:y,columns:C}=n,w=l.useContext(_e),{getContext:E}=w||{};Qe.default(()=>{S()},[o]);const _=b=>{s==null||s({items:b})};async function S(){p(!0);let b=[];if(n.domain){const x=await W.getHandler().evalDomain({domain:n.domain,values:st({fields:w==null?void 0:w.getFields(),values:w.getPlainValues()}),fields:w==null?void 0:w.getFields(),context:w.getContext()});b=[...b,...x]}try{const O=(await W.getHandler().search({model:g,params:b,fields:[y],context:{...E==null?void 0:E(),...v}})).map(T=>{const H=T[y];let F=H;return Array.isArray(H)&&(F=H[1]),{label:F,value:T.id}});c(O)}catch(x){f(x)}finally{p(!1)}if(d)return e.jsx(u.Alert,{className:"mt-10",message:d,type:"error",banner:!0})}const I=()=>{N(a.map(b=>b.value))},D=()=>{N([])},N=b=>{const x=o.map(T=>b.includes(T.id)?T.operation=="pendingRemove"?{...T,operation:"original"}:T:{id:T.id,operation:"pendingRemove"}),O=x.map(T=>T.id);b.filter(T=>!O.includes(T)).map(T=>{x.push({id:T,operation:"pendingLink"})}),_(x)};return h&&a.length===0?e.jsx(u.Spin,{}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-row",children:[e.jsx(u.Checkbox.Group,{value:a.length?i:[],disabled:m,onChange:N,style:{width:"100%"},children:e.jsx(u.Row,{children:a.map(b=>e.jsx(u.Col,{span:Math.floor(24/C),children:e.jsx(u.Checkbox,{value:b.value,children:b.label})}))})}),!m&&e.jsxs(u.Space,{children:[e.jsx(u.Button,{onClick:I,disabled:i.length==a.length,children:"Check all"}),e.jsx(u.Button,{onClick:D,disabled:i.length===0,children:"Uncheck all"})]})]})})},Wn=t=>e.jsx(me,{...t,children:e.jsx($l,{...t})}),$l=t=>{const{value:r,ooui:n}=t;return e.jsx("div",{style:{height:n.height?n.height+"px":"100%",overflow:"auto"},children:e.jsx(fo.default,{children:r,className:"ant-typography"})})},qn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(Ll,{...t})})},Ll=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,direction:a}=r,c=Array.from(o.entries()),d=c&&c.length&&c.map(f=>{const[h,p]=f;return e.jsx(u.Radio,{value:h,children:p},h)});return e.jsx(u.Radio.Group,{disabled:i,onChange:n,value:s,children:e.jsx(u.Space,{direction:a,children:d})})},Yn=t=>{const{ooui:r}=t,{id:n,readOnly:s,required:o}=r;return e.jsx(me,{...t,valuePropName:"checked",children:e.jsx(Nl,{id:n,readOnly:s,required:o})})},Nl=t=>{const{required:r,readOnly:n,...s}=t;return e.jsx("div",{className:"flex flex-row",children:e.jsx(u.Switch,{disabled:n,...s})})},Gn=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(me,{required:n,type:"any",...t,children:e.jsx(Pl,{...t})})},Pl=t=>{const{ooui:r,value:n}=t,{selectionValues:s,errorField:o}=r,i=l.useContext(_e),a=Array.from(s.entries()),c=a.map(h=>h[0]).indexOf(n);let d="process",f="";return o&&(f=i.getFieldValue(o),f&&(d="error")),e.jsx(u.Steps,{current:c,status:d,children:a.map((h,p)=>e.jsx(u.Steps.Step,{title:h[1],description:p===c&&d==="error"?f:null}))})},Un=t=>{const{ooui:r}=t,{lang:n,height:s}=r,o=l.useContext(_e),{elementHasLostFocus:i}=o||{},a=c=>{c.onDidBlurEditorWidget(i)};return e.jsx(me,{...t,children:e.jsx(ho.default,{defaultLanguage:n||"",height:s||300,onMount:a})})},{Content:Bl}=u.Layout,{Title:Hl}=u.Typography;function Kl(){const{t}=l.useContext(ge);return e.jsx(Bl,{className:"m-5 select-none",children:e.jsx(Hl,{level:5,children:t("welcome")})})}function Wl(t,r){const{children:n,globalValues:s={},rootContext:o={},lang:i}=t,[a,c]=l.useState("welcome"),[d,f]=l.useState([{title:Se("welcome",i),key:"welcome",closable:!0,content:e.jsx(Kl,{})}]),h=l.useRef(new Map),p=l.useRef();l.useImperativeHandle(r,()=>({retrieveAndOpenAction:m,openShortcut:w}));function g(S){if(S===a){const I=d.findIndex(D=>D.key===S);d[I-1]&&c(d[I-1].key),d[I+1]&&c(d[I+1].key)}f(d.filter(I=>I.key!==S)),h.current.delete(S)}function v({tabKey:S,canWeClose:I}){h.current.set(S,I)}async function m({action:S,values:I,forced_values:D,initialViewType:N,res_id:b,domain:x=[]}){const O=await W.getHandler().getActionData({action:S,context:o});if(O.type==="ir.actions.wizard"){Me("Action type not supported");return}const[T,H]=S.split(","),F=parseInt(H),A=se.parseContext({context:O.context,values:s,fields:{}}),k=O.domain?await W.getHandler().evalDomain({domain:O.domain,values:s,context:{...o,...A}}):[],{res_model:L,views:V,name:M,target:K,view_type:q,limit:z}=O,Y=q==="tree",Z=[];for(const $ of V){const[P,ee]=$;if(P)Z.push($);else if(ee==="dashboard")Z.push([void 0,"dashboard"]);else{const{view_id:le}=await W.getHandler().getView({model:L,type:ee,id:P,context:{...o,...A}});Z.push([le,ee])}}let J;if(N){const[$,P]=Z.find(([ee,le])=>le===N);J={id:$,type:P}}else{const[$,P]=Z[0];J={id:$,type:P}}_({domain:[...k,...x],context:{...o,...A},model:L,views:Z,title:M,target:K,initialView:J,action_type:T,action_id:F,values:I,forced_values:D,res_id:b,treeExpandable:Y,limit:z})}function y({title:S,content:I,key:D,action:N}){let b=[...d];d.length===1&&d[0].key==="welcome"&&(b=[...d.filter(x=>x.key!=="welcome")]),f([...b,{title:S,key:D,closable:!0,content:I,action:N}]),c(D)}async function C({relateData:S,fields:I,values:D,action_id:N,action_type:b}){const{res_model:x,context:O,domain:T,views:H,target:F,string:A,limit:k}=S,[L,V]=H[0],M={id:L,type:V},K=se.parseContext({context:O,values:{...D,...s},fields:I}),q=T?await W.getHandler().evalDomain({domain:T,values:st({fields:I,values:{...D,...s}}),fields:I,context:{...o,...K}}):[];_({model:x,target:F,views:H,context:{...o,...K},domain:q,title:A,initialView:M,action_id:N,action_type:b,limit:k})}async function w(S){const{action_id:I,action_type:D,res_id:N,view_id:b}=S,x=`${D},${I}`,O=await W.getHandler().getActionData({action:x,context:o}),T=se.parseContext({context:O.context,values:s,fields:{}}),H=O.domain?await W.getHandler().evalDomain({domain:O.domain,values:s,context:{...o,...T}}):[],{res_model:F,views:A,name:k,target:L,view_type:V,limit:M}=O,K=V==="tree",q=[];for(const J of A){const[$,P]=J;if($)q.push(J);else if(P==="dashboard")q.push([void 0,"dashboard"]);else{const{view_id:ee}=await W.getHandler().getView({model:F,type:P,id:$,context:{...o,...T}});q.push([ee,P])}}let z,Y;if(b==null){const J=q.find($=>$[0]===void 0);z=void 0,Y=J[1]}else[z,Y]=q.find(J=>J[0]===void 0?!1:J[0]===b);const Z={id:z,type:Y};_({domain:H,context:{...o,...T},model:F,views:q,title:k,target:L,initialView:Z,action_id:I,action_type:D,res_id:N,treeExpandable:K,limit:M})}async function E({model:S,values:I,forced_values:D,initialViewType:N,res_id:b,domain:x}){const O=await W.getHandler().getActionStringForModel(S);await m({action:O,values:I,forced_values:D,initialViewType:N,res_id:b,domain:x})}async function _({domain:S,context:I,model:D,views:N,title:b,target:x,initialView:O,action_id:T,action_type:H,res_id:F,values:A,forced_values:k,treeExpandable:L=!1,limit:V}){const M=gr.v4();if(x!=="current"){const K=await W.getHandler().getView({model:D,type:"form",id:O.type==="form"?O.id:void 0,context:{...o,...I}});p.current.openActionModal({domain:S,model:D,formView:K,context:{...o,...I},actionData:{action_id:T,action_type:H,res_id:F,view_id:K.view_id}})}else{const K=O&&Array.isArray(O.id)?{...O,id:O.id[0]}:O;y({title:b,action:{id:T,type:H},content:e.jsx(Ln,{action_id:T,action_type:H,tabKey:M,title:b,views:N,model:D,context:{...o,...I},domain:S,setCanWeClose:v,initialView:K,res_id:F,formDefaultValues:A,formForcedValues:k,treeExpandable:L,limit:V}),key:M})}}return e.jsx(wo,{lang:i,children:e.jsx(Ti,{openShortcut:w,openAction:_,openRelate:C,openDefaultActionForModel:E,tabs:d,activeKey:a,onRemoveTab:async S=>{const I=h.current.get(S);(await(I==null?void 0:I())||a==="welcome")&&g(S)},onChangeTab:S=>{c(S)},children:e.jsx(Zr,{ref:p,globalValues:s,children:n})})})}const ql=l.forwardRef(Wl),{useToken:Yl}=u.theme;function Gl(t){const{label:r,onClose:n,tabKey:s,isActive:o,onSelected:i}=t,{token:a}=Yl(),c=o?a.colorBgContainer:a.colorPrimaryBg;return e.jsxs("div",{onClick:()=>{!o&&i(s)},style:{cursor:"pointer",height:40,paddingTop:7,paddingBottom:5,paddingLeft:10,paddingRight:10,backgroundColor:c,display:"inline-flex",flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center",borderTopLeftRadius:a.borderRadius,borderTopRightRadius:a.borderRadius,marginLeft:2},children:[e.jsx("div",{style:{color:a.colorPrimaryActive,userSelect:"none",height:40,display:"flex",justifyContent:"center",alignItems:"center",paddingLeft:5,paddingRight:5,marginBottom:2,fontWeight:o?500:"normal"},children:r}),e.jsx("div",{style:{paddingLeft:5,height:40,display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(B.CloseOutlined,{style:{color:a.colorPrimaryActive},onClick:d=>{d.stopPropagation(),n(s)}})})]})}function Ul(){const t=l.useContext(Ye),{activeKey:r,tabs:n,onRemoveTab:s,onChangeTab:o}=t||{};return e.jsx(e.Fragment,{children:n.map(i=>e.jsx(Gl,{tabKey:i.key,label:i.title,onClose:s,isActive:r===i.key,onSelected:o},i.key))})}function jl(t){const{tab:r}=t,n=l.useContext(Ye),{activeKey:s}=n||{},o={display:"none"};return e.jsx("div",{style:r.key!==s?o:void 0,children:r.content})}const zl=Pe.default.memo(jl,()=>!0);function Jl(){const t=l.useContext(Ye),{tabs:r}=t||{},n=(r==null?void 0:r.map(s=>e.jsx(zl,{tab:s},s.key)))||null;return e.jsx(e.Fragment,{children:n})}const{useToken:Zl}=u.theme,Xl=t=>{const{onRetrieveShortcuts:r,onCheckIsFavourite:n,onAddFavourite:s,onRemoveFavourite:o}=t,[i,a]=l.useState(!1),[c,d]=l.useState(!1),[f,h]=l.useState([]),[p,g]=l.useState(!0),[v,m]=l.useState(),{t:y}=l.useContext(ge)||{},{token:C}=Zl(),w=l.useContext(Ye),{openShortcut:E,tabs:_,activeKey:S,currentView:I,currentId:D,openDefaultActionForModel:N}=w||{};l.useEffect(()=>{b()},[]),l.useEffect(()=>{T()},[_,S,I,D]);async function b(){try{g(!0);const L=await r();h(L)}catch(L){Me(L)}finally{g(!1)}}function x(L){const{key:V}=L,M=f.find(K=>K.id===Number(V));(M==null?void 0:M.action_type)!=="ir.actions.wizard"&&(M&&E(M),d(!1))}function O(L){L&&b(),d(L)}async function T(){if(!I)return;const L=_.find(Y=>Y.key===S),{id:V,type:M}=(L==null?void 0:L.action)||{};if(!V||!M){a(!1);return}const K=I.view_id;let q=!1;I.type==="form"&&(q=D||!1);const z=await n({action_id:V,action_type:M,view_id:K,res_id:q});z!==!1&&m(z),a(z!==!1)}async function H(){d(!1),N==null||N({model:"ir.ui.view_sc"})}const F=e.jsxs(u.Menu,{onClick:x,children:[e.jsxs("div",{style:{width:300,padding:5,display:"flex"},children:[e.jsx("div",{style:{paddingLeft:15,color:"#ccc"},children:y==null?void 0:y("favorites").toUpperCase()}),e.jsx("div",{style:{flexGrow:1,paddingLeft:10},children:e.jsx(u.Tooltip,{title:y==null?void 0:y("edit_favorites"),children:e.jsx(B.EditOutlined,{style:{color:C.colorPrimary,cursor:"pointer"},onClick:H})})})]}),e.jsx(u.Menu.Divider,{}),p?e.jsx(u.Spin,{style:{padding:"1rem"}}):f.length>0?e.jsx(e.Fragment,{children:f.map(L=>e.jsx(u.Menu.Item,{children:e.jsx(A,{title:L.name,type:L.view_type})},L.id))}):e.jsx("div",{style:{width:300,padding:5,paddingLeft:15},children:y==null?void 0:y("no_favorites")})]});function A({title:L,type:V}){const M=V==="tree"?e.jsx(B.TableOutlined,{}):e.jsx(B.FormOutlined,{});return e.jsxs(u.Row,{wrap:!1,children:[e.jsx(u.Col,{flex:"none",style:{paddingRight:20},children:M}),e.jsx(u.Col,{flex:"auto",children:L})]})}async function k(){if(i&&v)await o(v);else{if(!I)return;const L=_.find(z=>z.key===S),{id:V,type:M}=(L==null?void 0:L.action)||{},K=I.view_id;let q=!1;if(!V||!M){a(!1);return}I.type==="form"&&(q=D||!1),await s({action_id:V,action_type:M,view_id:K,res_id:q})}await b(),a(!i)}return e.jsxs(e.Fragment,{children:[e.jsx(u.Button,{type:i?"primary":"default",icon:i?e.jsx(B.StarFilled,{style:{color:"white"}}):e.jsx(B.StarOutlined,{}),style:{width:50,borderTopRightRadius:0,borderBottomRightRadius:0},onClick:k}),e.jsx(u.Dropdown,{overlay:F,onVisibleChange:O,open:c,children:e.jsx(u.Button,{style:{width:25,borderTopLeftRadius:0,borderBottomLeftRadius:0},icon:e.jsx(B.DownOutlined,{style:{fontSize:"0.5em"}}),onClick:L=>L.preventDefault()})})]})};G.ActionBar=kn,G.Binary=On,G.Boolean=Dr,G.Button=Wt,G.ButtonGroup=Sr,G.Char=qt,G.CodeEditor=Un,G.ConfigContext=$n,G.ConnectionProvider=W,G.ContentRootProvider=Zr,G.CurrentTabContent=Jl,G.Dashboard=Bn,G.DashboardGrid=Nn,G.DashboardGridItem=Pn,G.Date=xn,G.DateTime=Tn,G.Email=Mn,G.ExportModal=Sn,G.FavouriteButton=Xl,G.Float=Zt,G.FloatTime=mn,G.Form=at,G.FormModal=lt,G.GraphIndicator=fn,G.Group=rr,G.Image=Hr,G.Integer=wt,G.Label=pt,G.Many2one=ln,G.Markdown=Wn,G.MultiCheckbox=Kn,G.Notebook=yn,G.One2many=gn,G.ProgressBar=Rr,G.Radio=qn,G.Reference=Fn,G.RootView=ql,G.SearchFilter=Xt,G.SearchModal=er,G.SearchTree=Rt,G.Selection=Yt,G.Separator=wn,G.Steps=Gn,G.Switch=Yn,G.TabSelector=Ul,G.Tag=Hn,G.Tags=Yr,G.Text=vn,G.Tree=Ct,G.Url=In,G.iconMapper=qe,G.showConfirmDialog=et,Object.defineProperties(G,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
37
37
  //# sourceMappingURL=react-ooui.umd.js.map