Etemplate: Get vfsUpload values to use expose so they work like links

This commit is contained in:
nathangray 2020-07-03 14:23:41 -06:00
parent ee498f703d
commit 4c7709d49f
3 changed files with 43 additions and 2 deletions

View File

@ -938,7 +938,22 @@ var et2_vfsUpload = /** @class */ (function (_super) {
.addClass('title')
.appendTo(row);
var mime = et2_core_widget_1.et2_createWidget('vfs-mime', { value: file_data }, this);
var vfs = et2_core_widget_1.et2_createWidget('vfs', { value: file_data }, this);
// Trigger expose on click, if supported
var vfs_attrs = { value: file_data, onclick: undefined };
if (file_data && (typeof file_data.download_url != 'undefined')) {
var fe_mime = egw_get_file_editor_prefered_mimes(file_data.mime);
// Check if the link entry is mime with media type, in order to open it in expose view
if (typeof file_data.mime != 'undefined' &&
(file_data.mime.match(mime.mime_regexp, 'ig') || (fe_mime && fe_mime.mime[file_data.mime]))) {
vfs_attrs.onclick = function (ev) {
ev.stopPropagation();
// Pass it off to the associated vfsMime widget
jQuery('img', this.parentNode.parentNode).trigger("click");
return false;
};
}
}
var vfs = et2_core_widget_1.et2_createWidget('vfs', vfs_attrs, this);
// If already attached, need to do this explicitly
if (this.isAttached()) {
mime.set_value(file_data);

View File

@ -1068,6 +1068,11 @@ class et2_vfsUpload extends et2_file
}
}
}
// Set up for expose
if(file_data && typeof file_data.download_url === "undefined")
{
file_data.download_url = "/webdav.php" + file_data.path;
}
let row = jQuery(document.createElement("tr"))
.attr("data-path", file_data.path.replace(/'/g, '&quot'))
.attr("draggable", "true")
@ -1080,7 +1085,25 @@ class et2_vfsUpload extends et2_file
.addClass('title')
.appendTo(row);
let mime = <et2_vfsMime> et2_createWidget('vfs-mime',{value: file_data}, this);
let vfs = <et2_vfs> et2_createWidget('vfs', {value: file_data}, this);
// Trigger expose on click, if supported
let vfs_attrs = {value: file_data, onclick: undefined};
if (file_data && (typeof file_data.download_url != 'undefined'))
{
var fe_mime = egw_get_file_editor_prefered_mimes(file_data.mime);
// Check if the link entry is mime with media type, in order to open it in expose view
if (typeof file_data.mime != 'undefined' &&
(file_data.mime.match(mime.mime_regexp,'ig') || (fe_mime && fe_mime.mime[file_data.mime])))
{
vfs_attrs.onclick = function(ev) {
ev.stopPropagation();
// Pass it off to the associated vfsMime widget
jQuery('img',this.parentNode.parentNode).trigger("click");
return false;
};
}
}
let vfs = <et2_vfs> et2_createWidget('vfs', vfs_attrs, this);
// If already attached, need to do this explicitly
if(this.isAttached())

View File

@ -81,6 +81,7 @@ class Vfs extends File
$file['path'] = $path;
$file['name'] = Api\Vfs::basename($file['path']);
$file['mime'] = Api\Vfs::mime_content_type($file['path']);
$file['download_url'] = Api\Vfs::download_url($file['path']);
$value = array($file);
}
// Single file, missing extension in path
@ -97,6 +98,7 @@ class Vfs extends File
$file_info['path'] = $file;
$file_info['name'] = Api\Vfs::basename($file_info['path']);
$file_info['mime'] = Api\Vfs::mime_content_type($file_info['path']);
$file_info['download_url'] = Api\Vfs::download_url($file_info['path']);
$value[] = $file_info;
}
}
@ -109,6 +111,7 @@ class Vfs extends File
$file_info['path'] = "$path$file";
$file_info['name'] = Api\Vfs::basename($file_info['path']);
$file_info['mime'] = Api\Vfs::mime_content_type($file_info['path']);
$file_info['download_url'] = Api\Vfs::download_url($file_info['path']);
$value[] = $file_info;
}
}