From e033903126d8694275931f63ed6cc823d20cb966 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 8 Sep 2015 16:02:18 +0000 Subject: [PATCH] Add ability to select existing file in VFS for custom field type filemanager --- .../inc/class.etemplate_widget_link.inc.php | 7 ++- etemplate/js/et2_extension_customfields.js | 46 ++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_link.inc.php b/etemplate/inc/class.etemplate_widget_link.inc.php index 4314de7029..c493e7c787 100644 --- a/etemplate/inc/class.etemplate_widget_link.inc.php +++ b/etemplate/inc/class.etemplate_widget_link.inc.php @@ -232,11 +232,14 @@ class etemplate_widget_link extends etemplate_widget */ public static function link_existing($app_id, $files) { - list($app, $id) = explode(':', $app_id); + list($app, $id, $dest_file) = explode(':', $app_id); + if($id && $dest_file && trim($dest_file) !== '') + { + $id .= "/$dest_file"; + } if(!is_array($files)) $files = array($files); foreach($files as $target) { - error_log(array2string($target)); egw_link::link_file($app, $id, $target); } } diff --git a/etemplate/js/et2_extension_customfields.js b/etemplate/js/et2_extension_customfields.js index 61cc936b29..d35fd6c74e 100644 --- a/etemplate/js/et2_extension_customfields.js +++ b/etemplate/js/et2_extension_customfields.js @@ -590,7 +590,51 @@ var et2_customfields_list = et2_valueWidget.extend([et2_IDetachedDOM, et2_IInput _setup_filemanager: function(field_name, field, attrs) { attrs.type = 'vfs-upload'; delete(attrs.label); - return true; + + if (this._type == 'customfields-list') + { + // No special UI needed? + return true; + } + else + { + // Complicated case, a single custom field you get multiple widgets + // Handle it all here, since this is the exception + var row = $j('tr',this.tbody).last(); + var cf = $j('td',row); + + // Label in first column, widget in 2nd + cf.text(field.label + ""); + cf = jQuery(document.createElement("td")) + .appendTo(row); + + // Add a link to existing VFS file + var select_attrs = jQuery.extend({}, + attrs, + // Filemanager select + { + label: '', + method: 'etemplate_widget_link::link_existing', + method_id: attrs.path, + button_label: egw.lang('Link') + },{type: 'vfs-select'}); + select_attrs.id = attrs.id + '_vfs_select'; + + // This controls where the button is placed in the DOM + this.rows[select_attrs.id] = cf[0]; + + // Do not store in the widgets list, one name for multiple widgets would cause problems + widget = et2_createWidget(select_attrs.type, select_attrs, this); + $j(widget.getDOMNode(widget)).css('vertical-align','top'); + + // Create upload widget + var widget = this.widgets[field_name] = et2_createWidget(attrs.type ? attrs.type : field.type, attrs, this); + + // This controls where the widget is placed in the DOM + this.rows[attrs.id] = cf[0]; + $j(widget.getDOMNode(widget)).css('vertical-align','top'); + } + return false; }, /**