send/app/templates/downloadPassword/index.js

61 lines
1.7 KiB
JavaScript
Raw Normal View History

const html = require('choo/html');
module.exports = function(state, emit) {
const fileInfo = state.fileInfo;
2018-02-20 20:21:00 +00:00
const invalid = fileInfo.password === null;
2018-07-31 18:09:18 +00:00
const visible = invalid ? 'visible' : '';
const invalidBtn = invalid ? 'unlockBtn--error' : '';
const div = html`
<div class="passwordSection">
2018-07-31 18:09:18 +00:00
<label
class="error passwordForm__error ${visible}"
for="password-input">
${state.translate('passwordTryAgain')}
</label>
<form class="passwordForm" onsubmit=${checkPassword} data-no-csrf>
<input id="password-input"
2018-07-31 18:09:18 +00:00
class="input passwordForm__input"
2017-10-25 14:50:37 +00:00
maxlength="64"
autocomplete="off"
placeholder="${state.translate('unlockInputPlaceholder')}"
oninput=${inputChanged}
type="password" />
2018-07-31 18:09:18 +00:00
<input type="submit"
id="password-btn"
2018-07-31 18:09:18 +00:00
class="btn unlockBtn ${invalidBtn}"
value="${state.translate('unlockInputLabel')}"/>
</form>
</div>`;
if (!(div instanceof String)) {
setTimeout(() => document.getElementById('password-input').focus());
}
function inputChanged() {
2018-07-31 18:09:18 +00:00
const input = document.querySelector('.passwordForm__error');
input.classList.remove('visible');
const btn = document.getElementById('password-btn');
2018-07-31 18:09:18 +00:00
btn.classList.remove('unlockBtn--error');
}
function checkPassword(event) {
event.preventDefault();
const password = document.getElementById('password-input').value;
if (password.length > 0) {
document.getElementById('password-btn').disabled = true;
state.fileInfo.url = window.location.href;
state.fileInfo.password = password;
2018-01-24 18:23:13 +00:00
emit('getMetadata');
}
2018-02-01 20:49:18 +00:00
return false;
}
return div;
};