* added share-link feature to filemanager context menu

This commit is contained in:
W.A. Mozart 2017-08-01 15:25:33 +02:00
parent 1159df66cf
commit 91ecb5defc
3 changed files with 91 additions and 2 deletions

View File

@ -206,6 +206,14 @@ class filemanager_ui
'order' => 10,
'onExecute' => 'javaScript:app.filemanager.copy_link'
),
'sharelink' => array(
'caption' => lang('Share link'),
'group' => $group + 0.5,
'icon' => 'share',
'allowOnMultiple' => false,
'order' => 11,
'onExecute' => 'javaScript:app.filemanager.share_link'
),
'documents' => filemanager_merge::document_action(
$GLOBALS['egw_info']['user']['preferences']['filemanager']['document_dir'],
++$group, 'Insert in document', 'document_',
@ -836,8 +844,8 @@ class filemanager_ui
// do NOT store query, if hierarchical data / children are requested
if (!$query['csv_export'])
{
Api\Cache::setSession('filemanager', 'index',
array_diff_key ($query, array_flip(array('rows','actions','action_links','placeholder_actions'))));
Api\Cache::setSession('filemanager', 'index',
array_diff_key ($query, array_flip(array('rows','actions','action_links','placeholder_actions'))));
}
if(!$query['path']) $query['path'] = static::get_home_dir();
@ -1476,6 +1484,14 @@ class filemanager_ui
$arr['props'] = $props;
break;
case 'sharelink':
$share = Vfs\Sharing::create($selected, Vfs\Sharing::READONLY, basename($selected), array() );
$arr["share_link"] = $link = Vfs\Sharing::share2link($share);
$arr["template"] = Api\Etemplate\Widget\Template::rel2url('/filemanager/templates/default/share_dialog.xet');
break;
// Upload, then link
case 'link':
// First upload

View File

@ -299,6 +299,10 @@ app.classes.filemanager = AppJS.extend(
}
},
/**
* Finish callback for file a file dialog, to get the overwrite / rename prompt
*
@ -1139,6 +1143,66 @@ app.classes.filemanager = AppJS.extend(
}
},
/**
* create a share-link for the given file or directory
* @param {object} _action egw actions
* @param {object} _senders selected nm row
* @returns {Boolean} returns false if not successful
*/
share_link: function(_action, _senders){
var data = egw.dataGetUIDdata(_senders[0].id)
var path = this.id2path(_senders[0].id);
var request = egw.json('filemanager_ui::ajax_action', ['sharelink', path],
this._share_link_callback, this, true, this
).sendRequest();
return true;
},
/**
* share-link callback
*/
_share_link_callback: function(_data) {
if (_data.msg || _data.share_link) window.egw_refresh(_data.msg, this.appname);
console.log("_data", _data);
var copy_link_to_clipboard = null;
var copy_link_to_clipboard = function(evt){
var $target = jQuery(evt.target);
$target.select();
console.log("share_link click");
try {
successful = document.execCommand('copy');
if (successful)
{
egw.message('Share link copied into clipboard');
return true;
}
}
catch (e) {}
egw.message('Failed to copy the link!');
};
jQuery("body").on("click", "[name=share_link]", copy_link_to_clipboard);
var dialog = et2_createWidget("dialog",{
callback: function( button_id, value){
jQuery("body").off("click", "[name=share_link]", copy_link_to_clipboard);
return true;
},
title: "Share",
template: _data.template,
value: { content:{ "share_link": _data.share_link } }
});
},
/**
* This function copies the selected file/folder entry as webdav link into clipboard
*

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE overlay PUBLIC "-//Stylite AG//eTemplate 2//EN" "http://www.egroupware.org/etemplate2.dtd">
<!-- $Id$ -->
<overlay>
<template id="filemanager.share_dialog" template="" lang="" group="0" version="1.9.003">
<textbox id="share_link" no_lang="1" width="250px"/>
</template>
</overlay>