Enable the read-only mode in Cryptpoll
This commit is contained in:
parent
ad32ea2a82
commit
99004428d5
@ -151,6 +151,7 @@ define([
|
|||||||
|
|
||||||
var onLocal = config.onLocal = function () {
|
var onLocal = config.onLocal = function () {
|
||||||
if (initializing) { return; }
|
if (initializing) { return; }
|
||||||
|
if (readOnly) { return; }
|
||||||
|
|
||||||
editor.save();
|
editor.save();
|
||||||
var textValue = canonicalize($textarea.val());
|
var textValue = canonicalize($textarea.val());
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
<div id="toolbar" class="buttons">
|
<div id="toolbar" class="buttons">
|
||||||
<sub><a href="/"></a></sub>
|
<sub><a href="/"></a></sub>
|
||||||
</div>
|
</div>
|
||||||
<h1>CryptPoll</h1>
|
<h1 id="mainTitle">CryptPoll</h1>
|
||||||
<h2 data-localization="poll_subtitle"></h2>
|
<h2 data-localization="poll_subtitle"></h2>
|
||||||
|
|
||||||
<p data-localization="poll_p_save"></p>
|
<p data-localization="poll_p_save"></p>
|
||||||
@ -53,7 +53,7 @@
|
|||||||
<input type="text" id="title" placeholder="title"><br />
|
<input type="text" id="title" placeholder="title"><br />
|
||||||
<textarea id="description" placeholder="description"></textarea>
|
<textarea id="description" placeholder="description"></textarea>
|
||||||
|
|
||||||
<p data-localization="poll_p_howtouse"></p>
|
<p id="howToUse" data-localization="poll_p_howtouse"></p>
|
||||||
|
|
||||||
<!-- Table markup-->
|
<!-- Table markup-->
|
||||||
<table id="table">
|
<table id="table">
|
||||||
|
|||||||
@ -39,6 +39,14 @@ define([
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var secret = Cryptpad.getSecrets();
|
var secret = Cryptpad.getSecrets();
|
||||||
|
var readOnly = secret.keys && !secret.keys.editKeyStr;
|
||||||
|
if (!secret.keys) {
|
||||||
|
secret.keys = secret.key;
|
||||||
|
}
|
||||||
|
if (readOnly) {
|
||||||
|
$('#mainTitle').html($('#mainTitle').html() + ' - ' + Messages.readonly);
|
||||||
|
$('#adduser, #addoption, #howToUse').remove();
|
||||||
|
}
|
||||||
|
|
||||||
var module = window.APP = {
|
var module = window.APP = {
|
||||||
Cryptpad: Cryptpad,
|
Cryptpad: Cryptpad,
|
||||||
@ -139,6 +147,7 @@ define([
|
|||||||
var table = module.table = Table($('#table'), xy);
|
var table = module.table = Table($('#table'), xy);
|
||||||
|
|
||||||
var setEditable = function (bool) {
|
var setEditable = function (bool) {
|
||||||
|
if (readOnly && bool) { return; }
|
||||||
module.isEditable = bool;
|
module.isEditable = bool;
|
||||||
|
|
||||||
items.forEach(function ($item) {
|
items.forEach(function ($item) {
|
||||||
@ -163,6 +172,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var removeRow = function (proxy, uid) {
|
var removeRow = function (proxy, uid) {
|
||||||
|
if (readOnly) { return; }
|
||||||
// remove proxy.table.rows[uid]
|
// remove proxy.table.rows[uid]
|
||||||
|
|
||||||
proxy.table.rows[uid] = undefined;
|
proxy.table.rows[uid] = undefined;
|
||||||
@ -186,6 +196,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var removeColumn = function (proxy, uid) {
|
var removeColumn = function (proxy, uid) {
|
||||||
|
if (readOnly) { return; }
|
||||||
// remove proxy.table.cols[uid]
|
// remove proxy.table.cols[uid]
|
||||||
proxy.table.cols[uid] = undefined;
|
proxy.table.cols[uid] = undefined;
|
||||||
delete proxy.table.rows[uid];
|
delete proxy.table.rows[uid];
|
||||||
@ -212,6 +223,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var makeUserEditable = module.makeUserEditable = function (id, bool) {
|
var makeUserEditable = module.makeUserEditable = function (id, bool) {
|
||||||
|
if (readOnly) { return; }
|
||||||
var $name = $('input[type="text"][id="' + id + '"]').attr('disabled', !bool);
|
var $name = $('input[type="text"][id="' + id + '"]').attr('disabled', !bool);
|
||||||
|
|
||||||
var $edit = $name.parent().find('.edit');
|
var $edit = $name.parent().find('.edit');
|
||||||
@ -289,6 +301,11 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (readOnly) {
|
||||||
|
$edit = '';
|
||||||
|
$remove = '';
|
||||||
|
}
|
||||||
|
|
||||||
var $wrapper = $('<div>', {
|
var $wrapper = $('<div>', {
|
||||||
'class': 'text-cell',
|
'class': 'text-cell',
|
||||||
})
|
})
|
||||||
@ -313,6 +330,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var makeOptionEditable = function (id, bool) {
|
var makeOptionEditable = function (id, bool) {
|
||||||
|
if (readOnly) { return; }
|
||||||
if (bool) {
|
if (bool) {
|
||||||
module.rt.proxy.table.rowsOrder.forEach(function (rowuid) {
|
module.rt.proxy.table.rowsOrder.forEach(function (rowuid) {
|
||||||
$('#' + rowuid)
|
$('#' + rowuid)
|
||||||
@ -363,6 +381,11 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (readOnly) {
|
||||||
|
$edit = '';
|
||||||
|
$remove = '';
|
||||||
|
}
|
||||||
|
|
||||||
var $wrapper = $('<div>', {
|
var $wrapper = $('<div>', {
|
||||||
'class': 'text-cell',
|
'class': 'text-cell',
|
||||||
})
|
})
|
||||||
@ -715,6 +738,7 @@ define([
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (!readOnly) {
|
||||||
$toolbar.append(Button({
|
$toolbar.append(Button({
|
||||||
id: 'wizard',
|
id: 'wizard',
|
||||||
'class': 'wizard button action',
|
'class': 'wizard button action',
|
||||||
@ -725,6 +749,22 @@ define([
|
|||||||
Cryptpad.log(Messages.wizardLog);
|
Cryptpad.log(Messages.wizardLog);
|
||||||
Wizard.hasBeenDisplayed = true;
|
Wizard.hasBeenDisplayed = true;
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!readOnly && module.viewHash) {
|
||||||
|
/* add a 'links' button */
|
||||||
|
var $links = $('<button>', {
|
||||||
|
title: Messages.getViewButtonTitle
|
||||||
|
})
|
||||||
|
.text(Messages.getViewButton)
|
||||||
|
.addClass('button action')
|
||||||
|
.click(function () {
|
||||||
|
var baseUrl = window.location.origin + window.location.pathname + '#';
|
||||||
|
var content = '<b>' + Messages.readonlyUrl + '</b><br><a>' + baseUrl + module.viewHash + '</a><br>';
|
||||||
|
Cryptpad.alert(content);
|
||||||
|
});
|
||||||
|
$toolbar.append($links);
|
||||||
|
}
|
||||||
|
|
||||||
/* Import/Export buttons */
|
/* Import/Export buttons */
|
||||||
/*
|
/*
|
||||||
@ -784,6 +824,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
Cryptpad.getPadAttribute('column', function (err, column) {
|
Cryptpad.getPadAttribute('column', function (err, column) {
|
||||||
|
if (readOnly) { return; }
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("unable to retrieve column");
|
console.log("unable to retrieve column");
|
||||||
return;
|
return;
|
||||||
@ -831,7 +872,10 @@ define([
|
|||||||
websocketURL: Config.websocketURL,
|
websocketURL: Config.websocketURL,
|
||||||
channel: secret.channel,
|
channel: secret.channel,
|
||||||
data: {},
|
data: {},
|
||||||
crypto: Crypto.createEncryptor(secret.key),
|
// our public key
|
||||||
|
validateKey: secret.keys.validateKey || undefined,
|
||||||
|
readOnly: readOnly,
|
||||||
|
crypto: Crypto.createEncryptor(secret.keys),
|
||||||
};
|
};
|
||||||
|
|
||||||
// don't initialize until the store is ready.
|
// don't initialize until the store is ready.
|
||||||
@ -840,7 +884,17 @@ define([
|
|||||||
var rt = module.rt = Listmap.create(config);
|
var rt = module.rt = Listmap.create(config);
|
||||||
rt.proxy.on('create', function (info) {
|
rt.proxy.on('create', function (info) {
|
||||||
var realtime = module.realtime = info.realtime;
|
var realtime = module.realtime = info.realtime;
|
||||||
window.location.hash = Cryptpad.getHashFromKeys(info.channel, secret.key);
|
|
||||||
|
var editHash;
|
||||||
|
var viewHash = module.viewHash = Cryptpad.getViewHashFromKeys(info.channel, secret.keys);
|
||||||
|
if (!readOnly) {
|
||||||
|
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
|
||||||
|
}
|
||||||
|
// set the hash
|
||||||
|
if (!readOnly) {
|
||||||
|
window.location.hash = editHash;
|
||||||
|
}
|
||||||
|
|
||||||
module.patchText = TextPatcher.create({
|
module.patchText = TextPatcher.create({
|
||||||
realtime: realtime,
|
realtime: realtime,
|
||||||
logging: true,
|
logging: true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user