Add Writable Share Link action into Share context menu

This commit is contained in:
Hadi Nategh 2017-11-03 16:30:35 +01:00
parent 873a2a93d8
commit 6c093e0aac
3 changed files with 58 additions and 43 deletions

View File

@ -181,8 +181,16 @@ class filemanager_ui
'icon' => 'filemanager/mail_post_to',
'group' => $group,
'children' => array(
'sharelink' => array(
'caption' => lang('Share link'),
'shareReadonlyLink' => array(
'caption' => lang('Readonly Share link'),
'group' => 1,
'icon' => 'share',
'allowOnMultiple' => false,
'order' => 11,
'onExecute' => 'javaScript:app.filemanager.share_link'
),
'shareWritableLink' => array(
'caption' => lang('Writable Share link'),
'group' => 1,
'icon' => 'share',
'allowOnMultiple' => false,
@ -1542,9 +1550,27 @@ class filemanager_ui
$arr['path'] = $dir;
$arr['props'] = $props;
break;
case 'sharelink':
$share = Vfs\Sharing::create($selected, Vfs\Sharing::READONLY, basename($selected), array() );
case 'shareWritableLink':
case 'shareReadonlyLink':
if ($action === 'shareWritableLink')
{
$share = Vfs\Sharing::create(
$selected,
Vfs\Sharing::WRITABLE,
basename($selected),
array(),
array('share_writable' => true)
);
}
else
{
$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;

View File

@ -1152,26 +1152,21 @@ 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
* @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();
egw.json('filemanager_ui::ajax_action', [_action.id, path],
this._share_link_callback, this, true, this).sendRequest();
return true;
},
/**
* share-link callback
* Share-link callback
* @param {object} _data
*/
_share_link_callback: function(_data) {
if (_data.msg || _data.share_link) window.egw_refresh(_data.msg, this.appname);
console.log("_data", _data);
@ -1181,33 +1176,28 @@ app.classes.filemanager = AppJS.extend(
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!');
var 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);
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 } }
});
title: egw.lang("%1 Share Link", _data.action ==='shareWritableLink'? "Writable": "Readonly"),
template: _data.template,
width: 450,
value: {content:{ "share_link": _data.share_link }}
});
},
/**

View File

@ -2,8 +2,7 @@
<!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>
<template id="filemanager.share_dialog" template="" lang="" group="0" version="1.9.003">
<textbox id="share_link" no_lang="1" class="et2_fullWidth"/>
</template>
</overlay>