Add the share button when a file upload is complete

pull/1/head
yflory 8 years ago
parent c00158d23a
commit 96ccb94397

@ -367,7 +367,7 @@ define([
return "Loading share button"; return "Loading share button";
}; };
var createFileShare = function () { var createFileShare = function (toolbar) {
if (!window.location.hash) { if (!window.location.hash) {
throw new Error("Unable to display the share button: hash required in the URL"); throw new Error("Unable to display the share button: hash required in the URL");
} }
@ -380,6 +380,7 @@ define([
if (success) { Cryptpad.log(Messages.shareSuccess); } if (success) { Cryptpad.log(Messages.shareSuccess); }
}); });
toolbar.$leftside.append($button);
return $button; return $button;
}; };
@ -852,7 +853,7 @@ define([
tb['useradmin'] = createUserAdmin; tb['useradmin'] = createUserAdmin;
var addElement = function (arr, additionnalCfg, init) { var addElement = toolbar.addElement = function (arr, additionnalCfg, init) {
if (typeof additionnalCfg === "object") { $.extend(true, config, additionnalCfg); } if (typeof additionnalCfg === "object") { $.extend(true, config, additionnalCfg); }
arr.forEach(function (el) { arr.forEach(function (el) {
if (typeof el !== "string" || !el.trim()) { return; } if (typeof el !== "string" || !el.trim()) { return; }

@ -2,7 +2,7 @@ define([
'jquery', 'jquery',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/common/toolbar.js', '/common/toolbar2.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/visible.js', '/common/visible.js',
'/common/notify.js', '/common/notify.js',
@ -24,6 +24,8 @@ define([
Cryptpad.addLoadingScreen(); Cryptpad.addLoadingScreen();
var Title;
var myFile; var myFile;
var myDataType; var myDataType;
@ -68,17 +70,13 @@ define([
var uri = ['', 'blob', id.slice(0,2), id].join('/'); var uri = ['', 'blob', id.slice(0,2), id].join('/');
console.log("encrypted blob is now available as %s", uri); console.log("encrypted blob is now available as %s", uri);
// TODO use cryptpad-common utilities var b64Key = Nacl.util.encodeBase64(key);
window.location.hash = [ window.location.hash = Cryptpad.getFileHashFromKeys(id, ib64key);
'',
2,
Cryptpad.hexToBase64(id).replace(/\//g, '-'),
Nacl.util.encodeBase64(key).replace(/\//g, '-'),
''
].join('/');
$form.hide(); $form.hide();
APP.toolbar.addElement(['fileshare'], {});
// check if the uploaded file can be decrypted // check if the uploaded file can be decrypted
var newU8 = FileCrypto.joinChunks(chunks); var newU8 = FileCrypto.joinChunks(chunks);
FileCrypto.decrypt(newU8, key, function (e, res) { FileCrypto.decrypt(newU8, key, function (e, res) {
@ -88,7 +86,8 @@ define([
myDataType = res.metadata.type; myDataType = res.metadata.type;
var defaultName = Cryptpad.getDefaultName(Cryptpad.parsePadUrl(window.location.href)); var defaultName = Cryptpad.getDefaultName(Cryptpad.parsePadUrl(window.location.href));
APP.updateTitle(title || defaultName); Title.updateTitle(title || defaultName);
APP.toolbar.title.show();
Cryptpad.alert("successfully uploaded: " + title); Cryptpad.alert("successfully uploaded: " + title);
}); });
}); });
@ -133,9 +132,6 @@ define([
uploadMode = true; uploadMode = true;
} }
var parsed = Cryptpad.parsePadUrl(window.location.href);
var defaultName = Cryptpad.getDefaultName(parsed);
var getTitle = function () { var getTitle = function () {
var pad = Cryptpad.getRelativeHref(window.location.href); var pad = Cryptpad.getRelativeHref(window.location.href);
var fo = Cryptpad.getStore().getProxy().fo; var fo = Cryptpad.getStore().getProxy().fo;
@ -143,27 +139,6 @@ define([
return data ? data.title : undefined; return data ? data.title : undefined;
}; };
var updateTitle = APP.updateTitle = function (newTitle) {
Cryptpad.renamePad(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
return;
}
document.title = newTitle;
$bar.find('.' + Toolbar.constants.title).find('span.title').text(data);
$bar.find('.' + Toolbar.constants.title).find('input').val(data);
});
};
var suggestName = function () {
return document.title || getTitle() || '';
};
var renameCb = function (err, title) {
document.title = title;
};
var exportFile = function () { var exportFile = function () {
var suggestion = document.title; var suggestion = document.title;
Cryptpad.prompt(Messages.exportPrompt, Cryptpad.prompt(Messages.exportPrompt,
@ -174,33 +149,33 @@ define([
}); });
}; };
var displayed = ['useradmin', 'newpad', 'limit']; Title = Cryptpad.createTitle({}, function(){}, Cryptpad);
var displayed = ['title', 'useradmin', 'newpad', 'limit'];
if (secret && hexFileName) { if (secret && hexFileName) {
displayed.push('share'); displayed.push('fileshare');
} }
var configTb = { var configTb = {
displayed: displayed, displayed: displayed,
ifrw: ifrw, ifrw: ifrw,
common: Cryptpad, common: Cryptpad,
title: { title: Title.getTitleConfig(),
onRename: renameCb, hideDisplayName: true,
defaultName: defaultName, $container: $bar
suggestName: suggestName
},
share: {
secret: secret,
channel: hexFileName
},
hideDisplayName: true
}; };
Toolbar.create($bar, null, null, null, null, configTb); var toolbar = APP.toolbar = Toolbar.create(configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
Title.setToolbar(toolbar);
if (uploadMode) { toolbar.title.hide(); }
var $rightside = toolbar.$rightside;
var $export = Cryptpad.createButton('export', true, {}, exportFile); var $export = Cryptpad.createButton('export', true, {}, exportFile);
$rightside.append($export); $rightside.append($export);
updateTitle(Cryptpad.initialName || getTitle() || defaultName); Title.updateTitle(Cryptpad.initialName || getTitle() || Title.defaultTitle);
if (!uploadMode) { if (!uploadMode) {
var src = Cryptpad.getBlobPathFromHex(hexFileName); var src = Cryptpad.getBlobPathFromHex(hexFileName);
@ -219,7 +194,7 @@ define([
var title = document.title = data.metadata.name; var title = document.title = data.metadata.name;
myFile = data.content; myFile = data.content;
myDataType = data.metadata.type; myDataType = data.metadata.type;
updateTitle(title || defaultName); Title.updateTitle(title || Title.defaultTitle);
Cryptpad.removeLoadingScreen(); Cryptpad.removeLoadingScreen();
}); });
}); });

Loading…
Cancel
Save