Enable read-only mode in slides

pull/1/head
Yann Flory 8 years ago
parent 73d5ea967b
commit eac0cdd6dd

@ -32,6 +32,11 @@ define([
Cryptpad.styleAlerts(); Cryptpad.styleAlerts();
var secret = Cryptpad.getSecrets(); var secret = Cryptpad.getSecrets();
var readOnly = secret.keys && !secret.keys.editKeyStr;
Slide.readOnly = readOnly;
if (!secret.keys) {
secret.keys = secret.key;
}
var APP = window.APP = { var APP = window.APP = {
TextPatcher: TextPatcher, TextPatcher: TextPatcher,
@ -72,14 +77,30 @@ define([
var $content = $('#content'); var $content = $('#content');
Slide.setModal($modal, $content); Slide.setModal($modal, $content);
var enterPresentationMode = function (shouldLog) {
Slide.show(true, $textarea.val());
if (shouldLog) {
Cryptpad.log(Messages.presentSuccess);
}
};
if (readOnly) {
enterPresentationMode(false);
}
var config = APP.config = { var config = APP.config = {
initialState: '{}', initialState: '{}',
websocketURL: Config.websocketURL, websocketURL: Config.websocketURL,
channel: secret.channel, channel: secret.channel,
crypto: Crypto.createEncryptor(secret.key), crypto: Crypto.createEncryptor(secret.keys),
validateKey: secret.keys.validateKey || undefined,
readOnly: readOnly,
}; };
var setEditable = function (bool) { $textarea.attr('disabled', !bool); }; var setEditable = function (bool) {
if (readOnly && bool) { return; }
$textarea.attr('disabled', !bool);
};
var canonicalize = function (text) { return text.replace(/\r\n/g, '\n'); }; var canonicalize = function (text) { return text.replace(/\r\n/g, '\n'); };
setEditable(false); setEditable(false);
@ -101,6 +122,7 @@ define([
var onLocal = config.onLocal = function () { var onLocal = config.onLocal = function () {
if (initializing) { return; } if (initializing) { return; }
if (readOnly) { return; }
var textContent = canonicalize($textarea.val()); var textContent = canonicalize($textarea.val());
@ -119,7 +141,13 @@ define([
}; };
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
window.location.hash = Cryptpad.getHashFromKeys(info.channel, secret.key); var editHash;
var viewHash = Cryptpad.getViewHashFromKeys(info.channel, secret.keys);
if (!readOnly) {
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
window.location.hash = editHash;
}
$(window).on('hashchange', function() { $(window).on('hashchange', function() {
window.location.reload(); window.location.reload();
}); });
@ -147,8 +175,7 @@ define([
}) })
.text(Messages.presentButton) .text(Messages.presentButton)
.click(function () { .click(function () {
Slide.show(true, $textarea.val()); enterPresentationMode(true);
Cryptpad.log(Messages.presentSuccess);
}); });
var $forget = Button({ var $forget = Button({
@ -247,13 +274,35 @@ define([
Cryptpad.warn(Messages.shareFailed); Cryptpad.warn(Messages.shareFailed);
}); });
/* add a 'links' button */
var $links = Button({
title: Messages.getViewButtonTitle,
'class': 'links button action',
})
.text(Messages.getViewButton)
.click(function () {
var baseUrl = window.location.origin + window.location.pathname + '#';
var content = '<b>' + Messages.readonlyUrl + '</b><br><a>' + baseUrl + viewHash + '</a><br>';
Cryptpad.alert(content);
});
if (readOnly) {
$links = '';
$import = '';
$present = '';
}
if (!viewHash) {
$links = '';
}
$bar $bar
.append($present) .append($present)
.append($forget) .append($forget)
.append($rename) .append($rename)
.append($import) .append($import)
.append($export) .append($export)
.append($share); .append($share)
.append($links);
}; };
var onRemote = config.onRemote = function (info) { var onRemote = config.onRemote = function (info) {
if (initializing) { return; } if (initializing) { return; }

@ -160,7 +160,9 @@ define([
Slide.right(); Slide.right();
break; break;
case 27: // esc case 27: // esc
show(false); if (!Slide.readOnly) {
show(false);
}
break; break;
default: default:
console.log(e.which); console.log(e.which);

Loading…
Cancel
Save