2017-08-31 16:43:36 +00:00
|
|
|
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' : '';
|
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
const div = html`
|
2018-02-13 19:32:59 +00:00
|
|
|
<div class="passwordSection">
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
<label
|
|
|
|
class="error passwordForm__error ${visible}"
|
|
|
|
for="password-input">
|
|
|
|
${state.translate('passwordTryAgain')}
|
|
|
|
</label>
|
|
|
|
|
2018-02-13 19:32:59 +00:00
|
|
|
<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"
|
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" />
|
2018-07-31 18:09:18 +00:00
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
<input type="submit"
|
2018-02-13 19:32:59 +00:00
|
|
|
id="password-btn"
|
2018-07-31 18:09:18 +00:00
|
|
|
class="btn unlockBtn ${invalidBtn}"
|
|
|
|
value="${state.translate('unlockInputLabel')}"/>
|
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
</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-07-31 18:09:18 +00:00
|
|
|
const input = document.querySelector('.passwordForm__error');
|
|
|
|
input.classList.remove('visible');
|
2018-02-13 19:32:59 +00:00
|
|
|
const btn = document.getElementById('password-btn');
|
2018-07-31 18:09:18 +00:00
|
|
|
btn.classList.remove('unlockBtn--error');
|
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;
|
|
|
|
};
|