@gisce/react-ooui 1.1.19 → 1.1.20

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.
@@ -112,7 +112,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
112
112
  .ant-progress-text {
113
113
  display: none;
114
114
  }
115
- `,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx(interweave.Interweave,{content:e==null?void 0:e.replace(/(?:\r\n|\r|\n)/g,"<br>")}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:p={},onChangeSort:m,sorter:h,onFetchChildrenForRecord:v,childField:C}=e,[I,g]=React.useState([]),[x,y]=React.useState([]),O=React.useRef(!1),b=React.useRef(null),{t:E}=React.useContext(LocaleContext),w=React.useRef(t);React.useEffect(()=>{b.current=getTree(r);const L=getTableColumns(b.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});y(L)},[r]),React.useEffect(()=>{O.current=!1;const L=getTableItems(b.current,a);g(L),w.current=t},[a]);const S=(n-1)*w.current+1,T=S-1+I.length,M=o===void 0?null:o===0?E("no_results"):E("summary").replace("{from}",S==null?void 0:S.toString()).replace("{to}",T==null?void 0:T.toString()).replace("{total}",o==null?void 0:o.toString()),N=()=>!u||r.isExpandable||l?null:o===void 0?jsxRuntime.jsx(antd.Spin,{}):jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:w.current,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:M})]});function k(){var G;const $=b.current.columns.filter(z=>z.sum!==void 0).map(z=>({label:z.sum,field:z.id}));if(!$||$.length===0)return null;let j=[],U=((G=d==null?void 0:d.selectedRowKeys)==null?void 0:G.length)>0?I.filter(z=>d==null?void 0:d.selectedRowKeys.includes(z.id)):I;return $.forEach(z=>{const W=U.reduce((K,V)=>V[z.field]&&!isNaN(V[z.field])?K+V[z.field]:K,0);j.push(`${z.label}: ${Math.round(W*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:j.join(", ")})}let D,B=f;if(b.current!==null){D=calculateColumnsWidth(x,I,600);const $=b.current;f&&$.columns.some(j=>j.sum!==void 0)&&(B=f-30)}return b.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[N(),jsxRuntime.jsx(reactFormigaTable.Table,{height:B,columns:D.columns,dataSource:I,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:L=>{if(p[L.id])return{color:p[L.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:m,sorter:h,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:C}:void 0}),k()]})}function SearchTree(e,n){const{model:t,formView:o,treeView:r,onRowClicked:a,nameSearch:s,treeScrollY:l,domain:c=[],visible:u=!0,rootTree:d=!1,parentContext:f={},onChangeSelectedRowKeys:p}=e,[m,h]=React.useState(!1),[v,C]=React.useState(!1),I=React.useRef(!1),[g,x]=React.useState(),[y,O]=React.useState(),[b,E]=React.useState(),[w,S]=React.useState(),[T,M]=React.useState(200),N=React.useRef(),{height:k}=useWindowDimensions(),D=React.useContext(ContentRootContext),{processAction:B}=D||{},L=React.useContext(ActionViewContext),{setResults:$=void 0,setCurrentItemIndex:j=void 0,currentId:U=void 0,results:G=void 0,selectedRowItems:z=void 0,setSelectedRowItems:W=void 0,searchParams:K=[],setSearchParams:V=void 0,searchVisible:H=!0,setSearchVisible:P=void 0,sorter:A=void 0,setSorter:q=void 0,setTotalItems:Y=void 0,setSearchTreeNameSearch:X=void 0,setTreeIsLoading:F=void 0,searchValues:_={},setSearchValues:Z=void 0,limit:J=DEFAULT_SEARCH_LIMIT$1,setLimit:ee=void 0}=(d?L:{})||{},{submit:Q,clear:ie,fetchResults:te,tableRefreshing:ce,searchFilterLoading:ae,searchError:xe,page:Oe,offset:ne,getResults:pe,requestPageChange:he,changeSort:fe,fetchChildrenForRecord:ve,colorsForResults:me,totalItems:_e}=useSearch({model:g,setSearchTreeNameSearch:X,setSelectedRowItems:W,setSearchParams:V,setSearchValues:Z,searchParams:K,setSearchVisible:P,setTreeIsLoading:F,nameSearch:s,searchNameGetDoneRef:I,context:f,formView:b,treeView:y,sorter:A,setSorter:q,setCurrentItemIndex:j,setResultsActionView:$,resultsActionView:G,domain:c,currentId:U,setActionViewTotalItems:Y,limit:J,setLimit:ee});React.useImperativeHandle(n,()=>({refreshResults:()=>{I.current=!1,te()}})),React.useEffect(()=>{!v||u&&(I.current=!1,te())},[Oe,ne,v,u,s]);const be=async()=>{C(!1),h(!0),S(void 0),F==null||F(!0);try{await se(),C(!0)}catch(Re){S(Re)}finally{h(!1),F==null||F(!1)}},se=async()=>{x(t);let Re=o;o||(Re=await ConnectionProvider.getHandler().getView({model:t,type:"form",context:f}));let we=r;r||(we=await ConnectionProvider.getHandler().getView({model:t,type:"tree",context:f})),E(Re),O(we)};React.useEffect(()=>{be()},[t]);const ue=Re=>{ee==null||ee(Re)},Ce=async Re=>{const{id:we}=Re;N.current||(N.current=await ConnectionProvider.getHandler().treeButOpen({id:y.view_id,model:g,context:f}));const Ee=N.current[0][2];await(B==null?void 0:B({actionData:Ee,fields:y.fields,values:{active_id:we,...Re},context:f}))},Ie=async Re=>{const{id:we}=Re;if(y!=null&&y.isExpandable){try{await Ce(Re)}catch(Ee){showDialog$8(Ee)}return}a({id:we,model:g,formView:b,treeView:y})};function ge(Re){const we=pe().filter(Ee=>Re.includes(Ee.id));W==null||W(we),p==null||p(Re)}function Se(){return y!=null&&y.isExpandable?k-160:k-(T+210)}const Te=()=>!y||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchFilter,{fields:{...y.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,y.search_fields]),onClear:ie,limit:J,offset:ne,isSearching:ae,onSubmit:Q,onLimitChange:ue,setSearchFilterHeight:M,searchError:xe,searchVisible:H,searchValues:_}),jsxRuntime.jsx(Tree,{total:_e,limit:J,page:Oe,treeView:y,results:pe(),onRequestPageChange:he,loading:ce,onRowClicked:Ie,scrollY:l||Se(),colorsForResults:me,rowSelection:{selectedRowKeys:z==null?void 0:z.map(Re=>Re.id),onChange:ge},sorter:A,onChangeSort:fe,onFetchChildrenForRecord:y.isExpandable?ve:void 0,childField:y.field_parent})]}),Fe=w||xe;return Fe?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Fe,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:u?{}:{display:"none"},children:m?jsxRuntime.jsx(antd.Spin,{}):Te()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:p}=React.useContext(LocaleContext),[m,h]=React.useState([]),v=async()=>{await new Promise(x=>setTimeout(x,5)),t()},C=async x=>{const{id:y}=x;o([y])};function I(){if(m.length===0){v();return}o(m)}const g=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:C,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:x=>{h(x)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:p("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{I()},type:"primary",children:p("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:p("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:p("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:g()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:x=>{u(!1),v(),o([x])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,p]=React.useState(!1),[m,h]=React.useState(!1),[v,C]=React.useState(!1),[I,g]=React.useState(),x=React.useRef(!1),[y,O]=React.useState(""),b=React.useRef(),E=React.useContext(FormContext$1),{domain:w,getValues:S,getFields:T,getContext:M,setOriginalValue:N,elementHasLostFocus:k}=E||{},D=React.useRef([]),[B,L]=React.useState([]),$=n&&n[0]||void 0,j=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&n&&K(n)},[n]),React.useEffect(()=>{$&&j.length===0?K($):$&&j.length>0?O(j):!$&&!j&&O(b.current||"")},[n]);const U=A=>{t==null||t(A),k==null||k()},G=A=>{b.current=A.target.value,U([void 0,""])},z=async()=>{if(!v&&y!==j){if(await new Promise(A=>setTimeout(A,100)),x.current){U([void 0,""]);return}C(!0);try{if(D.current&&D.current.length>0)W(b.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:b.current,context:{...M==null?void 0:M(),...l}});A.length===1?(b.current=void 0,U(A[0])):W(b.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},W=async A=>{if(await V(),D.current&&D.current.length>0){const q=await ConnectionProvider.getHandler().searchAllIds({params:D.current,model:a,context:{...M==null?void 0:M(),...l},totalItems:2});q.length===1?K(q[0],!0):(g(A),p(!0));return}g(A),p(!0)},K=async(A,q)=>{C(!0);try{const Y=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...M==null?void 0:M(),...l}});U([A,Y[0][1]]),q&&N(o.id,[A,Y[0][1]])}catch(Y){showDialog$3(Y)}finally{C(!1)}};async function V(){u&&(D.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:T(),values:S()}),fields:T(),context:M()})),w&&w.length>0&&(D.current=D.current.concat(ooui.transformDomainForChildWidget({domain:w,widgetFieldName:c}))),L(D.current)}async function H(A){A.keyCode===13?(A.preventDefault(),A.stopPropagation(),await z()):A.code==="Backspace"&&$!==void 0&&(A.preventDefault(),A.stopPropagation(),U([void 0,""]))}const P=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(P,{type:"text",value:y,disabled:s,onChange:G,className:d,onBlur:z,onKeyDown:H,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:$,model:a,context:{...M==null?void 0:M(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:$===void 0||j===""||y===void 0,onClick:()=>{h(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{x.current=!0,W(j)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:B,context:{...M==null?void 0:M(),...l},visible:f,nameSearch:$?void 0:I,onSelectValues:A=>{p(!1),K(A[0]),x.current=!1,b.current=void 0},onCloseModal:()=>{p(!1),x.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...M==null?void 0:M(),...l},id:n&&n[0],visible:m,onSubmitSucceed:A=>{h(!1),K(A)},onCancel:()=>{h(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
115
+ `,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx(interweave.Interweave,{content:e==null?void 0:e.replace(/(?:\r\n|\r|\n)/g,"<br>")}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:p={},onChangeSort:m,sorter:h,onFetchChildrenForRecord:v,childField:C}=e,[I,g]=React.useState([]),[x,y]=React.useState([]),O=React.useRef(!1),b=React.useRef(null),{t:E}=React.useContext(LocaleContext),w=React.useRef(t);React.useEffect(()=>{b.current=getTree(r);const L=getTableColumns(b.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});y(L)},[r]),React.useEffect(()=>{O.current=!1;const L=getTableItems(b.current,a);g(L),w.current=t},[a]);const S=(n-1)*w.current+1,T=S-1+I.length,M=o===void 0?null:o===0?E("no_results"):E("summary").replace("{from}",S==null?void 0:S.toString()).replace("{to}",T==null?void 0:T.toString()).replace("{total}",o==null?void 0:o.toString()),N=()=>!u||r.isExpandable||l?null:o===void 0?jsxRuntime.jsx(antd.Spin,{}):jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:w.current===0?o:w.current,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:M})]});function k(){var G;const $=b.current.columns.filter(z=>z.sum!==void 0).map(z=>({label:z.sum,field:z.id}));if(!$||$.length===0)return null;let j=[],U=((G=d==null?void 0:d.selectedRowKeys)==null?void 0:G.length)>0?I.filter(z=>d==null?void 0:d.selectedRowKeys.includes(z.id)):I;return $.forEach(z=>{const W=U.reduce((K,V)=>V[z.field]&&!isNaN(V[z.field])?K+V[z.field]:K,0);j.push(`${z.label}: ${Math.round(W*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:j.join(", ")})}let D,B=f;if(b.current!==null){D=calculateColumnsWidth(x,I,600);const $=b.current;f&&$.columns.some(j=>j.sum!==void 0)&&(B=f-30)}return b.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[N(),jsxRuntime.jsx(reactFormigaTable.Table,{height:B,columns:D.columns,dataSource:I,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:L=>{if(p[L.id])return{color:p[L.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:m,sorter:h,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:C}:void 0}),k()]})}function SearchTree(e,n){const{model:t,formView:o,treeView:r,onRowClicked:a,nameSearch:s,treeScrollY:l,domain:c=[],visible:u=!0,rootTree:d=!1,parentContext:f={},onChangeSelectedRowKeys:p}=e,[m,h]=React.useState(!1),[v,C]=React.useState(!1),I=React.useRef(!1),[g,x]=React.useState(),[y,O]=React.useState(),[b,E]=React.useState(),[w,S]=React.useState(),[T,M]=React.useState(200),N=React.useRef(),{height:k}=useWindowDimensions(),D=React.useContext(ContentRootContext),{processAction:B}=D||{},L=React.useContext(ActionViewContext),{setResults:$=void 0,setCurrentItemIndex:j=void 0,currentId:U=void 0,results:G=void 0,selectedRowItems:z=void 0,setSelectedRowItems:W=void 0,searchParams:K=[],setSearchParams:V=void 0,searchVisible:H=!0,setSearchVisible:P=void 0,sorter:A=void 0,setSorter:q=void 0,setTotalItems:Y=void 0,setSearchTreeNameSearch:X=void 0,setTreeIsLoading:F=void 0,searchValues:_={},setSearchValues:Z=void 0,limit:J=DEFAULT_SEARCH_LIMIT$1,setLimit:ee=void 0}=(d?L:{})||{},{submit:Q,clear:ie,fetchResults:te,tableRefreshing:ce,searchFilterLoading:ae,searchError:xe,page:Oe,offset:ne,getResults:pe,requestPageChange:he,changeSort:fe,fetchChildrenForRecord:ve,colorsForResults:me,totalItems:_e}=useSearch({model:g,setSearchTreeNameSearch:X,setSelectedRowItems:W,setSearchParams:V,setSearchValues:Z,searchParams:K,setSearchVisible:P,setTreeIsLoading:F,nameSearch:s,searchNameGetDoneRef:I,context:f,formView:b,treeView:y,sorter:A,setSorter:q,setCurrentItemIndex:j,setResultsActionView:$,resultsActionView:G,domain:c,currentId:U,setActionViewTotalItems:Y,limit:J,setLimit:ee});React.useImperativeHandle(n,()=>({refreshResults:()=>{I.current=!1,te()}})),React.useEffect(()=>{!v||u&&(I.current=!1,te())},[Oe,ne,v,u,s]);const be=async()=>{C(!1),h(!0),S(void 0),F==null||F(!0);try{await se(),C(!0)}catch(Re){S(Re)}finally{h(!1),F==null||F(!1)}},se=async()=>{x(t);let Re=o;o||(Re=await ConnectionProvider.getHandler().getView({model:t,type:"form",context:f}));let we=r;r||(we=await ConnectionProvider.getHandler().getView({model:t,type:"tree",context:f})),E(Re),O(we)};React.useEffect(()=>{be()},[t]);const ue=Re=>{ee==null||ee(Re)},Ce=async Re=>{const{id:we}=Re;N.current||(N.current=await ConnectionProvider.getHandler().treeButOpen({id:y.view_id,model:g,context:f}));const Ee=N.current[0][2];await(B==null?void 0:B({actionData:Ee,fields:y.fields,values:{active_id:we,...Re},context:f}))},Ie=async Re=>{const{id:we}=Re;if(y!=null&&y.isExpandable){try{await Ce(Re)}catch(Ee){showDialog$8(Ee)}return}a({id:we,model:g,formView:b,treeView:y})};function ge(Re){const we=pe().filter(Ee=>Re.includes(Ee.id));W==null||W(we),p==null||p(Re)}function Se(){return y!=null&&y.isExpandable?k-160:k-(T+210)}const Te=()=>!y||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchFilter,{fields:{...y.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,y.search_fields]),onClear:ie,limit:J,offset:ne,isSearching:ae,onSubmit:Q,onLimitChange:ue,setSearchFilterHeight:M,searchError:xe,searchVisible:H,searchValues:_}),jsxRuntime.jsx(Tree,{total:_e,limit:J,page:Oe,treeView:y,results:pe(),onRequestPageChange:he,loading:ce,onRowClicked:Ie,scrollY:l||Se(),colorsForResults:me,rowSelection:{selectedRowKeys:z==null?void 0:z.map(Re=>Re.id),onChange:ge},sorter:A,onChangeSort:fe,onFetchChildrenForRecord:y.isExpandable?ve:void 0,childField:y.field_parent})]}),Fe=w||xe;return Fe?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Fe,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:u?{}:{display:"none"},children:m?jsxRuntime.jsx(antd.Spin,{}):Te()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:p}=React.useContext(LocaleContext),[m,h]=React.useState([]),v=async()=>{await new Promise(x=>setTimeout(x,5)),t()},C=async x=>{const{id:y}=x;o([y])};function I(){if(m.length===0){v();return}o(m)}const g=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:C,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:x=>{h(x)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:p("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{I()},type:"primary",children:p("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:p("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:p("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:g()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:x=>{u(!1),v(),o([x])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,p]=React.useState(!1),[m,h]=React.useState(!1),[v,C]=React.useState(!1),[I,g]=React.useState(),x=React.useRef(!1),[y,O]=React.useState(""),b=React.useRef(),E=React.useContext(FormContext$1),{domain:w,getValues:S,getFields:T,getContext:M,setOriginalValue:N,elementHasLostFocus:k}=E||{},D=React.useRef([]),[B,L]=React.useState([]),$=n&&n[0]||void 0,j=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&n&&K(n)},[n]),React.useEffect(()=>{$&&j.length===0?K($):$&&j.length>0?O(j):!$&&!j&&O(b.current||"")},[n]);const U=A=>{t==null||t(A),k==null||k()},G=A=>{b.current=A.target.value,U([void 0,""])},z=async()=>{if(!v&&y!==j){if(await new Promise(A=>setTimeout(A,100)),x.current){U([void 0,""]);return}C(!0);try{if(D.current&&D.current.length>0)W(b.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:b.current,context:{...M==null?void 0:M(),...l}});A.length===1?(b.current=void 0,U(A[0])):W(b.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},W=async A=>{if(await V(),D.current&&D.current.length>0){const q=await ConnectionProvider.getHandler().searchAllIds({params:D.current,model:a,context:{...M==null?void 0:M(),...l},totalItems:2});q.length===1?K(q[0],!0):(g(A),p(!0));return}g(A),p(!0)},K=async(A,q)=>{C(!0);try{const Y=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...M==null?void 0:M(),...l}});U([A,Y[0][1]]),q&&N(o.id,[A,Y[0][1]])}catch(Y){showDialog$3(Y)}finally{C(!1)}};async function V(){u&&(D.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:T(),values:S()}),fields:T(),context:M()})),w&&w.length>0&&(D.current=D.current.concat(ooui.transformDomainForChildWidget({domain:w,widgetFieldName:c}))),L(D.current)}async function H(A){A.keyCode===13?(A.preventDefault(),A.stopPropagation(),await z()):A.code==="Backspace"&&$!==void 0&&(A.preventDefault(),A.stopPropagation(),U([void 0,""]))}const P=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(P,{type:"text",value:y,disabled:s,onChange:G,className:d,onBlur:z,onKeyDown:H,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:$,model:a,context:{...M==null?void 0:M(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:$===void 0||j===""||y===void 0,onClick:()=>{h(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{x.current=!0,W(j)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:B,context:{...M==null?void 0:M(),...l},visible:f,nameSearch:$?void 0:I,onSelectValues:A=>{p(!1),K(A[0]),x.current=!1,b.current=void 0},onCloseModal:()=>{p(!1),x.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...M==null?void 0:M(),...l},id:n&&n[0],visible:m,onSubmitSucceed:A=>{h(!1),K(A)},onCancel:()=>{h(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
116
116
  .ant-input {
117
117
  background-color: ${Config.requiredColor};
118
118
  }