diff --git a/api/js/etemplate/Et2Vfs/Et2VfsSelect.ts b/api/js/etemplate/Et2Vfs/Et2VfsSelect.ts index b7f2190c06..63123cfd11 100644 --- a/api/js/etemplate/Et2Vfs/Et2VfsSelect.ts +++ b/api/js/etemplate/Et2Vfs/Et2VfsSelect.ts @@ -90,7 +90,18 @@ export class Et2VfsSelect extends Et2InputWidget(LitElement) implements SearchMi @property() mime : string | string[] | RegExp = ""; /** List of mimetypes to allow user to filter. */ - @property() mimeList : SelectOption[] = []; + @property() mimeList : SelectOption[] = [ + { + value: "/(application\\/vnd.oasis.opendocument.text|application\\/vnd.openxmlformats-officedocument.wordprocessingml.document)/i", + label: "Documents" + }, + { + value: "/(application\\/vnd.oasis.opendocument.spreadsheet|application\\/vnd.openxmlformats-officedocument.spreadsheetml.sheet)/i", + label: "Spreadsheets" + }, + {value: "image/", label: "Images"}, + {value: "video/", label: "Videos"} + ]; /** The select's help text. If you need to display HTML, use the `help-text` slot instead. */ @property({attribute: 'help-text'}) helpText = ''; @@ -699,6 +710,8 @@ export class Et2VfsSelect extends Et2InputWidget(LitElement) implements SearchMi const hasToolbar = !!hasToolbarSlot; const hasFilename = this.mode == "saveas"; + const mime = this.mimeList.length == 1 ? this.mimeList[0].value : + (typeof this.mime == "string" ? this.mime : ""); return html` + { + this.mime = e.target.value; + this.startSearch(); + }} > ${this.mimeOptionsTemplate()} diff --git a/api/src/Etemplate/Widget/Vfs.php b/api/src/Etemplate/Widget/Vfs.php index 46c39db268..f7b7084b95 100644 --- a/api/src/Etemplate/Widget/Vfs.php +++ b/api/src/Etemplate/Widget/Vfs.php @@ -643,10 +643,7 @@ class Vfs extends File $name = $path['name'] ?? Api\Vfs::basename($path); $is_dir = $path['isDir'] ?? Api\Vfs::is_dir($path); $mime = $path['mime'] ?? Api\Vfs::mime_content_type($path); - if($content['mime'] && !$is_dir && $mime != $content['mime']) - { - continue; // does not match mime-filter --> ignore - } + $response['files'][] = array( 'name' => $name, 'path' => $path, @@ -671,15 +668,21 @@ class Vfs extends File array('.{1}', '.*'), preg_quote($search)) . '/i'; } + $dirs = []; + if($params['mime']) + { + // Always get dirs + $vfs_options['type'] = 'd'; + $dirs = Api\Vfs::find($params['path'], $vfs_options); + $vfs_options['type'] = 'f'; + $vfs_options['mime'] = $params['mime']; + } if($params['num_rows']) { $vfs_options['limit'] = (int)$params['num_rows']; } - if(!($files = Api\Vfs::find($params['path'], $vfs_options))) - { - return lang("Can't open directory %1!", $params['path']); - } - return $files; + $files = Api\Vfs::find($params['path'], $vfs_options); + return array_merge($dirs, $files); } /**