From 06f46129fcf8d101db268db41116f5199fe5c7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Benqu=C3=A9?= Date: Mon, 9 Dec 2019 16:16:13 +0000 Subject: [PATCH] add functionality to buttons for no contacts --- www/common/common-ui-elements.js | 87 +++++++++++++++++-------------- www/common/sframe-common-outer.js | 10 ++-- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index fd2955e56..e7d107e36 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -1006,6 +1006,49 @@ define([ }; }; + var noContactsMessage = function(common){ + var metadataMgr = common.getMetadataMgr(); + var data = metadataMgr.getUserData(); + var origin = metadataMgr.getPrivateData().origin; + if (common.isLoggedIn()) { + return { + content: h('p', Messages.share_noContactsLoggedIn), + buttons: [{ + className: 'secondary', + name: Messages.share_copyProfileLink, + onClick: function () { + var profile = data.profile ? (origin + '/profile/#' + data.profile) : ''; + var success = Clipboard.copy(profile); + if (success) { UI.log(Messages.shareSuccess); } + }, + keys: [13] + }] + }; + } else { + return { + content: h('p', Messages.share_noContactsNotLoggedIn), + buttons: [{ + className: 'secondary', + name: Messages.login_register, + onClick: function () { + common.setLoginRedirect(function () { + common.openURL('/login/'); + }); + } + }, { + className: 'secondary', + name: Messages.login_login, + onClick: function () { + common.setLoginRedirect(function () { + common.openURL('/register/'); + }); + } + } + ] + }; + } + }; + UIElements.createShareModal = function (config) { var origin = config.origin; var pathname = config.pathname; @@ -1126,41 +1169,8 @@ define([ var hasFriends = Object.keys(config.friends || {}).length !== 0; var onFriendShare = Util.mkEvent(); - var noContactsMessage = function(){ - if (common.isLoggedIn()) { - return { - content: h('p', Messages.share_noContactsLoggedIn), - buttons: [{ - className: 'secondary', - name: Messages.share_copyProfileLink, - onClick: function () { - // XXX copy profile link - }, - keys: [13] - }] - }; - } else { - return { - content: h('p', Messages.share_noContactsNotLoggedIn), - buttons: [{ - className: 'secondary', - name: Messages.login_register, - onClick: function () { - // XXX link to register - } - }, { - className: 'secondary', - name: Messages.login_login, - onClick: function () { - // XXX link to log in - } - } - ] - }; - } - }; - var friendsObject = hasFriends ? createShareWithFriends(config, onFriendShare, getLinkValue) : noContactsMessage(); + var friendsObject = hasFriends ? createShareWithFriends(config, onFriendShare, getLinkValue) : noContactsMessage(common); var friendsList = friendsObject.content; onFriendShare.reg(saveValue); @@ -1332,17 +1342,14 @@ define([ // share with contacts tab var hasFriends = Object.keys(config.friends || {}).length !== 0; - var friendsObject = hasFriends ? createShareWithFriends(config, null, getLinkValue) : { - content: h('p', Messages.share_noContacts), - button: {} - }; + var friendsObject = hasFriends ? createShareWithFriends(config, null, getLinkValue) : noContactsMessage(common); var friendsList = friendsObject.content; var contactsContent = h('div.cp-share-modal'); $(contactsContent).append(friendsList); - var contactButtons = [makeCancelButton(), - friendsObject.button]; + var contactButtons = friendsObject.buttons; + contactButtons.unshift(makeCancelButton()); var frameContacts = UI.dialog.customModal(contactsContent, { buttons: contactButtons, diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index e439d04c1..0aa79cfd1 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -484,6 +484,11 @@ define([ Cryptpad.mailbox.execCommand(data, cb); }); + sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) { + sessionStorage.redirectTo = window.location.href; + cb(); + }); + sframeChan.on('Q_STORE_IN_TEAM', function (data, cb) { Cryptpad.storeInTeam(data, cb); }); @@ -634,11 +639,6 @@ define([ Notifier.notify(data); }); - sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) { - sessionStorage.redirectTo = window.location.href; - cb(); - }); - sframeChan.on('Q_MOVE_TO_TRASH', function (data, cb) { cb = cb || $.noop; if (readOnly && hashes.editHash) {