From a3a2c92c0c8be820644183b8e2ed1d9616bff2bd Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 4 Jun 2019 16:19:47 +0200 Subject: [PATCH] Share a pad, a file or a folder with friends --- www/common/common-ui-elements.js | 34 +++++++++++++++++++++++--------- www/common/notifications.js | 9 +++++++-- www/drive/inner.js | 3 +++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 67e0f6060..47b771c89 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -316,7 +316,7 @@ define([ }); }; - var getFriendsList = function (config) { // XXX test from the drive and don't forget to pass the title + var getFriendsList = function (config) { var common = config.common; var title = config.title; var friends = config.friends; @@ -374,6 +374,7 @@ define([ }; addFake(others); + // Hide friends when they are filtered using the text input var redraw = function () { var name = $(inputFilter).val().trim().replace(/"/g, ''); $div.find('.cp-share-friend').show(); @@ -394,8 +395,10 @@ define([ redraw(); }); + // Replace "copy link" by "share with friends" if at least one friedn is selected + // Also create the "share with friends" button if it doesn't exist var refreshButtons = function () { - var $nav = $div.parents('.alertify-tabs-content').find('nav'); + var $nav = $div.parents('.alertify').find('nav'); if (!$nav.find('.cp-share-with-friends').length) { var button = h('button.primary.cp-share-with-friends', { 'data-keys': '[13]' @@ -418,7 +421,6 @@ define([ }); }); - console.log(UI.findCancelButton()); UI.findCancelButton().click(); // Update the "recently shared with" array: @@ -659,8 +661,15 @@ define([ // Share link tab - var link = h('div.cp-share-modal', [ - UI.dialog.selectable('', { id: 'cp-share-link-preview' }) + var hasFriends = Object.keys(config.friends || {}).length !== 0; + var friendsList = hasFriends ? getFriendsList(config) : undefined; + var friendsUIClass = hasFriends ? '.cp-share-columns' : ''; + var link = h('div.cp-share-modal' + friendsUIClass, [ + h('div.cp-share-column', [ + hasFriends ? h('p', Messages.share_description) : undefined, + UI.dialog.selectable('', { id: 'cp-share-link-preview' }), + ]), + friendsList ]); var getLinkValue = function () { return url; }; $(link).find('#cp-share-link-preview').val(getLinkValue()); @@ -734,10 +743,17 @@ define([ 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 hasFriends = Object.keys(config.friends || {}).length !== 0; + var friendsList = hasFriends ? getFriendsList(config) : undefined; + var friendsUIClass = hasFriends ? '.cp-share-columns' : ''; + var link = h('div.cp-share-modal' + friendsUIClass, [ + h('div.cp-share-column', [ + h('label', Messages.sharedFolders_share), + h('br'), + hasFriends ? h('p', Messages.share_description) : undefined, + UI.dialog.selectable(url, { id: 'cp-share-link-preview', tabindex: 1 }) + ]), + friendsList ]); var linkButtons = [{ name: Messages.cancel, diff --git a/www/common/notifications.js b/www/common/notifications.js index 9296646f4..6d75c31c7 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -1,9 +1,10 @@ define([ 'jquery', '/common/hyperscript.js', + '/common/common-hash.js', '/common/common-ui-elements.js', '/customize/messages.js', -], function ($, h, UIElements, Messages) { +], function ($, h, Hash, UIElements, Messages) { var handlers = {}; @@ -49,8 +50,12 @@ define([ var content = data.content; var msg = content.msg; $(el).find('.cp-notification-content').addClass("cp-clickable"); + var type = Hash.parsePadUrl(msg.content.href).type; + var key = type === 'drive' ? 'notification_folderShared' : + (type === 'file' ? 'notification_fileShared' : + 'notification_padShared'); $(el).find('.cp-notification-content p') - .html(Messages._getKey('notification_padShared', [msg.content.name || Messages.anonymous, msg.content.title])) + .html(Messages._getKey(key, [msg.content.name || Messages.anonymous, msg.content.title])) .click(function () { common.openURL(msg.content.href); }); diff --git a/www/drive/inner.js b/www/drive/inner.js index d4425b653..7208bfd5a 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3245,6 +3245,9 @@ define([ modal = UIElements.createSFShareModal({ origin: APP.origin, pathname: "/drive/", + friends: friends, + title: data.title, + common: common, hashes: { editHash: parsed.hash }