send/app/templates/uploadPassword.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

const html = require('choo/html');
module.exports = function(state, emit) {
const file = state.storage.getFileById(state.params.id);
const div = html`
<div class="selectPassword">
2017-10-23 14:36:07 +00:00
<div id="addPasswordWrapper">
<input id="addPassword" type="checkbox" onchange=${togglePasswordInput}/>
2017-10-23 14:36:07 +00:00
<label for="addPassword">
${state.translate('requirePasswordCheckbox')}</label>
</div>
<form class="setPassword hidden" onsubmit=${setPassword}>
<input id="unlock-input"
2017-10-25 14:50:37 +00:00
maxlength="64"
autocomplete="off"
placeholder="${state.translate('unlockInputPlaceholder')}"/>
<input type="submit"
id="unlock-btn"
class="btn"
value="${state.translate('addPasswordButton')}"/>
</form>
</div>`;
function togglePasswordInput() {
document.querySelector('.setPassword').classList.toggle('hidden');
}
function setPassword(event) {
event.preventDefault();
const password = document.getElementById('unlock-input').value;
if (password.length > 0) {
emit('password', { password, file });
}
}
return div;
};