Add shareButton to pad2

pull/1/head
yflory 7 years ago
parent beb45740d0
commit e65b2f4e9f

@ -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 = $('<span>', {'class': displayNameCls});
var accountName = metadataMgr.getPrivateData().accountName;
var origin = metadataMgr.getPrivateData().origin;
var padType = metadataMgr.getMetadata().type;
var $userName = $('<span>', {'class': 'userDisplayName'});
var options = [];
if (config.displayNameCls) {
var $userAdminContent = $('<p>');
if (accountName) {
var $userAccount = $('<span>', {'class': 'userAccount'}).append(Messages.user_accountName + ': ' + Cryptpad.fixHTML(accountName));
$userAdminContent.append($userAccount);
$userAdminContent.append($('<br>'));
}
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 = $('<span>', {'class': 'fa fa-user-secret'});
//var $userbig = $('<span>', {'class': 'big'}).append($displayedName.clone());
var $userButton = $('<div>').append($icon);//.append($userbig);
if (accountName) {
$userButton = $('<div>').append(accountName);
}
/*if (account && config.displayNameCls) {
$userbig.append($('<span>', {'class': 'account-name'}).text('(' + accountName + ')'));
} else if (account) {
// If no display name, do not display the parentheses
$userbig.append($('<span>', {'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;
});

@ -35,7 +35,8 @@ define(['jquery'], function ($) {
if (isDefaultTitle()) { if (isDefaultTitle()) {
return getHeadingText() || fallback || ""; return getHeadingText() || fallback || "";
} else { } else {
return exp.title || getHeadingText() || exp.defaultTitle; var title = metadataMgr.getMetadata().title;
return title || getHeadingText() || exp.defaultTitle;
} }
}; };

@ -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) { ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) {
if (cb) { cb(err); } if (cb) { cb(err); }
}); });
}; };
*/
// TODO // TODO
funcs.feedback = function () {}; funcs.feedback = function () {};

@ -365,14 +365,13 @@ define([
throw new Error("You must provide a `metadataMgr` to display the userlist"); throw new Error("You must provide a `metadataMgr` to display the userlist");
} }
var metadataMgr = config.metadataMgr; var metadataMgr = config.metadataMgr;
var $shareIcon = $('<span>', {'class': 'fa fa-share-alt'}); var origin = config.metadataMgr.getPrivateData().origin;
var availableHashes = metadataMgr.getPrivateData().availableHashes; var pathname = config.metadataMgr.getPrivateData().pathname;
var hashes = metadataMgr.getPrivateData().availableHashes;
var readOnly = metadataMgr.getPrivateData().readOnly; var readOnly = metadataMgr.getPrivateData().readOnly;
var $shareIcon = $('<span>', {'class': 'fa fa-share-alt'});
var options = []; var options = [];
var hashes = {
editHash: availableHashes.indexOf('editHash') !== -1,
viewHash: availableHashes.indexOf('viewHash') !== -1
};
if (hashes.editHash) { if (hashes.editHash) {
options.push({ options.push({
@ -380,7 +379,6 @@ define([
attributes: {title: Messages.editShareTitle, 'class': 'editShare'}, attributes: {title: Messages.editShareTitle, 'class': 'editShare'},
content: '<span class="fa fa-users"></span> ' + Messages.editShare content: '<span class="fa fa-users"></span> ' + Messages.editShare
}); });
/* TODO iframe
if (readOnly) { if (readOnly) {
// We're in view mode, display the "open editing link" button // We're in view mode, display the "open editing link" button
options.push({ options.push({
@ -388,13 +386,12 @@ define([
attributes: { attributes: {
title: Messages.editOpenTitle, title: Messages.editOpenTitle,
'class': 'editOpen', 'class': 'editOpen',
href: window.location.pathname + '#' + hashes.editHash, href: origin + pathname + '#' + hashes.editHash,
target: '_blank' target: '_blank'
}, },
content: '<span class="fa fa-users"></span> ' + Messages.editOpen content: '<span class="fa fa-users"></span> ' + Messages.editOpen
}); });
} }
*/
options.push({tag: 'hr'}); options.push({tag: 'hr'});
} }
if (hashes.viewHash) { if (hashes.viewHash) {
@ -403,7 +400,6 @@ define([
attributes: {title: Messages.viewShareTitle, 'class': 'viewShare'}, attributes: {title: Messages.viewShareTitle, 'class': 'viewShare'},
content: '<span class="fa fa-eye"></span> ' + Messages.viewShare content: '<span class="fa fa-eye"></span> ' + Messages.viewShare
}); });
/* TODO iframe
if (!readOnly) { if (!readOnly) {
// We're in edit mode, display the "open readonly" button // We're in edit mode, display the "open readonly" button
options.push({ options.push({
@ -411,13 +407,12 @@ define([
attributes: { attributes: {
title: Messages.viewOpenTitle, title: Messages.viewOpenTitle,
'class': 'viewOpen', 'class': 'viewOpen',
href: window.location.pathname + '#' + hashes.viewHash, href: origin + pathname + '#' + hashes.viewHash,
target: '_blank' target: '_blank'
}, },
content: '<span class="fa fa-eye"></span> ' + Messages.viewOpen content: '<span class="fa fa-eye"></span> ' + Messages.viewOpen
}); });
} }
*/
} }
var dropdownConfigShare = { var dropdownConfigShare = {
text: $('<div>').append($shareIcon).html(), text: $('<div>').append($shareIcon).html(),
@ -431,16 +426,22 @@ define([
if (hashes.editHash) { if (hashes.editHash) {
$shareBlock.find('a.editShare').click(function () { $shareBlock.find('a.editShare').click(function () {
Common.storeLinkToClipboard(false, function (err) { /*Common.storeLinkToClipboard(false, function (err) {
if (!err) { Cryptpad.log(Messages.shareSuccess); } 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) { if (hashes.viewHash) {
$shareBlock.find('a.viewShare').click(function () { $shareBlock.find('a.viewShare').click(function () {
Common.storeLinkToClipboard(true, function (err) { /*Common.storeLinkToClipboard(true, function (err) {
if (!err) { Cryptpad.log(Messages.shareSuccess); } 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 // Events
var initClickEvents = function (toolbar, config) { var initClickEvents = function (toolbar, config) {
var removeDropdowns = function () { var removeDropdowns = function () {
window.setTimeout(function () {
toolbar.$toolbar.find('.cryptpad-dropdown').hide(); toolbar.$toolbar.find('.cryptpad-dropdown').hide();
});
}; };
var cancelEditTitle = function (e) { var cancelEditTitle = function (e) {
// Now we want to apply the title even if we click somewhere else // Now we want to apply the title even if we click somewhere else

@ -60,8 +60,9 @@ define([
priv: { priv: {
accountName: Cryptpad.getAccountName(), accountName: Cryptpad.getAccountName(),
origin: window.location.origin, origin: window.location.origin,
pathname: window.location.pathname,
readOnly: readOnly, readOnly: readOnly,
availableHashes: Object.keys(hashes) availableHashes: hashes
} }
}); });
}); });

Loading…
Cancel
Save