From 989f974da0e2da2cb51ebd353c04054f77c534d8 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 25 Jun 2024 14:58:12 -0600 Subject: [PATCH] Api: Filemanager customfield improvements - Fix links from VFS did not work - Update list after linking to VFS - Add noUpload option --- admin/inc/class.admin_customfields.inc.php | 2 +- api/js/etemplate/et2_extension_customfields.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/admin/inc/class.admin_customfields.inc.php b/admin/inc/class.admin_customfields.inc.php index eb7f2a74cc..f4897420bc 100644 --- a/admin/inc/class.admin_customfields.inc.php +++ b/admin/inc/class.admin_customfields.inc.php @@ -88,7 +88,7 @@ class admin_customfields 'button' => 'each value is a line like label=[javascript]', 'password' => 'set length=# for minimum password length, strength=# for password strength', 'serial' => 'you can set an initial value, which gets incremented every time a new serial get generated', - 'filemanager' => "use the following options:\nnoVfsSelect=1\nmime=application/pdf or /^image\//i\naccept=pdf,docx\nmax_upload_size=2M", + 'filemanager' => "use the following options:\nnoVfsSelect=1\nnoUpload=1\nmime=application/pdf or /^image\//i\naccept=pdf,docx\nmax_upload_size=2M", ); /** diff --git a/api/js/etemplate/et2_extension_customfields.ts b/api/js/etemplate/et2_extension_customfields.ts index 3cae2c524b..264a7277c1 100644 --- a/api/js/etemplate/et2_extension_customfields.ts +++ b/api/js/etemplate/et2_extension_customfields.ts @@ -911,7 +911,12 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac .appendTo(row); // Create upload widget - let widget = this.widgets[field_name] = et2_createWidget(attrs.type ? attrs.type : field.type, {...attrs}, this); + let upload_attrs = {...attrs}; + if(typeof field.values?.noUpload !== "undefined") + { + upload_attrs.class = "hideme"; + } + let widget = this.widgets[field_name] = et2_createWidget(attrs.type ? attrs.type : field.type, upload_attrs, this); // This controls where the widget is placed in the DOM this.rows[attrs.id] = cf[0]; @@ -929,8 +934,9 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac ...{ path: '~', mode: widget.options.multiple ? 'open-multiple' : 'open', + multiple: widget.options.multiple, method: 'EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_existing', - methodId: attrs.path, + methodId: widget.options.path ?? attrs.path, buttonLabel: this.egw().lang('Link') }, type: 'et2-vfs-select', @@ -943,6 +949,14 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac // Do not store in the widgets list, one name for multiple widgets would cause problems widget = loadWebComponent(select_attrs.type, select_attrs, this); + + // Update link list & show file in upload + widget.addEventListener("change", (e) => + { + document.querySelectorAll('et2-link-list').forEach(l => {l.get_links();}); + const info = e.target._dialog.fileInfo(e.target.value); + e.target.getParent().getWidgetById("#filemanager")?._addFile(info); + }); jQuery(widget.getDOMNode(widget)).css('vertical-align','top').prependTo(cf); } }