1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-11 13:42:56 +01:00
send/app/templates/uploadPassword.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

const html = require('choo/html');
module.exports = function(state, emit) {
const file = state.storage.getFileById(state.params.id);
const div = html`
<div class="selectPassword">
2017-10-23 16:36:07 +02:00
<div id="addPasswordWrapper">
2017-12-21 10:47:31 +01:00
<input id="addPassword" type="checkbox" autocomplete="off" onchange=${togglePasswordInput}/>
2017-10-23 16:36:07 +02:00
<label for="addPassword">
${state.translate('requirePasswordCheckbox')}</label>
</div>
<form class="setPassword hidden" onsubmit=${setPassword} data-no-csrf>
<input id="unlock-input"
class="unlock-input input-no-btn"
2017-10-25 16:50:37 +02:00
maxlength="64"
autocomplete="off"
placeholder="${state.translate('unlockInputPlaceholder')}"
2017-12-21 10:47:31 +01:00
type="password"
oninput=${inputChanged}/>
<input type="submit"
id="unlock-btn"
class="btn btn-hidden"
value="${state.translate('addPasswordButton')}"/>
</form>
</div>`;
function inputChanged() {
const input = document.getElementById('unlock-input');
const btn = document.getElementById('unlock-btn');
if (input.value.length > 0) {
btn.classList.remove('btn-hidden');
input.classList.remove('input-no-btn');
} else {
btn.classList.add('btn-hidden');
input.classList.add('input-no-btn');
}
}
function togglePasswordInput(e) {
2017-10-24 19:00:27 +02:00
const unlockInput = document.getElementById('unlock-input');
const boxChecked = e.target.checked;
2017-11-02 00:36:45 +01:00
document
.querySelector('.setPassword')
.classList.toggle('hidden', !boxChecked);
2017-10-24 19:00:27 +02:00
if (boxChecked) {
unlockInput.focus();
} else {
unlockInput.value = '';
}
inputChanged();
}
function setPassword(event) {
event.preventDefault();
2018-01-14 15:49:10 +01:00
const existingPassword = null;
const password = document.getElementById('unlock-input').value;
if (password.length > 0) {
document.getElementById('copy').classList.remove('wait-password');
document.getElementById('copy-btn').disabled = false;
2018-01-14 15:49:10 +01:00
emit('password', { existingPassword, password, file });
}
}
return div;
};