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