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-02-13 19:32:59 +00:00
|
|
|
<label class="red" for="password-input">
|
2018-01-24 18:23:13 +00:00
|
|
|
${state.translate('passwordTryAgain')}
|
|
|
|
</label>`
|
2017-08-31 16:43:36 +00:00
|
|
|
: html`
|
2018-02-13 19:32:59 +00:00
|
|
|
<label for="password-input">
|
2017-08-31 16:43:36 +00:00
|
|
|
${state.translate('unlockInputLabel')}
|
|
|
|
</label>`;
|
|
|
|
const div = html`
|
2018-02-13 19:32:59 +00:00
|
|
|
<div class="passwordSection">
|
2017-08-31 16:43:36 +00:00
|
|
|
${label}
|
2018-02-13 19:32:59 +00:00
|
|
|
<form class="passwordForm" onsubmit=${checkPassword} data-no-csrf>
|
|
|
|
<input id="password-input"
|
2018-02-19 22:02:06 +00:00
|
|
|
class="input input--noBtn"
|
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"
|
2018-02-13 19:32:59 +00:00
|
|
|
id="password-btn"
|
2018-02-19 22:02:06 +00:00
|
|
|
class="inputBtn inputBtn--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)) {
|
2018-02-13 19:32:59 +00:00
|
|
|
setTimeout(() => document.getElementById('password-input').focus());
|
2018-02-12 17:53:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 21:27:54 +00:00
|
|
|
function inputChanged() {
|
2018-02-13 19:32:59 +00:00
|
|
|
const input = document.getElementById('password-input');
|
|
|
|
const btn = document.getElementById('password-btn');
|
2017-11-02 21:27:54 +00:00
|
|
|
if (input.value.length > 0) {
|
2018-02-13 19:32:59 +00:00
|
|
|
btn.classList.remove('inputBtn--hidden');
|
|
|
|
input.classList.remove('input--noBtn');
|
2017-11-02 21:27:54 +00:00
|
|
|
} else {
|
2018-02-13 19:32:59 +00:00
|
|
|
btn.classList.add('inputBtn--hidden');
|
|
|
|
input.classList.add('input--noBtn');
|
2017-11-02 21:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
function checkPassword(event) {
|
|
|
|
event.preventDefault();
|
2018-02-13 19:32:59 +00:00
|
|
|
const password = document.getElementById('password-input').value;
|
2017-08-31 16:43:36 +00:00
|
|
|
if (password.length > 0) {
|
2018-02-13 19:32:59 +00:00
|
|
|
document.getElementById('password-btn').disabled = true;
|
2017-08-31 16:43:36 +00:00
|
|
|
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;
|
|
|
|
};
|