mirror of
https://gitlab.com/timvisee/send.git
synced 2024-11-11 13:42:56 +01:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
const html = require('choo/html');
|
|
const passwordInput = require('../passwordInput');
|
|
|
|
module.exports = function(state, emit) {
|
|
const file = state.storage.getFileById(state.params.id);
|
|
|
|
return html`
|
|
<div class="setPasswordSection">
|
|
<div class="checkbox">
|
|
<input
|
|
${file.hasPassword ? 'disabled' : ''}
|
|
${file.hasPassword || state.passwordSetError ? 'checked' : ''}
|
|
class="checkbox__input"
|
|
id="add-password"
|
|
type="checkbox"
|
|
autocomplete="off"
|
|
onchange=${togglePasswordInput}/>
|
|
<label class="checkbox__label" for="add-password">
|
|
${state.translate('requirePasswordCheckbox')}
|
|
</label>
|
|
</div>
|
|
${passwordInput(file, state, emit)}
|
|
</div>`;
|
|
|
|
function togglePasswordInput(e) {
|
|
const unlockInput = document.getElementById('password-input');
|
|
const boxChecked = e.target.checked;
|
|
document
|
|
.querySelector('.passwordInput')
|
|
.classList.toggle('passwordInput--hidden', !boxChecked);
|
|
if (boxChecked) {
|
|
unlockInput.focus();
|
|
} else {
|
|
unlockInput.value = '';
|
|
}
|
|
}
|
|
};
|