diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index 73da4792f7..10034259e7 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -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 diff --git a/filemanager/js/app.js b/filemanager/js/app.js index 68d5e9c3c4..5c9cb8c8d3 100644 --- a/filemanager/js/app.js +++ b/filemanager/js/app.js @@ -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 * diff --git a/filemanager/templates/default/share_dialog.xet b/filemanager/templates/default/share_dialog.xet new file mode 100644 index 0000000000..f77d420102 --- /dev/null +++ b/filemanager/templates/default/share_dialog.xet @@ -0,0 +1,9 @@ + + + + + + +