mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 08:34:29 +01:00
* Filemanager: Implement copy_link action for filemanager contextmenu in order to be able to copy webdav url of a file/folder into clipboard
This commit is contained in:
parent
a31b413018
commit
9710ef4f93
@ -179,6 +179,14 @@ class filemanager_ui
|
||||
'enabled' => 'javaScript:app.filemanager.paste_enabled',
|
||||
'children' => array()
|
||||
),
|
||||
'copylink' => array(
|
||||
'caption' => lang('Copy link address'),
|
||||
'group' => $group + 0.5,
|
||||
'icon' => 'copy',
|
||||
'allowOnMultiple' => false,
|
||||
'order' => 10,
|
||||
'onExecute' => 'javaScript:app.filemanager.copy_link'
|
||||
),
|
||||
'documents' => filemanager_merge::document_action(
|
||||
$GLOBALS['egw_info']['user']['preferences']['filemanager']['document_dir'],
|
||||
++$group, 'Insert in document', 'document_',
|
||||
|
@ -794,7 +794,7 @@ app.classes.filemanager = AppJS.extend(
|
||||
* @param {egwAction} _action drop action we're checking
|
||||
* @param {egwActionObject[]} _senders selected files
|
||||
* @param {egwActionObject} _target Drop or context menu activated on this one
|
||||
*
|
||||
*
|
||||
* @returns boolean true if enabled, false otherwise
|
||||
*/
|
||||
paste_enabled: function paste_enabled(_action, _senders, _target)
|
||||
@ -827,7 +827,7 @@ app.classes.filemanager = AppJS.extend(
|
||||
enabled: dir && dir.data && dir.data.class && dir.data.class.indexOf('noEdit') === -1 ||
|
||||
!dir && path_widget && !path_widget.options.readonly
|
||||
});
|
||||
|
||||
|
||||
// Target, if directory
|
||||
target_dir = this.id2path(_target.id);
|
||||
dir = egw.dataGetUIDdata(_target.id);
|
||||
@ -1124,5 +1124,64 @@ app.classes.filemanager = AppJS.extend(
|
||||
this.egw.lang('Do you want more information about EPL subscription?'),
|
||||
this.egw.lang('File a file'), undefined, et2_dialog.BUTTONS_YES_NO, et2_dialog.QUESTION_MESSAGE);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* This function copies the selected file/folder entry as webdav link into clipboard
|
||||
*
|
||||
* @param {object} _action egw actions
|
||||
* @param {object} _senders selected nm row
|
||||
* @returns {Boolean} returns false if not successful
|
||||
*/
|
||||
copy_link: function (_action, _senders)
|
||||
{
|
||||
var data = egw.dataGetUIDdata(_senders[0].id);
|
||||
var url = data ? data.data.download_url : '/webdav.php'+this.id2path(_senders[0].id);
|
||||
if (url[0] == '/') url = egw.link(url);
|
||||
if (url.substr(0,4) == 'http' && url.indexOf('://') <= 5) {
|
||||
// it's already a full url
|
||||
}
|
||||
else
|
||||
{
|
||||
var hostUrl = new URL(window.location.href);
|
||||
url = hostUrl.origin + url;
|
||||
}
|
||||
|
||||
if (url)
|
||||
{
|
||||
var elem = jQuery(document.createElement('div'));
|
||||
var range = [];
|
||||
elem.text(url);
|
||||
elem.appendTo('body');
|
||||
if (document.selection)
|
||||
{
|
||||
range = document.body.createTextRange();
|
||||
range.moveToElementText(elem);
|
||||
range.select();
|
||||
}
|
||||
else if (window.getSelection)
|
||||
{
|
||||
var range = document.createRange();
|
||||
range.selectNode(elem[0]);
|
||||
window.getSelection().removeAllRanges();
|
||||
window.getSelection().addRange(range);
|
||||
}
|
||||
|
||||
var successful = false;
|
||||
try {
|
||||
successful = document.execCommand('copy');
|
||||
if (successful)
|
||||
{
|
||||
egw.message('WebDav link copied into clipboard');
|
||||
window.getSelection().removeAllRanges();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
egw.message('Failed to copy the link!');
|
||||
elem.remove();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user