Useradmin menu, notifications and share button in pad2

This commit is contained in:
yflory
2017-08-18 16:34:41 +02:00
parent dd9b38066e
commit 90f892de9c
7 changed files with 194 additions and 157 deletions

View File

@@ -10,6 +10,7 @@ define([
], function (ApiConfig, SFrameChannel, $, CpNfOuter, nThen, Cryptpad, Crypto) {
console.log('xxx');
var sframeChan;
var hashes;
nThen(function (waitFor) {
$(waitFor());
}).nThen(function (waitFor) {
@@ -20,11 +21,16 @@ define([
console.log('sframe initialized');
}));
Cryptpad.ready(waitFor());
}).nThen(function (waitFor) {
Cryptpad.getShareHashes(function (err, h) {
hashes = h;
waitFor()();
});
}).nThen(function (waitFor) {
var secret = Cryptpad.getSecrets();
var readOnly = secret.keys && !secret.keys.editKeyStr;
if (!secret.keys) { secret.keys = secret.key; }
var parsed = Cryptpad.parsePadUrl(window.location.href);
parsed.type = parsed.type.replace('pad2', 'pad');
if (!parsed.type) { throw new Error(); }
@@ -52,7 +58,10 @@ define([
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
},
priv: {
accountName: Cryptpad.getAccountName()
accountName: Cryptpad.getAccountName(),
origin: window.location.origin,
readOnly: readOnly,
availableHashes: Object.keys(hashes)
}
});
});
@@ -87,6 +96,29 @@ define([
});
});
sframeChan.on('Q_LOGOUT', function (data, cb) {
Cryptpad.logout(cb);
});
sframeChan.on('Q_SET_LOGIN_REDIRECT', function (data, cb) {
sessionStorage.redirectTo = window.location.href;
cb();
});
sframeChan.on('Q_STORE_LINK_TO_CLIPBOARD', function (readOnly, cb) {
if (readOnly) {
if (!hashes.viewHash) { return void cb('E_INVALID_HASH'); }
var url = window.location.origin + window.location.pathname + '#' + hashes.viewHash;
var success = Cryptpad.Clipboard.copy(url);
cb(!success);
return;
}
if (!hashes.editHash) { return void cb('E_INVALID_HASH'); }
var eUrl = window.location.origin + window.location.pathname + '#' + hashes.editHash;
var eSuccess = Cryptpad.Clipboard.copy(eUrl);
cb(!eSuccess);
});
CpNfOuter.start({
sframeChan: sframeChan,
channel: secret.channel,