From 6c093e0aac083019694fbbac29dd4aceaabe033b Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 3 Nov 2017 16:30:35 +0100 Subject: [PATCH] Add Writable Share Link action into Share context menu --- filemanager/inc/class.filemanager_ui.inc.php | 36 ++++++++++-- filemanager/js/app.js | 58 ++++++++----------- .../templates/default/share_dialog.xet | 7 +-- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index 9d83f200a8..dc9a285774 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -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; diff --git a/filemanager/js/app.js b/filemanager/js/app.js index 48cc466491..3f70e930db 100644 --- a/filemanager/js/app.js +++ b/filemanager/js/app.js @@ -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 }} + }); }, /** diff --git a/filemanager/templates/default/share_dialog.xet b/filemanager/templates/default/share_dialog.xet index f77d420102..4a982a9b7c 100644 --- a/filemanager/templates/default/share_dialog.xet +++ b/filemanager/templates/default/share_dialog.xet @@ -2,8 +2,7 @@ - - +