| 467 | }; |
| 468 | |
| 469 | export function InputFileSelect({ controlProps, onChange, disabled, readonly, isvalidate = false, hideBrowseButton=false,validate, ...props }) { |
| 470 | const inpRef = useRef(); |
| 471 | let textControlProps = {}; |
| 472 | if(controlProps?.placeholder) { |
| 473 | const {placeholder} = controlProps; |
| 474 | textControlProps = {placeholder}; |
| 475 | } |
| 476 | const showFileDialog = ()=>{ |
| 477 | let params = { |
| 478 | supported_types: controlProps.supportedTypes || [], |
| 479 | dialog_type: controlProps.dialogType || 'select_file', |
| 480 | dialog_title: controlProps.dialogTitle || '', |
| 481 | btn_primary: controlProps.btnPrimary || '', |
| 482 | }; |
| 483 | showFileManager(params, (fileName, dir)=>{ |
| 484 | if (dir && dir != MY_STORAGE){ |
| 485 | onChange?.(dir + ':' + decodeURI(fileName)); |
| 486 | }else{ |
| 487 | onChange?.(decodeURI(fileName)); |
| 488 | } |
| 489 | inpRef.current.focus(); |
| 490 | }); |
| 491 | }; |
| 492 | |
| 493 | return ( |
| 494 | <InputText ref={inpRef} disabled={disabled} readonly={readonly} onChange={onChange} controlProps={textControlProps} {...props} endAdornment={ |
| 495 | <> |
| 496 | {!hideBrowseButton && |
| 497 | <IconButton onClick={showFileDialog} |
| 498 | disabled={disabled || readonly} aria-label={gettext('Select a file')}><FolderOpenRoundedIcon /></IconButton> |
| 499 | } |
| 500 | {isvalidate && |
| 501 | <PgIconButton title={gettext('Validate')} style={{ border: 'none' }} disabled={!props.value} onClick={() => { validate(props.value); }} icon={<AssignmentTurnedIn />}></PgIconButton> |
| 502 | } |
| 503 | </> |
| 504 | } /> |
| 505 | ); |
| 506 | } |
| 507 | InputFileSelect.propTypes = { |
| 508 | controlProps: PropTypes.object, |
| 509 | onChange: PropTypes.func, |