Add a share icon in the drive when displaying a shared folder

This commit is contained in:
yflory
2018-07-17 16:38:20 +02:00
parent 6143bceabb
commit 08005a709e
4 changed files with 56 additions and 1 deletions

View File

@@ -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();

View File

@@ -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 */

View File

@@ -1864,6 +1864,27 @@ define([
$container.append($block);
};
var createShareButton = function (id, $container) {
var $shareBlock = $('<button>', {
'class': 'fa fa-shhare-alt cp-toolbar-share-button',
title: Messages.shareButton
});
var data = manager.getSharedFolderData(id);
var parsed = Hash.parsePadUrl(data.href);
if (!parsed || !parsed.hash) { return void console.error("Invalid href: "+data.href); }
var modal = UIElements.createSFShareModal({
origin: APP.origin,
pathname: "/drive/",
hashes: {
editHash: parsed.hash
}
});
$shareBlock.click(function () {
UI.openCustomModal(modal);
});
$container.append($shareBlock);
};
var hideNewButton = function () {
$('.cp-dropdown-content').hide();
};
@@ -2527,6 +2548,10 @@ define([
// NewButton can be undefined if we're in read only mode
createNewButton(isInRoot, $toolbar.find('.cp-app-drive-toolbar-leftside'));
var sfId = manager.isInSharedFolder(currentPath);
if (sfId) {
createShareButton(sfId, $toolbar.find('.cp-app-drive-toolbar-leftside'));
}
createTitle($toolbar.find('.cp-app-drive-path'), path);