2017-08-31 18:43:36 +02: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 16:36:07 +02:00
|
|
|
<div id="addPasswordWrapper">
|
2018-01-24 19:23:13 +01:00
|
|
|
<input
|
|
|
|
id="addPassword"
|
|
|
|
type="checkbox"
|
|
|
|
autocomplete="off"
|
|
|
|
onchange=${togglePasswordInput}/>
|
2017-10-23 16:36:07 +02:00
|
|
|
<label for="addPassword">
|
2018-01-24 19:23:13 +01:00
|
|
|
${state.translate('requirePasswordCheckbox')}
|
|
|
|
</label>
|
2017-08-31 18:43:36 +02:00
|
|
|
</div>
|
2017-11-06 22:36:36 +01:00
|
|
|
<form class="setPassword hidden" onsubmit=${setPassword} data-no-csrf>
|
2017-08-31 18:43:36 +02:00
|
|
|
<input id="unlock-input"
|
2017-11-02 22:27:54 +01:00
|
|
|
class="unlock-input input-no-btn"
|
2018-01-20 01:53:57 +01:00
|
|
|
maxlength="32"
|
2017-08-31 18:43:36 +02:00
|
|
|
autocomplete="off"
|
2017-11-02 22:27:54 +01:00
|
|
|
placeholder="${state.translate('unlockInputPlaceholder')}"
|
2017-12-21 10:47:31 +01:00
|
|
|
type="password"
|
2017-11-02 22:27:54 +01:00
|
|
|
oninput=${inputChanged}/>
|
2017-08-31 18:43:36 +02:00
|
|
|
<input type="submit"
|
|
|
|
id="unlock-btn"
|
2017-11-02 22:27:54 +01:00
|
|
|
class="btn btn-hidden"
|
2017-08-31 18:43:36 +02:00
|
|
|
value="${state.translate('addPasswordButton')}"/>
|
|
|
|
</form>
|
|
|
|
</div>`;
|
|
|
|
|
2017-11-02 22:27:54 +01:00
|
|
|
function inputChanged() {
|
|
|
|
const input = document.getElementById('unlock-input');
|
|
|
|
const btn = document.getElementById('unlock-btn');
|
|
|
|
if (input.value.length > 0) {
|
|
|
|
btn.classList.remove('btn-hidden');
|
|
|
|
input.classList.remove('input-no-btn');
|
|
|
|
} else {
|
|
|
|
btn.classList.add('btn-hidden');
|
|
|
|
input.classList.add('input-no-btn');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:51:33 +02:00
|
|
|
function togglePasswordInput(e) {
|
2017-10-24 19:00:27 +02:00
|
|
|
const unlockInput = document.getElementById('unlock-input');
|
|
|
|
const boxChecked = e.target.checked;
|
2017-11-02 00:36:45 +01:00
|
|
|
document
|
|
|
|
.querySelector('.setPassword')
|
|
|
|
.classList.toggle('hidden', !boxChecked);
|
2017-10-24 19:00:27 +02:00
|
|
|
if (boxChecked) {
|
|
|
|
unlockInput.focus();
|
|
|
|
} else {
|
|
|
|
unlockInput.value = '';
|
2017-10-24 18:47:03 +02:00
|
|
|
}
|
2017-11-02 22:27:54 +01:00
|
|
|
inputChanged();
|
2017-08-31 18:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setPassword(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const password = document.getElementById('unlock-input').value;
|
|
|
|
if (password.length > 0) {
|
2017-10-23 15:51:33 +02:00
|
|
|
document.getElementById('copy').classList.remove('wait-password');
|
|
|
|
document.getElementById('copy-btn').disabled = false;
|
2018-01-24 19:23:13 +01:00
|
|
|
emit('password', { password, file });
|
2017-08-31 18:43:36 +02:00
|
|
|
}
|
2018-02-01 21:49:18 +01:00
|
|
|
return false;
|
2017-08-31 18:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return div;
|
|
|
|
};
|