2017-08-31 16:43:36 +00:00
|
|
|
const html = require('choo/html');
|
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
const fileInfo = state.fileInfo;
|
|
|
|
const label =
|
|
|
|
fileInfo.password === null
|
|
|
|
? html`
|
2018-01-24 18:23:13 +00:00
|
|
|
<label class="red" for="unlock-input">
|
|
|
|
${state.translate('passwordTryAgain')}
|
|
|
|
</label>`
|
2017-08-31 16:43:36 +00:00
|
|
|
: html`
|
|
|
|
<label for="unlock-input">
|
|
|
|
${state.translate('unlockInputLabel')}
|
|
|
|
</label>`;
|
|
|
|
const div = html`
|
|
|
|
<div class="enterPassword">
|
|
|
|
${label}
|
2017-11-06 21:36:36 +00:00
|
|
|
<form id="unlock" onsubmit=${checkPassword} data-no-csrf>
|
2017-08-31 16:43:36 +00:00
|
|
|
<input id="unlock-input"
|
2017-11-02 21:27:54 +00:00
|
|
|
class="unlock-input input-no-btn"
|
2017-10-25 14:50:37 +00:00
|
|
|
maxlength="64"
|
2017-08-31 16:43:36 +00:00
|
|
|
autocomplete="off"
|
|
|
|
placeholder="${state.translate('unlockInputPlaceholder')}"
|
2017-11-02 21:27:54 +00:00
|
|
|
oninput=${inputChanged}
|
2018-02-12 17:53:34 +00:00
|
|
|
type="password" />
|
2017-08-31 16:43:36 +00:00
|
|
|
<input type="submit"
|
|
|
|
id="unlock-btn"
|
2017-11-02 21:27:54 +00:00
|
|
|
class="btn btn-hidden"
|
2017-08-31 16:43:36 +00:00
|
|
|
value="${state.translate('unlockButtonLabel')}"/>
|
|
|
|
</form>
|
|
|
|
</div>`;
|
|
|
|
|
2018-02-12 17:53:34 +00:00
|
|
|
if (!(div instanceof String)) {
|
|
|
|
setTimeout(() => document.querySelector('#unlock-input').focus());
|
|
|
|
}
|
|
|
|
|
2017-11-02 21:27:54 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
function checkPassword(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const password = document.getElementById('unlock-input').value;
|
|
|
|
if (password.length > 0) {
|
|
|
|
document.getElementById('unlock-btn').disabled = true;
|
|
|
|
state.fileInfo.url = window.location.href;
|
|
|
|
state.fileInfo.password = password;
|
2018-01-24 18:23:13 +00:00
|
|
|
emit('getMetadata');
|
2017-08-31 16:43:36 +00:00
|
|
|
}
|
2018-02-01 20:49:18 +00:00
|
|
|
return false;
|
2017-08-31 16:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return div;
|
|
|
|
};
|