2018-02-13 20:32:59 +01:00
|
|
|
const html = require('choo/html');
|
|
|
|
const passwordInput = require('../passwordInput');
|
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
const file = state.storage.getFileById(state.params.id);
|
2018-02-16 21:56:53 +01:00
|
|
|
|
|
|
|
return html`
|
2018-02-13 20:32:59 +01:00
|
|
|
<div class="setPasswordSection">
|
|
|
|
<div class="checkbox">
|
|
|
|
<input
|
2018-02-16 21:56:53 +01:00
|
|
|
${file.hasPassword ? 'disabled' : ''}
|
|
|
|
${file.hasPassword ? 'checked' : ''}
|
2018-02-13 20:32:59 +01:00
|
|
|
class="checkbox__input"
|
|
|
|
id="add-password"
|
|
|
|
type="checkbox"
|
|
|
|
autocomplete="off"
|
|
|
|
onchange=${togglePasswordInput}/>
|
|
|
|
<label class="checkbox__label" for="add-password">
|
|
|
|
${state.translate('requirePasswordCheckbox')}
|
|
|
|
</label>
|
|
|
|
</div>
|
2018-02-16 21:56:53 +01:00
|
|
|
${passwordInput(file, state, emit)}
|
2018-02-13 20:32:59 +01:00
|
|
|
</div>`;
|
|
|
|
|
|
|
|
function togglePasswordInput(e) {
|
|
|
|
const unlockInput = document.getElementById('password-input');
|
|
|
|
const boxChecked = e.target.checked;
|
|
|
|
document
|
|
|
|
.querySelector('form.passwordInput')
|
|
|
|
.classList.toggle('passwordInput--hidden', !boxChecked);
|
|
|
|
if (boxChecked) {
|
|
|
|
unlockInput.focus();
|
|
|
|
} else {
|
|
|
|
unlockInput.value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|