From 08005a709e60bd62fd8144069ae5c326310b284c Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 17 Jul 2018 16:38:20 +0200 Subject: [PATCH] Add a share icon in the drive when displaying a shared folder --- customize.dist/translations/messages.js | 1 + www/common/common-ui-elements.js | 29 +++++++++++++++++++++++++ www/common/proxy-manager.js | 2 +- www/drive/inner.js | 25 +++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index a66cc28eb..543a0f778 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -1210,6 +1210,7 @@ define(function () { out.sharedFolders_create_name = "Folder name"; out.sharedFolders_create_owned = "Owned folder"; out.sharedFolders_create_password = "Folder password"; + out.sharedFolders_share = "Share this URL with other registered users to give them access to the shared folder. Once they open this URL, the shared folder will be added to the root directory of their CryptDrive."; return out; }); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 741688797..900913c0f 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -517,6 +517,35 @@ define([ } return tabs; }; + UIElements.createSFShareModal = function (config) { + var origin = config.origin; + var pathname = config.pathname; + var hashes = config.hashes; + + if (!hashes.editHash) { throw new Error("You must provide a valid hash"); } + var url = origin + pathname + '#' + hashes.editHash; + + // Share link tab + var link = h('div.cp-share-modal', [ + h('label', Messages.sharedFolders_share), + h('br'), + UI.dialog.selectable(url, { id: 'cp-share-link-preview', tabindex: 1 }) + ]); + var linkButtons = [{ + name: Messages.cancel, + onClick: function () {}, + keys: [27] + }, { + className: 'primary', + name: Messages.share_linkCopy, + onClick: function () { + var success = Clipboard.copy(url); + if (success) { UI.log(Messages.shareSuccess); } + }, + keys: [13] + }]; + return UI.dialog.customModal(link, {buttons: linkButtons}); + }; UIElements.createButton = function (common, type, rightside, data, callback) { var AppConfig = common.getAppConfig(); diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index df2b4ecd1..622eacbf0 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -866,7 +866,7 @@ define([ var isInSharedFolder = function (Env, path) { var resolved = _resolvePath(Env, path); - return typeof resolved.id === "number"; + return typeof resolved.id === "number" ? resolved.id : false; }; /* Generic: doesn't need access to a proxy */ diff --git a/www/drive/inner.js b/www/drive/inner.js index be8585156..93d8e5722 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -1864,6 +1864,27 @@ define([ $container.append($block); }; + var createShareButton = function (id, $container) { + var $shareBlock = $('