2017-08-31 16:43:36 +00:00
|
|
|
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">
|
2017-08-31 16:43:36 +00:00
|
|
|
<input id="addPassword" type="checkbox" onchange=${togglePasswordInput}/>
|
2017-10-23 14:36:07 +00:00
|
|
|
<label for="addPassword">
|
|
|
|
${state.translate('requirePasswordCheckbox')}</label>
|
2017-08-31 16:43:36 +00:00
|
|
|
</div>
|
|
|
|
<form class="setPassword hidden" onsubmit=${setPassword}>
|
|
|
|
<input id="unlock-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')}"/>
|
|
|
|
<input type="submit"
|
|
|
|
id="unlock-btn"
|
|
|
|
class="btn"
|
|
|
|
value="${state.translate('addPasswordButton')}"/>
|
|
|
|
</form>
|
|
|
|
</div>`;
|
|
|
|
|
2017-10-23 13:51:33 +00:00
|
|
|
function togglePasswordInput(e) {
|
2017-10-24 17:00:27 +00:00
|
|
|
const unlockInput = document.getElementById('unlock-input');
|
|
|
|
const boxChecked = e.target.checked;
|
2017-11-01 23:36:45 +00:00
|
|
|
document
|
|
|
|
.querySelector('.setPassword')
|
|
|
|
.classList.toggle('hidden', !boxChecked);
|
2017-10-23 13:51:33 +00:00
|
|
|
document
|
|
|
|
.getElementById('copy')
|
2017-10-24 17:00:27 +00:00
|
|
|
.classList.toggle('wait-password', boxChecked);
|
|
|
|
document.getElementById('copy-btn').disabled = boxChecked;
|
|
|
|
if (boxChecked) {
|
|
|
|
unlockInput.focus();
|
|
|
|
} else {
|
|
|
|
unlockInput.value = '';
|
2017-10-24 16:47:03 +00:00
|
|
|
}
|
2017-08-31 16:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setPassword(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const password = document.getElementById('unlock-input').value;
|
|
|
|
if (password.length > 0) {
|
2017-10-23 13:51:33 +00:00
|
|
|
document.getElementById('copy').classList.remove('wait-password');
|
|
|
|
document.getElementById('copy-btn').disabled = false;
|
2017-08-31 16:43:36 +00:00
|
|
|
emit('password', { password, file });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return div;
|
|
|
|
};
|