index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const html = require('choo/html');
  2. const passwordInput = require('../passwordInput');
  3. module.exports = function(state, emit) {
  4. const file = state.storage.getFileById(state.params.id);
  5. return html`
  6. <div class="setPasswordSection">
  7. <div class="checkbox">
  8. <input
  9. ${file.hasPassword ? 'disabled' : ''}
  10. ${file.hasPassword || state.passwordSetError ? 'checked' : ''}
  11. class="checkbox__input"
  12. id="add-password"
  13. type="checkbox"
  14. autocomplete="off"
  15. onchange=${togglePasswordInput}/>
  16. <label class="checkbox__label" for="add-password">
  17. ${state.translate('requirePasswordCheckbox')}
  18. </label>
  19. </div>
  20. ${passwordInput(file, state, emit)}
  21. </div>`;
  22. function togglePasswordInput(e) {
  23. const unlockInput = document.getElementById('password-input');
  24. const boxChecked = e.target.checked;
  25. document
  26. .querySelector('.passwordInput')
  27. .classList.toggle('passwordInput--hidden', !boxChecked);
  28. if (boxChecked) {
  29. unlockInput.focus();
  30. } else {
  31. unlockInput.value = '';
  32. }
  33. }
  34. };