@gisce/react-ooui 1.4.8-rc.0 → 1.4.9-rc.0
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.
package/dist/react-ooui.umd.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
`;var Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ro(t){var r=typeof t;return t!=null&&(r=="object"||r=="function")}var Mr=Ro,es=typeof Qe=="object"&&Qe&&Qe.Object===Object&&Qe,ts=es,rs=ts,ns=typeof self=="object"&&self&&self.Object===Object&&self,os=rs||ns||Function("return this")(),Er=os,ss=Er,is=function(){return ss.Date.now()},as=is,ls=/\s/;function cs(t){for(var r=t.length;r--&&ls.test(t.charAt(r)););return r}var ds=cs,us=ds,fs=/^\s+/;function hs(t){return t&&t.slice(0,us(t)+1).replace(fs,"")}var ps=hs,gs=Er,ms=gs.Symbol,Ir=ms,Ar=Ir,$r=Object.prototype,ys=$r.hasOwnProperty,ws=$r.toString,wt=Ar?Ar.toStringTag:void 0;function vs(t){var r=ys.call(t,wt),n=t[wt];try{t[wt]=void 0;var s=!0}catch{}var o=ws.call(t);return s&&(r?t[wt]=n:delete t[wt]),o}var Ss=vs,Cs=Object.prototype,bs=Cs.toString;function xs(t){return bs.call(t)}var Ts=xs,Lr=Ir,Fs=Ss,Os=Ts,_s="[object Null]",Ds="[object Undefined]",Nr=Lr?Lr.toStringTag:void 0;function ks(t){return t==null?t===void 0?Ds:_s:Nr&&Nr in Object(t)?Fs(t):Os(t)}var Vs=ks;function Ms(t){return t!=null&&typeof t=="object"}var Es=Ms,Is=Vs,As=Es,$s="[object Symbol]";function Ls(t){return typeof t=="symbol"||As(t)&&Is(t)==$s}var Ns=Ls,Ps=ps,Pr=Mr,Bs=Ns,Br=0/0,Hs=/^[-+]0x[0-9a-f]+$/i,Ks=/^0b[01]+$/i,Ys=/^0o[0-7]+$/i,Ws=parseInt;function qs(t){if(typeof t=="number")return t;if(Bs(t))return Br;if(Pr(t)){var r=typeof t.valueOf=="function"?t.valueOf():t;t=Pr(r)?r+"":r}if(typeof t!="string")return t===0?t:+t;t=Ps(t);var n=Ks.test(t);return n||Ys.test(t)?Ws(t.slice(2),n?2:8):Hs.test(t)?Br:+t}var Us=qs,Gs=Mr,jt=as,Hr=Us,js="Expected a function",zs=Math.max,Js=Math.min;function Zs(t,r,n){var s,o,i,a,c,f,d=0,h=!1,u=!1,g=!0;if(typeof t!="function")throw new TypeError(js);r=Hr(r)||0,Gs(n)&&(h=!!n.leading,u="maxWait"in n,i=u?zs(Hr(n.maxWait)||0,r):i,g="trailing"in n?!!n.trailing:g);function v(D){var L=s,x=o;return s=o=void 0,d=D,a=t.apply(x,L),a}function y(D){return d=D,c=setTimeout(S,r),h?v(D):a}function m(D){var L=D-f,x=D-d,T=r-L;return u?Js(T,i-x):T}function w(D){var L=D-f,x=D-d;return f===void 0||L>=r||L<0||u&&x>=i}function S(){var D=jt();if(w(D))return O(D);c=setTimeout(S,m(D))}function O(D){return c=void 0,g&&s?v(D):(s=o=void 0,a)}function V(){c!==void 0&&clearTimeout(c),d=0,s=f=o=c=void 0}function b(){return c===void 0?a:O(jt())}function M(){var D=jt(),L=w(D);if(s=arguments,o=this,f=D,L){if(c===void 0)return y(f);if(u)return clearTimeout(c),c=setTimeout(S,r),v(f)}return c===void 0&&(c=setTimeout(S,r)),a}return M.cancel=V,M.flush=b,M}var Xs=Zs;function Qs(t){const n=Buffer.from(t,"base64").length/1e3;return`${Math.round((n+Number.EPSILON)*100)/100} KB`}async function st(t){const r=await mo.fileTypeFromBuffer(Buffer.from(t,"base64"));return r||{mime:"text/plain",ext:"txt"}}const Kr=t=>new Promise((r,n)=>{const s=new FileReader;s.readAsDataURL(t),s.onload=o=>r(o.target.result.split(",")[1]),s.onerror=o=>n(o)});function Ot(t,r){for(var n=atob(t),s=new Array(n.length),o=0;o<n.length;o++)s[o]=n.charCodeAt(o);var i=new Uint8Array(s),a=new Blob([i],{type:r+";base64"}),c=URL.createObjectURL(a);window.open(c)}const Yr=t=>{const{ooui:r}=t,{required:n,id:s}=r,o=Ue(s);return o?e.jsx(o,{}):e.jsx(ge,{required:n,...t,children:e.jsx(Rs,{ooui:r})})},Rs=t=>{const{ooui:r,value:n,onChange:s}=t,{readOnly:o}=r,i=l.useRef(null),{t:a}=l.useContext(pe),c=u=>{s==null||s(u)};async function f(){const u=await st(n),g=`data:${u==null?void 0:u.mime};base64,${n}`,v=document.createElement("a");v.href=g,v.download=`image.${u==null?void 0:u.ext}`,v.click()}async function d(u){u.stopPropagation(),u.preventDefault();const g=u.target.files[0],v=await Kr(g);c(v)}function h(){c(void 0)}return e.jsxs(e.Fragment,{children:[e.jsxs(p.Row,{gutter:8,wrap:!1,justify:"center",children:[n&&e.jsx("img",{src:`data:image/*;base64,${n}`,style:{maxWidth:"100px"}}),e.jsx("input",{type:"file",id:"file",ref:i,accept:"image/*",style:{display:"none"},onChange:d})]}),e.jsx(p.Row,{gutter:8,wrap:!1,justify:"center",className:"pt-5",children:e.jsxs(p.Space,{children:[e.jsx(Be,{tooltip:a("uploadNewImage"),icon:e.jsx(H.FolderOpenOutlined,{}),disabled:o,onClick:()=>{i.current.click()}}),e.jsx(Be,{tooltip:a("download"),disabled:!n,onClick:f,icon:e.jsx(H.DownloadOutlined,{})}),e.jsx(Be,{tooltip:a("clear"),disabled:o||!n,onClick:h,icon:e.jsx(H.ClearOutlined,{})})]})})]})},ei=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(ge,{required:n,...t,children:e.jsx(ti,{})})},ti=t=>{const{value:r,onChange:n}=t;if(!r)return null;try{JSON.parse(r)}catch(s){return console.log(s),null}return e.jsx(yo.GridUi,{inputJson:r,onChange:s=>{n&&n(s)}})},it=t=>{const r=t.arch,n=t.fields,s=new ae.Tree(n);return s.parse(r),s},ri=(t,r,n)=>t.columns.map(o=>{const i=o.type,a=o.id,c=r==null?void 0:r[i];let f;return c&&(f=d=>c(d,a,o,n)),{key:a,dataIndex:a,title:o.label,render:f,sorter:(d,h)=>{var v,y;let u=d[a]||"",g=h[a]||"";return i==="many2one"&&(u=((v=d[a])==null?void 0:v.value)||"",g=((y=h[a])==null?void 0:y.value)||""),u<g?-1:u>g?1:0}}}),Wr=(t,r)=>r.map(s=>{const o={};return Object.keys(s).map(i=>{if(i==="id")o[i]=s[i];else{const a=t.findById(i);a instanceof ae.Reference||a instanceof ae.Selection?o[i]=s[i]:a instanceof ae.Many2one?o[i]=s[i]&&Array.isArray(s[i])&&s[i].length===2&&{model:a.relation,id:s[i][0],value:s[i][1]}:a instanceof ae.Boolean?o[i]=s[i]:a?o[i]=s[i]===!1?"":s[i]:o[i]=s[i]}}),o});function _t(t){return Ur(t,"colors")}function qr(t){return Ur(t,"status")}function Ur(t,r){if(!t)return;const n={};return t.forEach(s=>{n[s.id]=s[r]}),n}function at({resultsToSort:t,sorter:r,fields:n}){if(!r)return t;const{id:s,desc:o}=r,i=o===!1?"ascend":"descend",a=n[s].type,c=(f,d)=>{var g,v;let h=f[s]||"",u=d[s]||"";return a==="many2one"&&(h=((g=f[s])==null?void 0:g[1])||"",u=((v=d[s])==null?void 0:v[1])||""),h===u?0:i==="ascend"?h>u?1:-1:h<u?1:-1};return t.sort(c)}function ni(t){for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&t[r]!==void 0)return!0;return!1}const zt=async t=>{var y;const{items:r,model:n,formView:s,treeView:o,context:i,currentView:a={}}=t,c=r.filter(m=>m.operation!=="original"),f=r.filter(m=>m.operation==="original").map(m=>m.id),d={form:s.fields,tree:o.fields};let h=[],u;if(a==="tree"&&(o==null?void 0:o.arch)){const m=(y=it(o))==null?void 0:y.colors,w=await K.getHandler().readEvalUiObjects({model:n,ids:f,arch:o==null?void 0:o.arch,fields:o.fields,context:i,attrs:m&&{colors:m}});h=w[0],u=_t(w[1])}else h=await K.getHandler().readObjects({model:n,ids:f,fields:d[a],context:i});const g=h.map(m=>{const w={};return Object.keys(m).forEach(S=>{(d[a].hasOwnProperty(S)||S==="id")&&(w[S]=m[S])}),w});return[r.map(m=>{const w=g.find(O=>O.id===m.id),S={...m};return a==="form"?S.values=w:a==="tree"&&(S.treeValues=w),S}).concat(c),u]},oi=t=>{const r=t.filter(n=>n.id&&n.id<0).map(n=>n.id);return r.length===0?-1:Math.min(...r)-1},si=(t,r)=>{const n={};return Object.keys(t).forEach(s=>{var o;r.hasOwnProperty(s)&&(r[s].type==="one2many"||r[s].type==="many2many")&&t[s]&&((o=t[s])==null?void 0:o.items)?n[s]=t[s].items.filter(i=>i.operation!=="pendingRemove"):n[s]=t[s]}),n},ii=t=>{const{ooui:r}=t,{relation:n,context:s,views:o}=r,[i,a]=l.useState(!0),[c,f]=l.useState(),[d,h]=l.useState(new Map),u=l.useContext(Ve),{getContext:g}=u||{};Re.default(()=>{y()},[r]);const v=async m=>o&&o[m]?o[m]:await K.getHandler().getView({model:n,type:m,context:{...g==null?void 0:g(),...s}}),y=async()=>{a(!0),f(void 0);try{const m=await v("form"),w=await v("tree");d.set("form",m),d.set("tree",w),h(d)}catch(m){f(m)}finally{a(!1)}};return i?e.jsx(p.Spin,{}):c?e.jsx(p.Alert,{className:"mt-10",message:c,type:"error",banner:!0}):e.jsx(ge,{type:"array",...t,children:e.jsx(ai,{ooui:r,views:d})})},ai=t=>{const{value:r,views:n,ooui:s,onChange:o}=t,{items:i=[]}=r||{},[a,c]=l.useState(!1),[f,d]=l.useState(),[h,u]=l.useState(!1),[g,v]=l.useState(),{relation:y,context:m,readOnly:w,summaryField:S,titleField:O}=s,V=i.filter(x=>x.values),b=l.useContext(Ve),{getContext:M}=b||{};Re.default(()=>{L()},[i]);const D=x=>{o==null||o({items:x})};async function L(){c(!0),d(void 0);try{const[x]=await zt({treeView:{fields:n.get("tree").fields,arch:n.get("tree").arch},formView:{fields:n.get("form").fields},model:y,items:i,context:{...M==null?void 0:M(),...m},currentView:"form"});D(x)}catch(x){d(x)}finally{c(!1)}}return f?e.jsx(p.Alert,{className:"mt-10",message:f,type:"error",banner:!0}):a?e.jsx(p.Spin,{}):e.jsxs(e.Fragment,{children:[e.jsx(p.Timeline,{style:{padding:"1rem"},children:V.map((x,T)=>{var C,F;return e.jsx("div",{children:e.jsxs(p.Timeline.Item,{children:[e.jsx("div",{style:{display:"inline-block",cursor:"pointer"},onClick:()=>{v(V.find(P=>x.id===P.id)),u(!0)},children:e.jsx("strong",{children:(C=x.values)==null?void 0:C[O]})}),e.jsx("br",{}),e.jsx("div",{style:{display:"inline-block",cursor:"pointer"},onClick:()=>{v(V.find(P=>x.id===P.id)),u(!0)},children:(F=x.values)==null?void 0:F[S]})]},T)},T)})}),e.jsx(ft,{formView:n.get("form"),model:y,id:g==null?void 0:g.id,values:g==null?void 0:g.values,defaultValues:g==null?void 0:g.defaultValues,visible:h,onSubmitSucceed:()=>{u(!1)},parentContext:{...M==null?void 0:M(),...m},onCancel:()=>{u(!1)},readOnly:w,postSaveAction:L})]})},{useToken:li}=p.theme,ci=t=>{const{ooui:r}=t;return e.jsx(ge,{ooui:r,children:e.jsx(di,{ooui:r})})},di=t=>{const{token:r}=li(),{ooui:n,value:s}=t,o=e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[n.label," "]}),n.tooltip&&e.jsx(p.Tooltip,{title:n.tooltip,children:e.jsx(H.QuestionCircleOutlined,{className:"pr-1 text-xs",style:{color:r.colorPrimaryBg}})})]}),i=Ue(n.icon);let a=s;n.selectionValues.size?a=n.selectionValues.get(s):Array.isArray(s)&&(a=s[1]);const c=e.jsx(p.Statistic,{title:o,prefix:i&&e.jsx(i,{}),suffix:n.suffix,value:a});return n.card?e.jsx(p.Card,{children:c}):c},ui=(t,r)=>{if(!r)return t;const n={};return Object.keys(t).forEach(s=>{if(r[s]===void 0)n[s]=t[s];else if(!(t[s]===!1&&r[s].type!=="boolean"))if(r[s].type==="boolean"){const o=t[s];o===0?n[s]=!1:o===1?n[s]=!0:n[s]=t[s]}else n[s]=t[s]}),n},lt=(t,r)=>ui(t,r),Jt=({source:t,target:r,fields:n})=>{const s={};return Object.keys(r).forEach(o=>{var a,c;if(n[o]?n[o].type==="one2many"||n[o].type==="many2many":!1){const f=JSON.stringify(t[o]),d=JSON.stringify(r[o]);if(f===d)return;(((c=(a=r[o])==null?void 0:a.items)==null?void 0:c.filter(u=>u.operation!=="original"))||[]).length>0&&(s[o]=r[o])}else if(Array.isArray(r[o]))if(t[o]===void 0)s[o]=r[o];else if(n[o].type==="many2one")if(Array.isArray(t[o])){const f=JSON.stringify(t[o]),d=JSON.stringify(r[o]);f!==d&&(s[o]=r[o])}else{const f=t[o],[d]=r[o];f!==d&&(s[o]=r[o])}else{const f=JSON.stringify(t[o]),d=JSON.stringify(r[o]);f!==d&&(s[o]=r[o])}else t[o]!==r[o]&&(r[o]===void 0?s[o]=null:s[o]=r[o])}),s},fi=({changedFields:t,formOoui:r,types:n})=>t.map(o=>{var a;const i=(a=r==null?void 0:r.findById(o))==null?void 0:a.type;return n.includes(i)}).some(o=>o===!0),hi=({fieldsDomain:t,fields:r})=>{const n={};return Object.keys(r).forEach(s=>{n[s]=r[s],t[s]&&(n[s].domain=t[s])}),n},pi=t=>{const r={};return!t||!Array.isArray(t)||(t==null?void 0:t.length)===0?{}:(t.forEach(n=>{(n==null?void 0:n[1])==="="&&(r[n[0]]=n[2])}),r)},gi=({onChangeFieldActionArgs:t,values:r,parentValues:n={}})=>{const s={};return t.forEach(o=>{const i=o.split("");if(o==="True")s[o]=!0;else if(o==="False")s[o]=!1;else if(r[o])s[o]=r[o];else if(i[0]==="'"&&i[i.length-1]==="'"&&i.filter(a=>a==="'").length===2)s[o]=o.replace(/'/g,"");else if(i.includes("'"))s[o]=o;else if(o.indexOf("parent.")!==-1){const a=o.replace("parent.","");s[o]=n[a]||!1}else s[o]=!1}),s},Gr=t=>{const r={primary:[],secondary:[]};return t.forEach(n=>{!n||(r.primary=r.primary.concat(n.primary),r.secondary=r.secondary.concat(n.secondary))}),{primary:r.primary.filter(jr),secondary:r.secondary.filter(jr)}};function jr(t,r,n){return n.indexOf(t)===r}const ct=({values:t,fields:r})=>{let n={};return Object.keys(t).forEach(s=>{const o=t[s];r[s]&&r[s].type==="many2one"&&o&&Array.isArray(o)&&o.length===2?n[s]=o[0]:n[s]=o}),n},Dt=t=>{let r=0;t=t.toString().padEnd(10,"0");for(let o=0;o<t.length;o++)r=t.charCodeAt(o)+((r<<5)-r);let n="#";for(let o=0;o<3;o++){var s=r>>o*8&255;n+=("00"+s.toString(16)).slice(-2)}return n},mi=(t,r)=>t.replace(/\{([^}]+)\}/g,(n,s)=>r[s]!==void 0?r[s]:n),zr=t=>e.jsx(ge,{...t,children:e.jsx(Jr,{...t})}),Jr=t=>{const{ooui:r,value:n}=t;let s=n,o=n;if(r.selectionValues.size?s=r.selectionValues.get(n):Array.isArray(n)&&(o=n[0],s=n[1]),!n)return null;const i=r.colors==="auto"?Dt(o):r.colors[o]||Dt(o);return e.jsx(Zr,{color:i,children:s})},Zr=t=>{let{color:r}=t,n={};return!pr.isPresetStatusColor(t.color)&&!pr.isPresetColor(t.color)&&(n={color:r,borderColor:r,borderStyle:"solid",borderWidth:"1px"},r=`${r}20`),e.jsx(p.Tag,{...t,style:n,color:r,children:t.children})},Xr=t=>{const{ooui:r}=t;return e.jsx(ge,{type:"array",...t,children:e.jsx(yi,{ooui:r})})},yi=t=>{const{value:r,ooui:n,onChange:s}=t,{items:o=[]}=r||{},i=o.filter(D=>D.operation!=="pendingRemove").map(D=>D.id),[a,c]=l.useState([]),[f,d]=l.useState(),[h,u]=l.useState(!1),{relation:g,context:v,readOnly:y,field:m}=n,w=l.useContext(Ve),{getContext:S}=w||{};Re.default(()=>{V()},[o]);const O=D=>{s==null||s({items:D})};async function V(){u(!0);let D=[];try{if(y&&(D=[["id","in",i]]),n.domain){const T=await K.getHandler().evalDomain({domain:n.domain,values:ct({fields:w==null?void 0:w.getFields(),values:w.getPlainValues()}),fields:w==null?void 0:w.getFields(),context:w.getContext()});D=[...D,...T]}const x=(await K.getHandler().search({model:g,params:D,fields:[m],context:{...S==null?void 0:S(),...v}})).map(T=>{const C=T[m];let F=C;return Array.isArray(C)&&(F=C[1]),{label:F,value:T.id}});c(x)}catch(L){d(L)}finally{u(!1)}}const b=D=>{const L=o.map(T=>D.includes(T.id)?T.operation=="pendingRemove"?{...T,operation:"pendingLink"}:T:{id:T.id,operation:"pendingRemove"}),x=L.map(T=>T.id);D.filter(T=>!x.includes(T)).map(T=>{L.push({id:T,operation:"pendingLink"})}),O(L)},M=D=>{const{label:L,closable:x,onClose:T}=D,C=P=>{P.preventDefault(),P.stopPropagation()},F=Dt(L);return e.jsx(Zr,{color:F,onMouseDown:C,closable:x,onClose:T,closeIcon:e.jsx("span",{style:{color:F},children:"X"}),children:L})};return f?e.jsx(p.Alert,{className:"mt-10",message:f,type:"error",banner:!0}):e.jsx(e.Fragment,{children:e.jsx("div",{className:"flex flex-row",children:e.jsx(p.Select,{mode:"multiple",value:a.length?i:[],tagRender:M,bordered:!y,disabled:y,options:a,onChange:b,loading:h})})})},wi=t=>{switch(t){case"form":return ut;case"tree":return bt;case"notebook":return On;case"group":return nr;case"label":return yt;case"char":return Ut;case"text":return _n;case"button":return qt;case"buttonGroup":return Tr;case"selection":return Gt;case"many2one":return yn;case"boolean":return Vr;case"integer":return Ct;case"float":return Xt;case"progressbar":return an;case"date":return En;case"datetime":return In;case"time":return $n;case"one2many":case"one2many_list":case"many2many":return Tn;case"separator":return Dn;case"reference":return Ln;case"binary":return Nn;case"image":return Yr;case"url":return Wn;case"email":return qn;case"float_time":return Fn;case"fiber_grid":return ei;case"timeline":return ii;case"indicator":return ci;case"tags":return Xr;case"tag":return zr;case"multicheckbox":return Xn;case"markdown":return Qn;case"radio":return Rn;case"switch":return eo;case"steps":return to;case"codeeditor":return ro;default:return}},vi=t=>{const{ooui:r}=t,{type:n}=r,s=wi(n);return s?Ke.default.createElement(s,t):null},Si=({item:t,responsiveBehaviour:r})=>({gridColumnStart:"span "+(r?1:t.colspan)}),Ci=({row:t,mustFillWithEmpties:r,numberOfColumns:n})=>{const s=[];let o=0;const i=a=>a+1===t.length&&o<n&&!r;return t.map((a,c)=>{if(o+=a.colspan,i(c)){const f=n-o;a.colspan=a.colspan+f,o+=f}if(s.push(a),i(c)){const f=n-o;for(let d=0;d<f;d+=1)s.push(new ae.Label({string:""}))}}),s},bi=({row:t,numberOfColumns:r})=>t.map(n=>(n._mustExpand&&(n.colspan=r),n)),xi=(t,r)=>{const n=t.map(s=>s instanceof ae.Label&&s.fieldForLabel||s instanceof ae.Container?"auto":"1fr");if(n.length<r){const s=r-n.length;for(let o=0;o<s;o++)n.push("1fr")}return n.join(" ")},Ti=(t,r)=>{const n=r?"1fr":"auto",s="auto";let o="";for(let i=0;i<t;i++)o+=i%2?n:s,i+1<t&&(o+=" ");return o},Fi=t=>t.map(n=>n.reduce((s,o)=>s+o.colspan,0)).reduce((n,s)=>Math.max(n,s)),Zt=t=>{const{container:r,responsiveBehaviour:n}=t,{rows:s}=r;let{columns:o}=r;const i=Fi(s);i<o&&(o=i);let a=!1,c=[];const f=s.map((u,g)=>{const v=u.filter(w=>!w.invisible),y=bi({row:v,numberOfColumns:o});let m=y;return(g===0||!(u.length===1&&u.some(w=>w.type==="group")))&&(m=Ci({row:y,numberOfColumns:o,mustFillWithEmpties:n}),c=c.concat(m)),m.map(w=>(w instanceof ae.Label&&w.fieldForLabel&&(a=!0),e.jsx("div",{style:{...Si({item:w,responsiveBehaviour:n}),minWidth:0},children:vi({ooui:w,responsiveBehaviour:n})},w.key)))}),d=s.length===1?xi(c,o):Ti(o,a),h={display:"grid",gridTemplateColumns:n?"auto":d,gap:"1rem",minHeight:0,minWidth:0};return e.jsx("div",{style:h,children:f})},{confirm:Oi}=p.Modal,vt=({onOk:t,onCancel:r,lang:n})=>{Oi({title:Ce("unsavedChanges",n),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Ce("confirmCloseWithoutSave",n),okText:Ce("closeWithoutSaving",n),onOk:t,onCancel:r,cancelText:Ce("cancel",n)})},{error:_i}=p.Modal,Qr=t=>{_i({title:Ce("formHasErrors",t),icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:Ce("fillRequiredFields",t)})},{warning:Di}=p.Modal,ki=(t,r,n)=>{Di({title:t,icon:e.jsx(H.WarningOutlined,{}),centered:!0,content:r,onOk:n})},Rr=Ke.default.createContext(null),Vi=t=>{const{children:r,setTitle:n}=t;return e.jsx(Rr.Provider,{value:{setTitle:n},children:r})},en=t=>typeof t=="string"&&t==="true"||t==="false"?t==="true":t,Mi=(t,r)=>{const n=Ni(t),s=$i(n),o=Li(s,r);return[...Object.keys(o).map(c=>Ei(c,o[c],r))].reduce((c,f)=>Array.isArray(f[0])?c.concat(f):[...c,f],[])},Ei=(t,r,n)=>{var i;const s=t.split("#")[0],o=(i=n.findById(s))==null?void 0:i.type;if(o==="char"||o==="text"||o==="many2one"||o==="many2many"||o==="one2many")return[t,"ilike",r];if(o==="float"||o==="integer"||o==="float_time"||o==="progressbar"){const a=t.indexOf("#from")!==-1?">=":"<=";return[s,a,r]}else if(o==="date"){const a=t.indexOf("#from")!==-1?">=":"<=";return[s,a,r.format("YYYY-MM-DD")]}else if(o==="datetime"){const a=[];return r[0]&&a.push([s,">=",r[0]]),r[1]&&a.push([s,"<=",r[1]]),a}else return o==="selection"?[t,"in",r.map(a=>en(a))]:[t,"=",en(r)]},Ii=t=>Object.keys(t).filter(r=>r.indexOf("#date")!==-1),Ai=t=>{const r={...t};return Object.keys(r).forEach(n=>(n.indexOf("#time")!==-1||n.indexOf("#date")!==-1)&&delete r[n]),r},$i=t=>{const r={...Ai(t)};return Ii(t).forEach(s=>{const o=t[s],i=s.split("#")[0],a=i+"#time",c=t[a];let f,d;if(o[0]!==null&&(f=o[0].format("YYYY-MM-DD"),c&&c[0]!==null)){const u=c[0].format("HH:mm:ss");f=f+" "+u}if(o[1]!==null&&(d=o[1].format("YYYY-MM-DD"),c&&c[1]!==null)){const u=c[1].format("HH:mm:ss");d=d+" "+u}r[i+"#datetime"]=[f,d]}),r},Li=(t,r)=>{const n=Object.keys(t).filter(o=>{const i=r.findById(o);return i&&i.type==="date"});let s={...t};return n.forEach(o=>{delete s[o],t[o][0]!==null&&(s[o+"#from"]=t[o][0]),t[o][1]!==null&&(s[o+"#to"]=t[o][1])}),s},Ni=t=>{const r={...t};return Object.keys(r).forEach(n=>(r[n]===void 0||r[n]===null||r[n]==="")&&delete r[n]),r},Pi=t=>{const r={};return t.forEach(n=>{Array.isArray(n)&&n[0]?r[n[0]]=!0:r[n]=!0}),Object.keys(r)},kt=(t,r)=>{const n=[...t],s=Pi(t);return r.forEach(o=>{Array.isArray(o)&&o[0]?s.includes(o[0])||n.push(o):s.includes(o)||n.push(o)}),n},St=80,tn=t=>{const{model:r,setSearchTreeNameSearch:n,setSelectedRowItems:s,setSearchParams:o,setSearchVisible:i,setTreeIsLoading:a,nameSearch:c,searchNameGetDoneRef:f,context:d,setActionViewTotalItems:h,treeView:u,formView:g,sorter:v,setSorter:y,setCurrentItemIndex:m,setResultsActionView:w,resultsActionView:S,domain:O,currentId:V,limit:b,setLimit:M,searchParams:D=[],setSearchValues:L}=t,[x,T]=l.useState(!1),[C,F]=l.useState(!1),[P,I]=l.useState(),[_,A]=l.useState(1),[$,k]=l.useState(0),[B,E]=l.useState(),[W,J]=l.useState([]),[G,X]=l.useState(void 0),[j,N]=l.useState(void 0),Y=l.useRef(b||St),re=l.useRef([]),Q=l.useCallback(se=>{w==null||w([...se]),J([...se])},[]),le=l.useCallback(()=>S||W,[S,W]),R=l.useCallback(async()=>{const se=await K.getHandler().nameSearch({model:r,payload:c,limit:Y.current,attrs:O,context:d});if(E(se.length),h==null||h(se.length),se.length>0){const de=se.map(ke=>ke==null?void 0:ke[0]),{colors:Ae,status:ye}=it(u),De={};Ae&&(De.colors=Ae),ye&&(De.status=ye);const Ye=await K.getHandler().readEvalUiObjects({model:r,ids:de,arch:u==null?void 0:u.arch,fields:u.field_parent?{...u.fields,[u.field_parent]:{}}:u.fields,context:d,attrs:De}),te=Ye[0];re.current=[...te],X(_t(Ye[1])),N(qr(Ye[1]));const Te=te.map(ke=>ke.id),_e=v!==void 0?at({resultsToSort:te,sorter:v,fields:{...u.fields,...g.fields}}):[...re.current];Q(_e),Te.length>0?m==null||m(0):m==null||m(void 0)}else Q([]),m==null||m(void 0);T(!1),f.current=!0},[Q,f,c,r,d,O,u,g,v,m,h]),Z=l.useCallback(async se=>{const{params:de,newOffset:Ae}=se||{},ye=kt(de||D,O),{colors:De,status:Ye}=it(u),te={};De&&(te.colors=De),Ye&&(te.status=Ye);const{totalItems:Te,results:_e,attrsEvaluated:ke}=await K.getHandler().searchForTree({params:ye,limit:Y.current,offset:Ae||$,model:r,fields:u.field_parent?{...u.fields,[u.field_parent]:{}}:u.fields,context:d,attrs:te});X(_t(ke)),N(qr(ke)),re.current=[..._e];const ce=v!==void 0?at({resultsToSort:_e,sorter:v,fields:{...u.fields,...g.fields}}):[...re.current];if(Q(ce),S&&ce.length>0){const Pe=ce.findIndex(ue=>V===ue.id);Pe===-1?m==null||m(0):m==null||m(Pe)}else m==null||m(void 0);T(!1);const fe=await Te;E(fe),h==null||h(fe)},[m,S,Q,V,r,d,O,u,g,v,h,b,$,D]),he=l.useCallback(async se=>{try{T(!0),a==null||a(!0),c&&!f.current?await R():await Z(se)}catch(de){I(de.message)}finally{F(!1),a==null||a(!1)}},[d,V,O,g,b,r,c,$,S,f,h,m,Q,I,F,T,a,v,u]),we=l.useCallback(se=>{if(JSON.stringify(se)===JSON.stringify(v))return;y==null||y(se);const de=se!==void 0?at({resultsToSort:le(),sorter:se,fields:{...u.fields,...g.fields}}):[...re.current];Q(de)},[y,le,u,g,Q]),Me=l.useCallback(se=>{const{params:de,searchValues:Ae,limit:ye,offset:De}=se;x||(n==null||n(void 0),s==null||s([]),L==null||L(Ae),o==null||o(de),i==null||i(!1),F(!0),I(void 0),A(1),ye&&(Y.current=ye,M==null||M(ye)),De&&k(De),he({params:de,newOffset:De}))},[x,n,s,o,i,F,I,A,M,k,he]),Oe=l.useCallback(se=>{T(!0),A(se),k((se-1)*b)},[T,b,k,A]),Ie=l.useCallback(()=>{x||(n==null||n(void 0),o==null||o([]),L==null||L({}),I(void 0),k(0),A(1),M==null||M(b||St))},[x,n,o,I,k,A,M,b]),Ne=l.useCallback(async se=>{const de=se[(u==null?void 0:u.field_parent)||"child_id"],Ae=await K.getHandler().readObjects({model:r,ids:de,fields:u.field_parent?{...u.fields,[u.field_parent]:{}}:u.fields,context:d});return Q([...le(),...Ae]),Wr(it(u),Ae)},[u,r,d,le,Q]);return{submit:Me,clear:Ie,fetchResults:he,tableRefreshing:x,searchFilterLoading:C,searchError:P,page:_,offset:$,limit:b,getResults:le,requestPageChange:Oe,changeSort:we,fetchChildrenForRecord:Ne,colorsForResults:G,statusForResults:j,totalItems:B}},We=Ke.default.createContext(null),Bi=t=>{const{children:r,currentView:n,title:s,setCurrentView:o,availableViews:i,formRef:a,searchTreeRef:c,onNewClicked:f,currentId:d,setCurrentId:h,setResults:u,results:g,currentItemIndex:v,setCurrentItemIndex:y,currentModel:m,sorter:w,setSorter:S,totalItems:O,setTotalItems:V,setSelectedRowItems:b,selectedRowItems:M,searchTreeNameSearch:D,setSearchTreeNameSearch:L,goToResourceId:x,limit:T}=t,[C,F]=l.useState(!1),[P,I]=l.useState(!1),[_,A]=l.useState(!1),[$,k]=l.useState(!0),[B,E]=l.useState(!0),[W,J]=l.useState([]),[G,X]=l.useState(!1),[j,N]=l.useState([]),[Y,re]=l.useState(!1),[Q,le]=l.useState(!0),[R,Z]=l.useState(),[he,we]=l.useState({}),[Me,Oe]=l.useState(T!==void 0?T:St),[Ie,Ne]=l.useState(s);l.useEffect(()=>{g&&g.length>0&&!v&&(y==null||y(0),h==null||h(g[0].id))},[g]),l.useEffect(()=>{Oe(T!==void 0?T:St)},[T]),l.useEffect(()=>{i.length===1?Z(i[0]):i.length>1&&Z(i.filter(de=>de.view_id!==n.view_id)[0])},[i]),l.useEffect(()=>{(R==null?void 0:R.view_id)===n.view_id&&i.length>1&&Z(i.filter(de=>de.view_id!==n.view_id)[0])},[n]);const se=async()=>{var de;return await((de=a.current)==null?void 0:de.submitForm())};return e.jsx(We.Provider,{value:{title:Ie,currentView:n,setCurrentView:o,availableViews:i,formIsSaving:C,setFormIsSaving:F,formHasChanges:P,setFormHasChanges:I,formRef:a,searchTreeRef:c,onFormSave:se,onNewClicked:f,currentId:d,setCurrentId:h,currentItemIndex:v,setCurrentItemIndex:y,results:g,setResults:u,currentModel:m,removingItem:_,setRemovingItem:A,formIsLoading:$,setFormIsLoading:k,treeIsLoading:B,setTreeIsLoading:E,attachments:W,setAttachments:J,selectedRowItems:M,setSelectedRowItems:b,duplicatingItem:G,setDuplicatingItem:X,setSearchParams:N,searchParams:j,searchVisible:Y,setSearchVisible:re,sorter:w,setSorter:S,totalItems:O,setTotalItems:V,searchTreeNameSearch:D,setSearchTreeNameSearch:L,setGraphIsLoading:le,graphIsLoading:Q,previousView:R,setPreviousView:Z,goToResourceId:x,searchValues:he,setSearchValues:we,limit:Me,setLimit:Oe,setTitle:Ne},children:r})},Ge=Ke.default.createContext(null),Hi=t=>{const{children:r,openAction:n,openRelate:s,openDefaultActionForModel:o,openShortcut:i,activeKey:a,onChangeTab:c,onRemoveTab:f,tabs:d}=t,[h,u]=l.useState(),[g,v]=l.useState();return e.jsx(Ge.Provider,{value:{openAction:n,openRelate:s,openDefaultActionForModel:o,activeKey:a,openShortcut:i,onChangeTab:c,onRemoveTab:f,tabs:d,currentId:g,currentView:h,setCurrentId:v,setCurrentView:u},children:r})},dt=Ke.default.createContext(null),rn=async t=>{var r;for(let n=0;n<t.length;n++)await((r=t==null?void 0:t[n])==null?void 0:r.call(t))},Ki=(t,r)=>{const{children:n,globalValues:s={}}=t,o=l.useRef(),i=l.useRef(),[a,c]=l.useState(!1),f=l.useContext(Ge),{openAction:d}=f||{},h=l.useRef([]),{t:u}=l.useContext(pe);l.useImperativeHandle(r,()=>({openActionModal:b}));const[g,v]=l.useState(!1),[y,m]=l.useState({context:{}});async function w(L){const{reportData:x,fields:T,values:C,context:F={}}=L,{context:P,model:I,datas:_={},report_name:A,type:$}=x;if($!=="ir.actions.report.xml"){Le(`${$} action not supported`);return}const{ids:k}=_||{};let B=k||[];const E=typeof P=="string"?ae.parseContext({context:P,fields:T,values:C}):P;try{const W=await K.getHandler().createReport({model:I,name:A,datas:_,ids:B,context:{...F,...E}});c(!0),i.current=!0,o.current=setInterval(()=>{S(W)},1e3)}catch(W){i.current=!1,clearInterval(o.current),Le(W),c(!1)}}async function S(L){let x;try{if(x=await K.getHandler().getReport({id:L}),x.state&&i.current===!0){i.current=!1,clearInterval(o.current),c(!1);const T=await st(x.result);Ot(x.result,T.mime)}}catch(T){i.current=!1,clearInterval(o.current),c(!1),Le(T.exception||T)}}async function O({actionData:L,fields:x,values:T,context:C,onRefreshParentValues:F}){const{type:P}=L;if(h.current.push(F),P==="ir.actions.report.xml")return await w({reportData:L,fields:x,values:T,context:C});if(P==="ir.actions.act_window")return await V({actionData:L,fields:x,values:T,context:C});if(P==="ir.actions.act_url")window.open(mi(L.url,{...T,context:C}),"_blank");else return Le(`${P} action not supported`),{}}async function V({actionData:L,fields:x={},values:T={},context:C={}}){var A;let F=L;L.res_model||(F=(await K.getHandler().readObjects({model:"ir.actions.act_window",ids:[parseInt(L.id)],context:C}))[0]);const I={...typeof(F==null?void 0:F.context)=="string"?ae.parseContext({context:F.context,fields:x,values:{...T,...s}}):F.context,...C};let _=[];if(F.domain&&(_=await K.getHandler().evalDomain({domain:F.domain,values:ct({fields:x,values:{...T,...s}}),fields:x,context:I})),F.target==="new"){const $=await K.getHandler().getView({model:F.res_model,type:"form",id:((A=F==null?void 0:F.view_id)==null?void 0:A[0])||void 0,context:I});return b({domain:_,model:F.res_model,formView:$,context:I}),{}}else{const{initialView:$,views:k}=await Yi({model:F.res_model,context:I,view_mode:F.view_mode,views:F.views});return d==null||d({target:"current",context:I,domain:_,model:F.res_model,views:k,title:F.name,initialView:$,action_id:F.id,action_type:F.type}),{closeParent:!0}}}function b({domain:L,model:x,formView:T,context:C,actionData:F}){g?M({domain:L,model:x,formView:T,context:C,actionData:F}):(m({domain:L,model:x,context:C,formView:T,actionData:F}),v(!0))}async function M({domain:L,model:x,formView:T,context:C,actionData:F}){m({domain:void 0,model:void 0,context:{},formView:void 0,actionData:void 0}),v(!1),await new Promise(P=>setTimeout(P,300)),m({domain:L,model:x,context:C,formView:T,actionData:F}),v(!0)}async function D(){rn(h.current),h.current=[],v(!1),m({domain:void 0,model:void 0,context:{},formView:void 0,actionData:void 0})}return e.jsx(e.Fragment,{children:e.jsx(dt.Provider,{value:{processAction:O,globalValues:s},children:e.jsxs(e.Fragment,{children:[n,e.jsx(p.Modal,{title:u("generatingReport"),open:a,footer:null,closable:!1,centered:!0,maskClosable:!1,children:e.jsx(p.Spin,{})}),e.jsx(ft,{buttonModal:!0,parentContext:y.context,model:y.model,formView:y.formView,visible:g,onSubmitSucceed:D,onCancel:()=>{rn(h.current),h.current=[],v(!1),m({domain:void 0,model:void 0,context:{},formView:void 0,actionData:void 0})},showFooter:!1,actionDomain:y.domain,isMenuAction:(y==null?void 0:y.actionData)!==void 0,actionData:y==null?void 0:y.actionData})]})})})};async function Yi({views:t,view_mode:r,model:n,context:s,view_id:o}){const i=[];let a;if(t)for(const c of t){const f=await K.getHandler().getView({model:n,type:c[1],id:c[0],context:s});i.push([f.view_id,c[1]])}else{const c=r.split(",");for(const f of c){const d=await K.getHandler().getView({model:n,type:f,context:s});i.push([d.view_id,f])}}if(t&&t.length>0){const[c,f]=t[0];a={id:c,type:f}}else if(o)a={id:o,type:r.split(",")[0]};else{const c=r.split(",")[0],[f]=i.find(([d,h])=>h===c);a={id:f,type:c}}return{views:i,initialView:a}}const nn=l.forwardRef(Ki),Wi=({error:t,className:r})=>{let n,s="error";if(typeof t=="string"&&t.indexOf(" -- ")!==-1&&t.indexOf(`
|
|
18
18
|
|
|
19
|
-
`)!==-1){const{message:o,type:i,title:a}=Or(t);n=e.jsx(Ht.Interweave,{content:`${a}<br />${o}`}),s=i}else n=t.message?JSON.stringify(t.message):JSON.stringify(t);return e.jsx(p.Alert,{className:r,message:n,type:s,banner:!0})},qi=800;function Ui(t,r){const{model:n,id:s,onCancel:o,onSubmitSucceed:i,showFooter:a=!1,getDataFromAction:c=!1,onFieldsChange:f,onSubmitError:d,readOnly:h=!1,mustClearAfterSave:u=!1,submitMode:g="api",values:v,formView:y,postSaveAction:m,insideButtonModal:w=!1,parentContext:S={},actionDomain:O,visible:V=!0,rootForm:b=!1,defaultValues:M,forcedValues:D={},parentWidth:L}=t,{t:x,lang:T}=l.useContext(pe),[C,F]=l.useState(!1),[P,I]=l.useState(),[_,A]=l.useState(),[$]=p.Form.useForm(),[k,B]=l.useState(),[E,W]=l.useState(),J=l.useContext(Rr),[G,X]=l.useState(),[j,N]=l.useState(!1),Y=l.useRef(),re=l.useRef({}),Q=l.useRef({}),le=l.useRef(!1),R=l.useRef(!1),Z=l.useRef(!1),we=(L!==void 0?L:G)<qi,Me=l.useContext(Ve),{activeId:Oe,getPlainValues:Ie}=Me||{},Ne=l.useContext(We),{setFormIsSaving:se=void 0,setFormHasChanges:de=void 0,setCurrentId:Ae=void 0,setFormIsLoading:ye=void 0,setAttachments:De=void 0,title:Ye=void 0,setTitle:te=void 0}=(b?Ne:{})||{},Te=l.useContext(dt),{processAction:_e,globalValues:ke}=Te||{};l.useImperativeHandle(r,()=>({submitForm:Pt,getFields:je,getValues:$e,getPlainValues:ee,getContext:ve,fetchValues:rt,cancelUnsavedChanges:so,clearAndReload:()=>{Y.current=void 0,A(void 0),oo()}})),l.useEffect(()=>{if(I(void 0),!(!n&&!y)){if(!V){Y.current=void 0,A(void 0);return}(s===void 0&&E||s!==void 0&&E&&s<0)&&(Y.current=void 0,A(void 0)),oo()}},[s,n,v,y,V]),l.useEffect(()=>{j&&(ur({elementHasLostFocus:!0}),N(!1))},[j]);const ce=(q,z,oe,ne)=>{de==null||de(!1),se==null||se(!1),i==null||i(q,z,oe,ne),Ae==null||Ae(q)},fe=()=>{se==null||se(!1),o==null||o()},Pe=q=>{se==null||se(!1),d==null||d(q)};function ue(){return s||Y.current}function je(){return E}function $e(){const q={...Ee(E),...Se()};for(const z in q)q[z]===void 0&&delete q[z];return q}function ee(){const q=$e(),z=je();let oe={};return Object.keys(q).forEach(ne=>{const Fe=q[ne];z[ne]&&z[ne].type==="many2one"&&Fe&&Array.isArray(Fe)&&Fe.length===2?oe[ne]=Fe[0]:z[ne]&&(z[ne].type==="one2many"||z[ne].type==="many2many")&&Fe&&Fe.items?oe[ne]=Fe.items.filter(nt=>nt.operation!=="pendingRemove").map(nt=>nt.id):oe[ne]=Fe}),oe}function ie(){const q={...Ee(E)};for(const z in q)q[z]===void 0&&delete q[z];return q}function ve(){return{...S,..._==null?void 0:_.context}}function me(){return ue()?{active_id:ue(),active_ids:[ue()]}:{}}function Se(){return{id:ue(),active_id:ue(),active_ids:[ue()],parent_id:Oe,...ke}}const be=async q=>{const z=ue()?_==null?void 0:_.context:{};return await K.getHandler().defaultGet({model:n,fields:q,context:{...S,...z},extraValues:M})},xe=()=>Object.keys(Jt({source:re.current,target:Ee(E),fields:E})).length!==0,Ee=q=>{const z=$.getFieldsValue(!0);return lt(z,q)},ze=(q,z)=>{Tt({values:{...lt($.getFieldsValue(!0),E),[q]:z},fields:E,reset:!1})},tt=q=>$.getFieldsValue(!0)[q];async function no(){try{return await $.validateFields(),!1}catch{return p.message.error(x("fillRequiredFields")),!0}}const oo=async()=>{I(void 0),ye==null||ye(!0);let q;try{y?q={arch:y.arch,fields:y.fields}:q=await wc();const{fields:z,arch:oe}=q;W(z),B(oe),await rt({fields:z,arch:oe})}catch(z){I(z!=null&&z.message?z.message+z.stack:z),ye==null||ye(!1)}},rt=async q=>{let z,oe,ne,Fe;ye==null||ye(!0),I(void 0),q!=null&&q.fields?(oe=q.fields,ne=q.arch):(oe=E,ne=k),v&&(q==null?void 0:q.forceRefresh)!==!0?z=v:{values:z,defaultGetCalled:Fe}=await vc({fields:oe,arch:ne}),O&&(z={...pi(O),...z}),re.current=lt(z,oe),Tt({values:z,fields:oe,reset:!0,isDefaultGet:Fe}),Bt({fields:oe,arch:ne,values:z}),ye==null||ye(!1),de==null||de(!1),Fe&&N(!0)},so=async()=>new Promise(async q=>{xe()?vt({lang:T,onOk:()=>{fe==null||fe(),q(!0)},onCancel:()=>{q(!1)}}):(fe==null||fe(),q(!0))}),wc=async()=>{if(c){const q=await K.getHandler().getActionStringForModel(n);return(await K.getHandler().getViewsForAction({action:q,context:S})).views.get("form")}return await K.getHandler().getView({model:n,type:"form",context:S})},Tt=({values:q,fields:z,reset:oe,isDefaultGet:ne=!1})=>{const nt={...oe?{}:$.getFieldsValue(!0),...q},fr=lt(nt,z),Mc=Object.keys(z).map(hr=>{const Ec=fr[hr]!==void 0?fr[hr]:void 0;return{name:hr,touched:!1,value:Ec}});ne||(Q.current=fr),$.setFields(Mc)},vc=async({fields:q,arch:z})=>{let oe={},ne=!1;if(ue()){oe=(await K.getHandler().readObjects({model:n,ids:[ue()],fields:q,context:S}))[0];const Fe=await K.getHandler().search({params:[["res_model","=",n],["res_id","=",ue()]],fields:["id","name"],context:ve(),model:"ir.attachment"});De==null||De(Fe)}else De==null||De([]),oe=await be(q),ne=!0;return{values:oe,defaultGetCalled:ne}},io=async q=>{const{callOnSubmitSucceed:z=!0}=q||{};if(ue()){const oe=Jt({source:re.current,target:Ee(E),fields:E});await K.getHandler().update({model:n,id:ue(),values:{...oe,...D},fields:E,context:{...S,..._==null?void 0:_.context}}),re.current=Ee(E)}else{const oe=Ee(E),ne=await K.getHandler().create({model:n,values:{...oe,...D},fields:E,context:{...S,..._==null?void 0:_.context}});Y.current=ne,re.current=oe}m&&await m([ue()]),!w&&z&&(ce==null||ce(ue(),$e(),ie()))},Sc=async q=>{const{callOnSubmitSucceed:z=!0}=q||{};!w&&z&&(ce==null||ce(ue(),$e(),ie()))},Pt=async q=>{let z=!1;const{callOnSubmitSucceed:oe=!0}=q||{};if(R.current=!0,I(void 0),Z.current&&!xe()&&ue()&&oe){R.current=!1,de==null||de(!1),ce==null||ce(ue(),$e(),ie(),Z.current),Z.current=!1;const ne=ue();return u&&(Y.current=void 0,Tt({values:{},fields:E,reset:!0})),{succeed:!0,id:ne}}if(!xe()&&ue()&&oe)return R.current=!1,de==null||de(!1),fe==null||fe(),{succeed:!0,id:ue()};if(await no())return R.current=!1,Qr(T),{succeed:!1,id:ue()};F(!0),se==null||se(!0);try{g==="api"?await io(q):await Sc(q),u&&(Y.current=void 0,Tt({values:{},fields:E,reset:!0})),await rt({forceRefresh:!0}),z=!0,p.message.success(x("savedRegisters"))}catch(ne){R.current=!1,F(!1),se==null||se(!1),Pe==null||Pe(ne),p.message.error(x("errorWhileSavingForm")),I(ne!=null&&ne.message?ne.message:ne)}finally{R.current=!1,se==null||se(!1),F(!1)}return{succeed:z,id:ue()}},Bt=({fields:q,arch:z,values:oe})=>{var Fe;const ne=new ae.Form(q);ne.parse(z,{readOnly:h,values:si({...oe,...Se()},q)}),A(ne),ne.string&&ne.string!==Ye&&(te==null||te(ne.string)),J&&ne.string&&((Fe=J.setTitle)==null||Fe.call(J,ne.string))},ur=async({elementHasLostFocus:q=!1})=>{if(R.current)return;const z=Jt({source:Q.current,target:Ee(E),fields:E}),oe=Object.keys(z);if(oe.length!==0){if(fi({changedFields:oe,formOoui:_,types:["text","codeeditor","email","url","char","float","float_time","integer","many2one"]})&&q!==!0)return;{const ne=lt($.getFieldsValue(!0),E);Q.current=ne,f==null||f(ne),de==null||de(!0),bc(oe)}}},Cc=Xs(ur,100),bc=async q=>{try{for(let z=0;z<q.length;z+=1){const oe=q[z];await xc(oe)}}catch(z){Le(z)}},xc=async q=>{const z=_==null?void 0:_.onChangeFields[q];if(!z){Bt({fields:E,arch:k,values:Ee(E)});return}const oe=gi({values:{...Ee(E),context:{...S,..._==null?void 0:_.context}},parentValues:Ie==null?void 0:Ie(),onChangeFieldActionArgs:z.args}),ne=await K.getHandler().executeOnChange({model:n,action:z.method,ids:ue()?[ue()]:[],payload:oe,fields:E});if(ne.value){const Fe={...Ee(E),...ne.value};Bt({fields:E,arch:k,values:Fe}),Tt({values:Fe,fields:E,reset:!1})}if(ne.warning&&ne.warning.title&&ne.warning.message&&!le.current){const{title:Fe,message:nt}=ne.warning;le.current=!0,ki(Fe,nt,()=>{le.current=!1})}if(ne.domain&&Object.keys(ne.domain).length>0){const Fe=hi({fieldsDomain:ne.domain,fields:E});Bt({fields:Fe,arch:k,values:Ee(Fe)}),W(Fe)}};async function Tc({action:q,context:z}){const oe=await K.getHandler().execute({model:n,action:q,payload:[ue()],context:{...z,..._==null?void 0:_.context,...S}});if(typeof oe=="object"&&oe!==null&&Object.keys(oe).length===0&&w)ce==null||ce(ue(),$e(),ie());else if(oe.type&&oe.type==="ir.actions.act_window_close")ce==null||ce(ue(),$e(),ie());else if(oe.type){let ne={};oe.context&&(ne=ae.parseContext({context:oe.context,fields:E,values:$e()})),await ao({actionData:oe,context:{...z,...ne}})}else await rt({forceRefresh:!0})}async function Fc({action:q}){const z=await K.getHandler().executeWorkflow({model:n,action:q,payload:ue()});z.type&&z.type==="ir.actions.act_window_close"?ce==null||ce(ue(),$e(),ie()):await rt({forceRefresh:!0})}async function Oc({action:q,context:z}){const oe=(await K.getHandler().readObjects({model:"ir.actions.actions",ids:[parseInt(q)],context:S}))[0];await ao({actionData:oe,context:z})}async function ao({actionData:q,context:z}){const{closeParent:oe}=await(_e==null?void 0:_e({actionData:q,fields:E,values:$e(),context:{...S,..._==null?void 0:_.context,...z},onRefreshParentValues:()=>{rt({forceRefresh:!0})}}))||{};!b&&oe&&(ce==null||ce(ue(),$e(),ie()))}function _c(){ur({elementHasLostFocus:!0})}async function Dc({type:q,action:z,context:oe}){if(q==="cancel"){fe==null||fe();return}if(await no()){Qr(T);return}try{(xe()||ue()===void 0)&&(g==="2many"?(await io({callOnSubmitSucceed:!1}),Z.current=!0):await Pt({callOnSubmitSucceed:!1}));const ne={...oe,...me()};q==="object"?await Tc({action:z,context:ne}):q==="workflow"?await Fc({action:z}):q==="action"&&await Oc({action:z,context:ne})}catch(ne){Le(ne)}}const kc=()=>!_&&!P?e.jsx(p.Spin,{}):!n&&!y||!V?null:e.jsx(e.Fragment,{children:e.jsx($o,{getValues:$e,getPlainValues:ee,getFields:je,domain:O,activeId:s,activeModel:n,setFieldValue:ze,getFieldValue:tt,executeButtonAction:Dc,getContext:ve,submitForm:Pt,fetchValues:rt,formHasChanges:xe,elementHasLostFocus:_c,children:e.jsx(p.Form,{form:$,onFieldsChange:()=>{Cc({elementHasLostFocus:!1})},component:!1,children:_&&e.jsx(Zt,{container:_.container,responsiveBehaviour:we})})})}),Vc=()=>e.jsxs(e.Fragment,{children:[e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),disabled:C,onClick:async()=>{await so()},children:"Cancel"}),e.jsx(p.Button,{disabled:C||h,loading:C,icon:e.jsx(H.CheckOutlined,{}),onClick:async()=>{await Pt()},type:"primary",children:"OK"})]})})]});return V?e.jsx(Yt.default,{bounds:!0,onResize:q=>{var z;X((z=q.bounds)==null?void 0:z.width)},children:({measureRef:q})=>e.jsxs("div",{className:"pb-2",ref:q,children:[P&&e.jsx(Wi,{className:"mt-5 mb-10",error:P}),kc(),a&&Vc()]})}):null}const ut=l.forwardRef(Ui),ft=t=>{const{visible:r,id:n,title:s,buttonModal:o=!1,onCancel:i,isMenuAction:a=!1,actionData:c,...f}=t,{modalWidth:d}=Ft(),[h,u]=l.useState(s),[g,v]=l.useState(!1),[y,m]=l.useState();l.useEffect(()=>{a&&w()},[c,a]);async function w(){const{action_id:b,res_id:M,action_type:D,view_id:L}=c,x=await K.getHandler().isShortcutFavorite({action_id:b,action_type:D,view_id:L,res_id:M||!1});v(x!==!1),x!==!1&&m(x)}async function S(){if(g&&y)await K.getHandler().removeFavourite({shortcut_id:y});else{const{action_id:b,res_id:M,action_type:D,view_id:L}=c;await K.getHandler().addFavourite({action_id:b,action_type:D,view_id:L,res_id:M||!1})}v(!g)}function O(){return e.jsxs(p.Row,{align:"middle",children:[e.jsx(p.Col,{children:e.jsx(p.Button,{type:g?"primary":"default",icon:g?e.jsx(H.StarFilled,{style:{color:"white"}}):e.jsx(H.StarOutlined,{}),style:{width:30},onClick:S})}),e.jsx(p.Col,{style:{paddingLeft:10},children:h})]})}const V=d*.95;return e.jsx(Vi,{setTitle:u,children:e.jsx(p.Modal,{title:a?O():h,centered:!0,width:d,open:r,footer:null,destroyOnClose:!0,onCancel:i,maskClosable:!1,children:e.jsx(ut,{id:n,showFooter:!0,insideButtonModal:o,onCancel:i,parentWidth:V,...f})})})},Gi=t=>e.jsx(ge,{...t,layout:"vertical",children:e.jsx(p.DatePicker.RangePicker,{allowEmpty:[!0,!0],format:"DD/MM/YYYY"})}),ji=t=>{const{ooui:r,showLabel:n=!1}=t,{label:s,id:o}=r,i=[new ae.Field({name:o+"#date",label:""}),new ae.Field({name:o+"#time",label:""})];return e.jsxs(e.Fragment,{children:[n&&e.jsx(yt,{ooui:new ae.Label({name:o+"_label",string:s,help:r.tooltip,fieldForLabel:o}),align:"left"}),e.jsxs(p.Row,{align:"bottom",className:"p-0",children:[e.jsx(p.Col,{className:"mr-2",children:e.jsx(ge,{...t,ooui:i[0],showLabel:!1,children:e.jsx(p.DatePicker.RangePicker,{className:"w-60",allowEmpty:[!0,!0],format:"DD/MM/YYYY"})})}),e.jsx(p.Col,{children:e.jsx(ge,{...t,ooui:i[1],showLabel:!1,children:e.jsx(p.TimePicker.RangePicker,{className:"w-60",allowEmpty:[!0,!0],format:"HH:mm"})})})]})]})},{useToken:zi}=p.theme,Xt=t=>{const{ooui:r}=t,{id:n,decimalDigits:s,readOnly:o,required:i}=r,{token:a}=zi(),c=i&&!o?{backgroundColor:a.colorPrimaryBg}:void 0,f=l.useContext(Ve),{elementHasLostFocus:d}=f||{};return e.jsx(ge,{required:i,type:"number",...t,children:e.jsx(p.InputNumber,{disabled:o,className:"w-full",style:c,id:n,precision:s,formatter:h=>`${h}`.replace(/[^0-9\.\-]+/g,""),defaultValue:0,decimalSeparator:".",onBlur:d})})},{useToken:Ji}=p.theme,Ct=t=>{const{ooui:r,onChange:n}=t,{id:s,readOnly:o,required:i}=r,{token:a}=Ji(),c=i&&!o?{backgroundColor:a.colorPrimaryBg}:void 0,f=l.useContext(Ve),{elementHasLostFocus:d}=f||{};return e.jsx(ge,{required:i,type:"number",...t,children:e.jsx(p.InputNumber,{id:s,className:"w-full ",disabled:o,formatter:h=>h===void 0||typeof h!="number"||isNaN(h)?"":`${Math.trunc(h)}`.replace(/[^0-9\-]+/g,""),onChange:h=>{const u=h;n==null||n(u)},defaultValue:0,onBlur:d,precision:0,style:c})})};function Zi(t){const{ooui:r,showLabel:n}=t,{id:s,label:o,tooltip:i}=r,a=r instanceof ae.Integer?Ct:Xt,c=f=>e.jsx(a,{ooui:{...r,id:s+f,label:"",tooltip:void 0},layout:"vertical"});return e.jsxs(e.Fragment,{children:[n&&e.jsx(yt,{ooui:new ae.Label({name:s+"_label",string:o,help:i,fieldForLabel:s}),align:"left"}),e.jsxs(p.Row,{align:"bottom",className:"mt-0",wrap:!1,children:[e.jsx(p.Col,{children:c("#from")}),e.jsx(p.Col,{className:"pb-1",children:e.jsx("span",{className:"pl-2 pr-2 h-full",children:" - "})}),e.jsx(p.Col,{children:c("#to")})]})]})}const{defaultAlgorithm:Xi,defaultSeed:Qi}=p.theme,Ri=Xi(Qi),{Option:ea}=p.Select,ta=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(ge,{required:n,type:"any",...t,children:e.jsx(ra,{...t})})},ra=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,required:a}=r,c=Array.from(o.entries()),f=c&&c.length&&c.filter(u=>{const[g]=u;return s?!s.includes(g):!0}).map(u=>{const[g,v]=u;return e.jsx(ea,{value:v,children:v},g)}),d=a&&!i?na:p.Select;function h(u){const g=u.map(v=>{const y=c.find(([m,w])=>v===w);return y&&y[0]});if(g.length===0){n==null||n(void 0);return}n==null||n(g)}return e.jsx(d,{disabled:i,onChange:h,value:s==null?void 0:s.map(u=>o.get(u)),mode:"multiple",showArrow:!0,children:f})},na=mt.default(p.Select)`
|
|
19
|
+
`)!==-1){const{message:o,type:i,title:a}=Or(t);n=e.jsx(Ht.Interweave,{content:`${a}<br />${o}`}),s=i}else n=t.message?JSON.stringify(t.message):JSON.stringify(t);return e.jsx(p.Alert,{className:r,message:n,type:s,banner:!0})},qi=800;function Ui(t,r){const{model:n,id:s,onCancel:o,onSubmitSucceed:i,showFooter:a=!1,getDataFromAction:c=!1,onFieldsChange:f,onSubmitError:d,readOnly:h=!1,mustClearAfterSave:u=!1,submitMode:g="api",values:v,formView:y,postSaveAction:m,insideButtonModal:w=!1,parentContext:S={},actionDomain:O,visible:V=!0,rootForm:b=!1,defaultValues:M,forcedValues:D={},parentWidth:L}=t,{t:x,lang:T}=l.useContext(pe),[C,F]=l.useState(!1),[P,I]=l.useState(),[_,A]=l.useState(),[$]=p.Form.useForm(),[k,B]=l.useState(),[E,W]=l.useState(),J=l.useContext(Rr),[G,X]=l.useState(),[j,N]=l.useState(!1),Y=l.useRef(),re=l.useRef({}),Q=l.useRef({}),le=l.useRef(!1),R=l.useRef(!1),Z=l.useRef(!1),we=(L!==void 0?L:G)<qi,Me=l.useContext(Ve),{activeId:Oe,getPlainValues:Ie}=Me||{},Ne=l.useContext(We),{setFormIsSaving:se=void 0,setFormHasChanges:de=void 0,setCurrentId:Ae=void 0,setFormIsLoading:ye=void 0,setAttachments:De=void 0,title:Ye=void 0,setTitle:te=void 0}=(b?Ne:{})||{},Te=l.useContext(dt),{processAction:_e,globalValues:ke}=Te||{};l.useImperativeHandle(r,()=>({submitForm:Pt,getFields:je,getValues:$e,getPlainValues:ee,getContext:ve,fetchValues:rt,cancelUnsavedChanges:so,clearAndReload:()=>{Y.current=void 0,A(void 0),oo()}})),l.useEffect(()=>{if(I(void 0),!(!n&&!y)){if(!V){Y.current=void 0,A(void 0);return}(s===void 0&&E||s!==void 0&&E&&s<0)&&(Y.current=void 0,A(void 0)),oo()}},[s,n,v,y,V]),l.useEffect(()=>{j&&(ur({elementHasLostFocus:!0}),N(!1))},[j]);const ce=(q,z,oe,ne)=>{de==null||de(!1),se==null||se(!1),i==null||i(q,z,oe,ne),Ae==null||Ae(q)},fe=()=>{se==null||se(!1),o==null||o()},Pe=q=>{se==null||se(!1),d==null||d(q)};function ue(){return s||Y.current}function je(){return E}function $e(){const q={...Ee(E),...Se()};for(const z in q)q[z]===void 0&&delete q[z];return q}function ee(){const q=$e(),z=je();let oe={};return Object.keys(q).forEach(ne=>{const Fe=q[ne];z[ne]&&z[ne].type==="many2one"&&Fe&&Array.isArray(Fe)&&Fe.length===2?oe[ne]=Fe[0]:z[ne]&&(z[ne].type==="one2many"||z[ne].type==="many2many")&&Fe&&Fe.items?oe[ne]=Fe.items.filter(nt=>nt.operation!=="pendingRemove").map(nt=>nt.id):oe[ne]=Fe}),oe}function ie(){const q={...Ee(E)};for(const z in q)q[z]===void 0&&delete q[z];return q}function ve(){return{...S,..._==null?void 0:_.context}}function me(){return ue()?{active_id:ue(),active_ids:[ue()]}:{}}function Se(){return{id:ue(),active_id:ue(),active_ids:[ue()],parent_id:Oe,...ke}}const be=async q=>{const z=ue()?_==null?void 0:_.context:{};return await K.getHandler().defaultGet({model:n,fields:q,context:{...S,...z},extraValues:M})},xe=()=>Object.keys(Jt({source:re.current,target:Ee(E),fields:E})).length!==0,Ee=q=>{const z=$.getFieldsValue(!0);return lt(z,q)},ze=(q,z)=>{Tt({values:{...lt($.getFieldsValue(!0),E),[q]:z},fields:E,reset:!1})},tt=q=>$.getFieldsValue(!0)[q];async function no(){try{return await $.validateFields(),!1}catch{return p.message.error(x("fillRequiredFields")),!0}}const oo=async()=>{I(void 0),ye==null||ye(!0);let q;try{y?q={arch:y.arch,fields:y.fields}:q=await wc();const{fields:z,arch:oe}=q;W(z),B(oe),await rt({fields:z,arch:oe})}catch(z){I(z!=null&&z.message?z.message+z.stack:z),ye==null||ye(!1)}},rt=async q=>{let z,oe,ne,Fe;ye==null||ye(!0),I(void 0),q!=null&&q.fields?(oe=q.fields,ne=q.arch):(oe=E,ne=k),v&&(q==null?void 0:q.forceRefresh)!==!0?z=v:{values:z,defaultGetCalled:Fe}=await vc({fields:oe,arch:ne}),O&&(z={...pi(O),...z}),re.current=lt(z,oe),Tt({values:z,fields:oe,reset:!0,isDefaultGet:Fe}),Bt({fields:oe,arch:ne,values:z}),ye==null||ye(!1),de==null||de(!1),Fe&&N(!0)},so=async()=>new Promise(async q=>{xe()?vt({lang:T,onOk:()=>{fe==null||fe(),q(!0)},onCancel:()=>{q(!1)}}):(fe==null||fe(),q(!0))}),wc=async()=>{if(c){const q=await K.getHandler().getActionStringForModel(n);return(await K.getHandler().getViewsForAction({action:q,context:S})).views.get("form")}return await K.getHandler().getView({model:n,type:"form",context:S})},Tt=({values:q,fields:z,reset:oe,isDefaultGet:ne=!1})=>{const nt={...oe?{}:$.getFieldsValue(!0),...q},fr=lt(nt,z),Mc=Object.keys(z).map(hr=>{const Ec=fr[hr]!==void 0?fr[hr]:void 0;return{name:hr,touched:!1,value:Ec}});ne||(Q.current=fr),$.setFields(Mc)},vc=async({fields:q,arch:z})=>{let oe={},ne=!1;if(ue()){oe=(await K.getHandler().readObjects({model:n,ids:[ue()],fields:q,context:S}))[0];const Fe=await K.getHandler().search({params:[["res_model","=",n],["res_id","=",ue()]],fields:["id","name"],context:ve(),model:"ir.attachment"});De==null||De(Fe)}else De==null||De([]),oe=await be(q),ne=!0;return{values:oe,defaultGetCalled:ne}},io=async q=>{const{callOnSubmitSucceed:z=!0}=q||{};if(ue()){const oe=Jt({source:re.current,target:Ee(E),fields:E});await K.getHandler().update({model:n,id:ue(),values:{...oe,...D},fields:E,context:{...S,..._==null?void 0:_.context}}),re.current=Ee(E)}else{const oe=Ee(E),ne=await K.getHandler().create({model:n,values:{...oe,...D},fields:E,context:{...S,..._==null?void 0:_.context}});Y.current=ne,re.current=oe}m&&await m([ue()]),!w&&z&&(ce==null||ce(ue(),$e(),ie()))},Sc=async q=>{const{callOnSubmitSucceed:z=!0}=q||{};!w&&z&&(ce==null||ce(ue(),$e(),ie()))},Pt=async q=>{let z=!1;const{callOnSubmitSucceed:oe=!0}=q||{};if(R.current=!0,I(void 0),Z.current&&!xe()&&ue()&&oe){R.current=!1,de==null||de(!1),ce==null||ce(ue(),$e(),ie(),Z.current),Z.current=!1;const ne=ue();return u&&(Y.current=void 0,Tt({values:{},fields:E,reset:!0})),{succeed:!0,id:ne}}if(!xe()&&ue()&&oe)return R.current=!1,de==null||de(!1),fe==null||fe(),{succeed:!0,id:ue()};if(await no())return R.current=!1,Qr(T),{succeed:!1,id:ue()};F(!0),se==null||se(!0);try{g==="api"?await io(q):await Sc(q),u&&(Y.current=void 0,Tt({values:{},fields:E,reset:!0})),await rt({forceRefresh:!0}),z=!0,p.message.success(x("savedRegisters"))}catch(ne){R.current=!1,F(!1),se==null||se(!1),Pe==null||Pe(ne),p.message.error(x("errorWhileSavingForm")),I(ne!=null&&ne.message?ne.message:ne)}finally{R.current=!1,se==null||se(!1),F(!1)}return{succeed:z,id:ue()}},Bt=({fields:q,arch:z,values:oe})=>{var Fe;const ne=new ae.Form(q);ne.parse(z,{readOnly:h,values:si({...oe,...Se()},q)}),A(ne),ne.string&&ne.string!==Ye&&(te==null||te(ne.string)),J&&ne.string&&((Fe=J.setTitle)==null||Fe.call(J,ne.string))},ur=async({elementHasLostFocus:q=!1})=>{if(R.current)return;const z=Jt({source:Q.current,target:Ee(E),fields:E}),oe=Object.keys(z);if(oe.length!==0){if(fi({changedFields:oe,formOoui:_,types:["text","codeeditor","email","url","char","float","float_time","integer","many2one"]})&&q!==!0)return;{const ne=lt($.getFieldsValue(!0),E);Q.current=ne,f==null||f(ne),de==null||de(!0),bc(oe)}}},Cc=Xs(ur,100),bc=async q=>{try{for(let z=0;z<q.length;z+=1){const oe=q[z];await xc(oe)}}catch(z){Le(z)}},xc=async q=>{const z=_==null?void 0:_.onChangeFields[q];if(!z){Bt({fields:E,arch:k,values:Ee(E)});return}const oe=gi({values:{...Ee(E),context:{...S,..._==null?void 0:_.context}},parentValues:Ie==null?void 0:Ie(),onChangeFieldActionArgs:z.args}),ne=await K.getHandler().executeOnChange({model:n,action:z.method,ids:ue()?[ue()]:[],payload:oe,fields:E});if(ne.value){const Fe={...Ee(E),...ne.value};Bt({fields:E,arch:k,values:Fe}),Tt({values:Fe,fields:E,reset:!1})}if(ne.warning&&ne.warning.title&&ne.warning.message&&!le.current){const{title:Fe,message:nt}=ne.warning;le.current=!0,ki(Fe,nt,()=>{le.current=!1})}if(ne.domain&&Object.keys(ne.domain).length>0){const Fe=hi({fieldsDomain:ne.domain,fields:E});Bt({fields:Fe,arch:k,values:Ee(Fe)}),W(Fe)}};async function Tc({action:q,context:z}){const oe=await K.getHandler().execute({model:n,action:q,payload:[ue()],context:{...z,..._==null?void 0:_.context,...S}});if(typeof oe=="object"&&oe!==null&&Object.keys(oe).length===0&&w)ce==null||ce(ue(),$e(),ie());else if(oe.type&&oe.type==="ir.actions.act_window_close")ce==null||ce(ue(),$e(),ie());else if(oe.type){let ne={};oe.context&&(ne=ae.parseContext({context:oe.context,fields:E,values:$e()})),await ao({actionData:oe,context:{...z,...ne}})}else await rt({forceRefresh:!0})}async function Fc({action:q}){const z=await K.getHandler().executeWorkflow({model:n,action:q,payload:ue()});z.type&&z.type==="ir.actions.act_window_close"?ce==null||ce(ue(),$e(),ie()):await rt({forceRefresh:!0})}async function Oc({action:q,context:z}){const oe=(await K.getHandler().readObjects({model:"ir.actions.actions",ids:[parseInt(q)],context:S}))[0];await ao({actionData:oe,context:z})}async function ao({actionData:q,context:z}){const{closeParent:oe}=await(_e==null?void 0:_e({actionData:q,fields:E,values:$e(),context:{...S,..._==null?void 0:_.context,...z},onRefreshParentValues:()=>{rt({forceRefresh:!0})}}))||{};!b&&oe&&(ce==null||ce(ue(),$e(),ie()))}function _c(){ur({elementHasLostFocus:!0})}async function Dc({type:q,action:z,context:oe}){if(q==="cancel"){fe==null||fe();return}if(await no()){Qr(T);return}try{(xe()||ue()===void 0)&&(g==="2many"?(await io({callOnSubmitSucceed:!1}),Z.current=!0):await Pt({callOnSubmitSucceed:!1}));const ne={...oe,...me()};q==="object"?await Tc({action:z,context:ne}):q==="workflow"?await Fc({action:z}):q==="action"&&await Oc({action:z,context:ne})}catch(ne){Le(ne)}}const kc=()=>!_&&!P?e.jsx(p.Spin,{}):!n&&!y||!V?null:e.jsx(e.Fragment,{children:e.jsx($o,{getValues:$e,getPlainValues:ee,getFields:je,domain:O,activeId:s,activeModel:n,setFieldValue:ze,getFieldValue:tt,executeButtonAction:Dc,getContext:ve,submitForm:Pt,fetchValues:rt,formHasChanges:xe,elementHasLostFocus:_c,children:e.jsx(p.Form,{form:$,onFieldsChange:()=>{Cc({elementHasLostFocus:!1})},component:!1,children:_&&e.jsx(Zt,{container:_.container,responsiveBehaviour:we})})})}),Vc=()=>e.jsxs(e.Fragment,{children:[e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),disabled:C,onClick:async()=>{await so()},children:"Cancel"}),e.jsx(p.Button,{disabled:C||h,loading:C,icon:e.jsx(H.CheckOutlined,{}),onClick:async()=>{await Pt()},type:"primary",children:"OK"})]})})]});return V?e.jsx(Yt.default,{bounds:!0,onResize:q=>{var z;X((z=q.bounds)==null?void 0:z.width)},children:({measureRef:q})=>e.jsxs("div",{className:"pb-2",ref:q,children:[P&&e.jsx(Wi,{className:"mt-5 mb-10",error:P}),kc(),a&&Vc()]})}):null}const ut=l.forwardRef(Ui),ft=t=>{const{visible:r,id:n,title:s,buttonModal:o=!1,onCancel:i,isMenuAction:a=!1,actionData:c,...f}=t,{modalWidth:d}=Ft(),[h,u]=l.useState(s),[g,v]=l.useState(!1),[y,m]=l.useState();l.useEffect(()=>{a&&w()},[c,a]);async function w(){const{action_id:b,res_id:M,action_type:D,view_id:L}=c,x=await K.getHandler().isShortcutFavorite({action_id:b,action_type:D,view_id:L,res_id:M||!1});v(x!==!1),x!==!1&&m(x)}async function S(){if(g&&y)await K.getHandler().removeFavourite({shortcut_id:y});else{const{action_id:b,res_id:M,action_type:D,view_id:L}=c;await K.getHandler().addFavourite({action_id:b,action_type:D,view_id:L,res_id:M||!1})}v(!g)}function O(){return e.jsxs(p.Row,{align:"middle",children:[e.jsx(p.Col,{children:e.jsx(p.Button,{type:g?"primary":"default",icon:g?e.jsx(H.StarFilled,{style:{color:"white"}}):e.jsx(H.StarOutlined,{}),style:{width:30},onClick:S})}),e.jsx(p.Col,{style:{paddingLeft:10},children:h})]})}const V=d*.95;return e.jsx(Vi,{setTitle:u,children:e.jsx(p.Modal,{title:a?O():h,centered:!0,width:d,open:r,footer:null,destroyOnClose:!0,onCancel:i,maskClosable:!1,children:e.jsx(ut,{id:n,showFooter:!0,insideButtonModal:o,onCancel:i,parentWidth:V,...f})})})},Gi=t=>e.jsx(ge,{...t,layout:"vertical",children:e.jsx(p.DatePicker.RangePicker,{allowEmpty:[!0,!0],format:"DD/MM/YYYY"})}),ji=t=>{const{ooui:r,showLabel:n=!1}=t,{label:s,id:o}=r,i=[new ae.Field({name:o+"#date",label:""}),new ae.Field({name:o+"#time",label:""})];return e.jsxs(e.Fragment,{children:[n&&e.jsx(yt,{ooui:new ae.Label({name:o+"_label",string:s,help:r.tooltip,fieldForLabel:o}),align:"left"}),e.jsxs(p.Row,{align:"bottom",className:"p-0",children:[e.jsx(p.Col,{className:"mr-2",children:e.jsx(ge,{...t,ooui:i[0],showLabel:!1,children:e.jsx(p.DatePicker.RangePicker,{className:"w-60",allowEmpty:[!0,!0],format:"DD/MM/YYYY"})})}),e.jsx(p.Col,{children:e.jsx(ge,{...t,ooui:i[1],showLabel:!1,children:e.jsx(p.TimePicker.RangePicker,{className:"w-60",allowEmpty:[!0,!0],format:"HH:mm"})})})]})]})},{useToken:zi}=p.theme,Xt=t=>{const{ooui:r}=t,{id:n,decimalDigits:s,readOnly:o,required:i}=r,{token:a}=zi(),c=i&&!o?{backgroundColor:a.colorPrimaryBg}:void 0,f=l.useContext(Ve),{elementHasLostFocus:d}=f||{};return e.jsx(ge,{required:i,type:"number",...t,children:e.jsx(p.InputNumber,{disabled:o,className:"w-full",style:c,id:n,precision:s,formatter:h=>`${h}`.replace(/[^0-9\.\-]+/g,""),defaultValue:0,decimalSeparator:".",onBlur:d})})},{useToken:Ji}=p.theme,Ct=t=>{const{ooui:r,onChange:n}=t,{id:s,readOnly:o,required:i}=r,{token:a}=Ji(),c=i&&!o?{backgroundColor:a.colorPrimaryBg}:void 0,f=l.useContext(Ve),{elementHasLostFocus:d}=f||{};return e.jsx(ge,{required:i,type:"number",...t,children:e.jsx(p.InputNumber,{id:s,className:"w-full ",disabled:o,formatter:h=>h===void 0?"":typeof h=="string"&&!isNaN(parseFloat(h))?`${Math.trunc(parseFloat(h))}`.replace(/[^0-9\-]+/g,""):typeof h=="number"?`${Math.trunc(h)}`.replace(/[^0-9\-]+/g,""):"",onChange:h=>{const u=h;n==null||n(u)},defaultValue:0,onBlur:d,precision:0,style:c})})};function Zi(t){const{ooui:r,showLabel:n}=t,{id:s,label:o,tooltip:i}=r,a=r instanceof ae.Integer?Ct:Xt,c=f=>e.jsx(a,{ooui:{...r,id:s+f,label:"",tooltip:void 0},layout:"vertical"});return e.jsxs(e.Fragment,{children:[n&&e.jsx(yt,{ooui:new ae.Label({name:s+"_label",string:o,help:i,fieldForLabel:s}),align:"left"}),e.jsxs(p.Row,{align:"bottom",className:"mt-0",wrap:!1,children:[e.jsx(p.Col,{children:c("#from")}),e.jsx(p.Col,{className:"pb-1",children:e.jsx("span",{className:"pl-2 pr-2 h-full",children:" - "})}),e.jsx(p.Col,{children:c("#to")})]})]})}const{defaultAlgorithm:Xi,defaultSeed:Qi}=p.theme,Ri=Xi(Qi),{Option:ea}=p.Select,ta=t=>{const{ooui:r}=t,{required:n}=r;return e.jsx(ge,{required:n,type:"any",...t,children:e.jsx(ra,{...t})})},ra=t=>{const{ooui:r,onChange:n,value:s}=t,{selectionValues:o,readOnly:i,required:a}=r,c=Array.from(o.entries()),f=c&&c.length&&c.filter(u=>{const[g]=u;return s?!s.includes(g):!0}).map(u=>{const[g,v]=u;return e.jsx(ea,{value:v,children:v},g)}),d=a&&!i?na:p.Select;function h(u){const g=u.map(v=>{const y=c.find(([m,w])=>v===w);return y&&y[0]});if(g.length===0){n==null||n(void 0);return}n==null||n(g)}return e.jsx(d,{disabled:i,onChange:h,value:s==null?void 0:s.map(u=>o.get(u)),mode:"multiple",showArrow:!0,children:f})},na=mt.default(p.Select)`
|
|
20
20
|
&.ant-select:not(.ant-select-customize-input) .ant-select-selector {
|
|
21
21
|
background-color: ${Ri.colorPrimaryBg};
|
|
22
22
|
}
|