mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 04:29:28 +01:00
WIP allow to place custom-fields in tabs: fix automatic extension and use name not label
name for filename type cf is a relative path, optionally ending in a / to create a directory with all files the user uploads preserving their name
This commit is contained in:
parent
a215015e0e
commit
44db5c68b5
@ -880,12 +880,6 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
|
||||
attrs.type = 'vfs-upload';
|
||||
delete(attrs.label);
|
||||
|
||||
// fix vfs-upload id="$app:$id:$rest" e.g. "infolog:$cont[info_id]:test.pdf"
|
||||
const vfs_app_id_regexp = /^#([a-z_]+):([@$][^:]+):(.*)$/;
|
||||
if (attrs.id.match(vfs_app_id_regexp))
|
||||
{
|
||||
attrs.id = <string>this.getArrayMgr('content').expandName(attrs.id);
|
||||
}
|
||||
// allow to set/pass further et2_file attributes to the vfs-upload
|
||||
if (field.values && typeof field.values === 'object')
|
||||
{
|
||||
|
@ -343,7 +343,7 @@ class Customfields extends Transformer
|
||||
case 'vfs-upload':
|
||||
$widget->attrs['path'] = $field['app'] . ':' .
|
||||
self::expand_name('$cont['.Api\Link::get_registry($field['app'],'view_id').']',0,0,0,0,self::$request->content).
|
||||
':'.$field['label'];
|
||||
':'.(preg_match('/^[a-z_]+:[^:]+:(.+)$/', $field['name'], $matches) ? $matches[1] : $field['name']);
|
||||
break;
|
||||
|
||||
case 'link-to':
|
||||
|
@ -39,7 +39,7 @@ class Vfs extends File
|
||||
{
|
||||
if ($this->type === 'vfs-upload' || !empty($this->attrs['type']) && $this->attrs['type'] === 'vfs-upload')
|
||||
{
|
||||
$form_name = self::form_name($cname, $this->id, $expand ? $expand : array('cont' => self::$request->content));
|
||||
$form_name = self::form_name($cname, $this->id, $expand ?: array('cont' => self::$request->content));
|
||||
if (!empty($this->attrs['path']))
|
||||
{
|
||||
$path = self::expand_name($this->attrs['path'], $expand['c'] ?? null, $expand['row'], $expand['c_'] ?? null, $expand['row_'] ?? null, $expand['cont']);
|
||||
@ -286,21 +286,21 @@ class Vfs extends File
|
||||
{
|
||||
$name = $_REQUEST['widget_id'];
|
||||
|
||||
// Find real path
|
||||
if($path[0] != '/')
|
||||
// Find real path, could be "$app:$id:$path"
|
||||
if($path[0] !== '/')
|
||||
{
|
||||
$path = self::get_vfs_path($path);
|
||||
}
|
||||
$filename = $file['name'];
|
||||
if ($path && substr($path,-1) != '/')
|
||||
if ($path && substr($path,-1) !== '/')
|
||||
{
|
||||
$parts = explode('.', $filename);
|
||||
// check if path already contains a valid extension --> don't add another one
|
||||
$path_parts = explode('.', Api\Vfs::basename($path));
|
||||
if ((!($path_ext = array_pop($path_parts)) || Api\MimeMagic::ext2mime($path_ext) === 'application/octet-stream') &&
|
||||
($extension = array_pop($parts) ?: Api\MimeMagic::mime2ext($file['mime'])))
|
||||
{
|
||||
// add extension to path
|
||||
$parts = explode('.',$filename);
|
||||
// check if path already contains a valid extension --> dont add an other one
|
||||
$path_parts = explode('.', $path);
|
||||
if (count($path_parts) > 2 && (!($extension = array_pop($path_parts)) || !Api\MimeMagic::ext2mime($extension)) &&
|
||||
($extension = array_pop($parts)) && Api\MimeMagic::ext2mime($extension)) // really an extension --> add it to path
|
||||
{
|
||||
$path .= '.'.$extension;
|
||||
}
|
||||
$file['name'] = Api\Vfs::basename($path);
|
||||
|
@ -637,7 +637,9 @@ class Customfields implements \IteratorAggregate
|
||||
|
||||
protected static function handle_file($entry_id, $field, $value)
|
||||
{
|
||||
$path = Api\Etemplate\Widget\Vfs::get_vfs_path($field['app'].":$entry_id:".$field['label']);
|
||||
$path = Api\Etemplate\Widget\Vfs::get_vfs_path($field['app'].':'.$entry_id.':'.
|
||||
(preg_match('/^[a-z_]+:[^:]+:(.+)$/', $field['name'], $matches) ? $matches[1] : $field['name']));
|
||||
|
||||
if($path)
|
||||
{
|
||||
foreach($value as $file)
|
||||
|
Loading…
Reference in New Issue
Block a user