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