diff --git a/www/common/sframe-common-interface.js b/www/common/sframe-common-interface.js new file mode 100644 index 000000000..1bfa553ed --- /dev/null +++ b/www/common/sframe-common-interface.js @@ -0,0 +1,168 @@ +define([ + 'jquery', + '/common/cryptpad-common.js' +], function ($, Cryptpad) { + var UI = {}; + var Messages = Cryptpad.Messages; + + UI.createUserAdminMenu = function (config) { + var Common = config.Common; + var metadataMgr = config.metadataMgr; + + var displayNameCls = config.displayNameCls || 'displayName'; + var $displayedName = $('', {'class': displayNameCls}); + + var accountName = metadataMgr.getPrivateData().accountName; + var origin = metadataMgr.getPrivateData().origin; + var padType = metadataMgr.getMetadata().type; + + var $userName = $('', {'class': 'userDisplayName'}); + var options = []; + if (config.displayNameCls) { + var $userAdminContent = $('

'); + if (accountName) { + var $userAccount = $('', {'class': 'userAccount'}).append(Messages.user_accountName + ': ' + Cryptpad.fixHTML(accountName)); + $userAdminContent.append($userAccount); + $userAdminContent.append($('
')); + } + if (config.displayName) { + // Hide "Display name:" in read only mode + $userName.append(Messages.user_displayName + ': '); + $userName.append($displayedName); + } + $userAdminContent.append($userName); + options.push({ + tag: 'p', + attributes: {'class': 'accountData'}, + content: $userAdminContent.html() + }); + } + if (padType !== 'drive') { + options.push({ + tag: 'a', + attributes: { + 'target': '_blank', + 'href': origin+'/drive/' + }, + content: Messages.login_accessDrive + }); + } + // Add the change display name button if not in read only mode + if (config.changeNameButtonCls && config.displayChangeName) { + options.push({ + tag: 'a', + attributes: {'class': config.changeNameButtonCls}, + content: Messages.user_rename + }); + } + if (accountName) { + options.push({ + tag: 'a', + attributes: {'class': 'profile'}, + content: Messages.profileButton + }); + } + if (padType !== 'settings') { + options.push({ + tag: 'a', + attributes: {'class': 'settings'}, + content: Messages.settingsButton + }); + } + // Add login or logout button depending on the current status + if (accountName) { + options.push({ + tag: 'a', + attributes: {'class': 'logout'}, + content: Messages.logoutButton + }); + } else { + options.push({ + tag: 'a', + attributes: {'class': 'login'}, + content: Messages.login_login + }); + options.push({ + tag: 'a', + attributes: {'class': 'register'}, + content: Messages.login_register + }); + } + var $icon = $('', {'class': 'fa fa-user-secret'}); + //var $userbig = $('', {'class': 'big'}).append($displayedName.clone()); + var $userButton = $('

').append($icon);//.append($userbig); + if (accountName) { + $userButton = $('
').append(accountName); + } + /*if (account && config.displayNameCls) { + $userbig.append($('', {'class': 'account-name'}).text('(' + accountName + ')')); + } else if (account) { + // If no display name, do not display the parentheses + $userbig.append($('', {'class': 'account-name'}).text(accountName)); + }*/ + var dropdownConfigUser = { + text: $userButton.html(), // Button initial text + options: options, // Entries displayed in the menu + left: true, // Open to the left of the button + container: config.$initBlock, // optional + feedback: "USER_ADMIN", + }; + var $userAdmin = Cryptpad.createDropdown(dropdownConfigUser); + + var $displayName = $userAdmin.find('.'+displayNameCls); + + var $avatar = $userAdmin.find('.buttonTitle'); + var updateButton = function () { + var myData = metadataMgr.getMetadata().users[metadataMgr.getNetfluxId()]; + if (!myData) { return; } + var newName = myData.name; + var url = myData.avatar; + $displayName.text(newName || Messages.anonymous); + console.log(newName || Messages.anonymous); + if (accountName) { + $avatar.html(''); + Cryptpad.displayAvatar($avatar, url, newName, function ($img) { + if ($img) { + $userAdmin.find('button').addClass('avatar'); + } + }); + } + }; + metadataMgr.onChange(updateButton); + updateButton(); + + $userAdmin.find('a.logout').click(function () { + Common.logout(function () { + window.top.location = origin+'/'; + }); + }); + $userAdmin.find('a.settings').click(function () { + if (padType) { + window.open(origin+'/settings/'); + } else { + window.top.location = origin+'/settings/'; + } + }); + $userAdmin.find('a.profile').click(function () { + if (padType) { + window.open(origin+'/profile/'); + } else { + window.top.location = origin+'/profile/'; + } + }); + $userAdmin.find('a.login').click(function () { + Common.setLoginRedirect(function () { + window.top.location = origin+'/login/'; + }); + }); + $userAdmin.find('a.register').click(function () { + Common.setLoginRedirect(function () { + window.top.location = origin+'/register/'; + }); + }); + + return $userAdmin; + }; + + return UI; +}); diff --git a/www/common/sframe-common-title.js b/www/common/sframe-common-title.js index 545e80d51..9b8d52399 100644 --- a/www/common/sframe-common-title.js +++ b/www/common/sframe-common-title.js @@ -35,7 +35,8 @@ define(['jquery'], function ($) { if (isDefaultTitle()) { return getHeadingText() || fallback || ""; } else { - return exp.title || getHeadingText() || exp.defaultTitle; + var title = metadataMgr.getMetadata().title; + return title || getHeadingText() || exp.defaultTitle; } }; diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 1a59e7475..4407bff83 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -63,12 +63,12 @@ define([ }); }; - funcs.storeLinkToClipboard = function (readOnly, cb) { +/* funcs.storeLinkToClipboard = function (readOnly, cb) { ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) { if (cb) { cb(err); } }); }; - +*/ // TODO funcs.feedback = function () {}; diff --git a/www/common/toolbar3.js b/www/common/toolbar3.js index 2a2fe9d77..d32bfab3a 100644 --- a/www/common/toolbar3.js +++ b/www/common/toolbar3.js @@ -365,14 +365,13 @@ define([ throw new Error("You must provide a `metadataMgr` to display the userlist"); } var metadataMgr = config.metadataMgr; - var $shareIcon = $('', {'class': 'fa fa-share-alt'}); - var availableHashes = metadataMgr.getPrivateData().availableHashes; + var origin = config.metadataMgr.getPrivateData().origin; + var pathname = config.metadataMgr.getPrivateData().pathname; + var hashes = metadataMgr.getPrivateData().availableHashes; var readOnly = metadataMgr.getPrivateData().readOnly; + + var $shareIcon = $('', {'class': 'fa fa-share-alt'}); var options = []; - var hashes = { - editHash: availableHashes.indexOf('editHash') !== -1, - viewHash: availableHashes.indexOf('viewHash') !== -1 - }; if (hashes.editHash) { options.push({ @@ -380,7 +379,6 @@ define([ attributes: {title: Messages.editShareTitle, 'class': 'editShare'}, content: ' ' + Messages.editShare }); - /* TODO iframe if (readOnly) { // We're in view mode, display the "open editing link" button options.push({ @@ -388,13 +386,12 @@ define([ attributes: { title: Messages.editOpenTitle, 'class': 'editOpen', - href: window.location.pathname + '#' + hashes.editHash, + href: origin + pathname + '#' + hashes.editHash, target: '_blank' }, content: ' ' + Messages.editOpen }); } - */ options.push({tag: 'hr'}); } if (hashes.viewHash) { @@ -403,7 +400,6 @@ define([ attributes: {title: Messages.viewShareTitle, 'class': 'viewShare'}, content: ' ' + Messages.viewShare }); - /* TODO iframe if (!readOnly) { // We're in edit mode, display the "open readonly" button options.push({ @@ -411,13 +407,12 @@ define([ attributes: { title: Messages.viewOpenTitle, 'class': 'viewOpen', - href: window.location.pathname + '#' + hashes.viewHash, + href: origin + pathname + '#' + hashes.viewHash, target: '_blank' }, content: ' ' + Messages.viewOpen }); } - */ } var dropdownConfigShare = { text: $('
').append($shareIcon).html(), @@ -431,16 +426,22 @@ define([ if (hashes.editHash) { $shareBlock.find('a.editShare').click(function () { - Common.storeLinkToClipboard(false, function (err) { + /*Common.storeLinkToClipboard(false, function (err) { if (!err) { Cryptpad.log(Messages.shareSuccess); } - }); + });*/ + var url = origin + pathname + '#' + hashes.editHash; + var success = Cryptpad.Clipboard.copy(url); + if (success) { Cryptpad.log(Messages.shareSuccess); } }); } if (hashes.viewHash) { $shareBlock.find('a.viewShare').click(function () { - Common.storeLinkToClipboard(true, function (err) { + /*Common.storeLinkToClipboard(true, function (err) { if (!err) { Cryptpad.log(Messages.shareSuccess); } - }); + });*/ + var url = origin + pathname + '#' + hashes.viewHash; + var success = Cryptpad.Clipboard.copy(url); + if (success) { Cryptpad.log(Messages.shareSuccess); } }); } @@ -786,7 +787,9 @@ define([ // Events var initClickEvents = function (toolbar, config) { var removeDropdowns = function () { - toolbar.$toolbar.find('.cryptpad-dropdown').hide(); + window.setTimeout(function () { + toolbar.$toolbar.find('.cryptpad-dropdown').hide(); + }); }; var cancelEditTitle = function (e) { // Now we want to apply the title even if we click somewhere else diff --git a/www/pad2/outer.js b/www/pad2/outer.js index 5d88b765d..8a39d669c 100644 --- a/www/pad2/outer.js +++ b/www/pad2/outer.js @@ -60,8 +60,9 @@ define([ priv: { accountName: Cryptpad.getAccountName(), origin: window.location.origin, + pathname: window.location.pathname, readOnly: readOnly, - availableHashes: Object.keys(hashes) + availableHashes: hashes } }); });