Improved ask password

This commit is contained in:
the-djmaze 2022-02-07 19:35:24 +01:00
parent d9f50fa829
commit 66a3a18f67
3 changed files with 27 additions and 22 deletions

View file

@ -11,50 +11,50 @@ class AskPopupView extends AbstractViewPopup {
this.addObservables({ this.addObservables({
askDesc: '', askDesc: '',
yesButton: '', yesButton: '',
noButton: '' noButton: '',
passphrase: '',
askPass: false
}); });
this.fYesAction = null; this.fYesAction = null;
this.fNoAction = null; this.fNoAction = null;
this.bFocusYesOnShow = true; this.focusOnShow = true;
this.bDisabeCloseOnEsc = true; this.bDisabeCloseOnEsc = true;
} }
yesClick() { yesClick() {
this.cancelCommand(); this.cancelCommand();
isFunction(this.fYesAction) && this.fYesAction.call(null); isFunction(this.fYesAction) && this.fYesAction();
} }
noClick() { noClick() {
this.cancelCommand(); this.cancelCommand();
isFunction(this.fNoAction) && this.fNoAction.call(null); isFunction(this.fNoAction) && this.fNoAction();
} }
/** /**
* @param {string} sAskDesc * @param {string} sAskDesc
* @param {Function=} fYesFunc * @param {Function=} fYesFunc
* @param {Function=} fNoFunc * @param {Function=} fNoFunc
* @param {string=} sYesButton * @param {boolean=} focusOnShow = true
* @param {string=} sNoButton
* @param {boolean=} bFocusYesOnShow = true
* @returns {void} * @returns {void}
*/ */
onShow(sAskDesc, fYesFunc = null, fNoFunc = null, yesButton = '', noButton = '', isFocusYesOnShow = true) { onShow(sAskDesc, fYesFunc = null, fNoFunc = null, focusOnShow = true, askPass = false) {
this.askDesc(sAskDesc || ''); this.askDesc(sAskDesc || '');
this.yesButton(yesButton || i18n('POPUPS_ASK/BUTTON_YES')); this.askPass(askPass);
this.noButton(noButton || i18n('POPUPS_ASK/BUTTON_NO')); this.passphrase('');
this.yesButton(i18n('POPUPS_ASK/BUTTON_YES'));
this.noButton(i18n(askPass ? 'GLOBAL/CANCEL' : 'POPUPS_ASK/BUTTON_NO'));
this.fYesAction = fYesFunc; this.fYesAction = fYesFunc;
this.fNoAction = fNoFunc; this.fNoAction = fNoFunc;
this.bFocusYesOnShow = !!isFocusYesOnShow; this.focusOnShow = focusOnShow ? (askPass ? 'input[type="password"]' : '.buttonYes') : '';
} }
onShowWithDelay() { onShowWithDelay() {
if (this.bFocusYesOnShow) { this.focusOnShow && this.querySelector(this.focusOnShow).focus();
this.querySelector('.buttonYes').focus();
}
} }
onBuild() { onBuild() {
@ -78,12 +78,11 @@ class AskPopupView extends AbstractViewPopup {
AskPopupView.password = function(sAskDesc) { AskPopupView.password = function(sAskDesc) {
return new Promise(resolve => { return new Promise(resolve => {
this.showModal([ this.showModal([
sAskDesc + `<p>${i18n('GLOBAL/PASSWORD')}: <input type="password" autofocus=""></p>`, sAskDesc,
() => resolve(this.__dom.querySelector('input[type="password"]').value), () => resolve(this.__vm.passphrase()),
() => resolve(null), () => resolve(null),
'', true,
i18n('GLOBAL/CANCEL'), true
false
]); ]);
}); });
} }

View file

@ -800,8 +800,6 @@ class ComposePopupView extends AbstractViewPopup {
this.initOnShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText); this.initOnShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText);
}, },
null, null,
null,
null,
false false
]); ]);
} else { } else {

View file

@ -1,4 +1,12 @@
<div class="modal-body" data-bind="html: askDesc"></div> <div class="modal-body">
<div data-bind="html: askDesc"></div>
<form class="form-horizontal" data-bind="visible: askPass, submit: yesClick" style="margin: 2em 0 0">
<div class="control-group">
<label data-i18n="GLOBAL/PASSWORD"></label>
<input type="password" data-bind="value: passphrase">
</div>
</form>
</div>
<footer> <footer>
<button class="btn buttonYes" data-bind="click: yesClick, text: yesButton" data-icon="✔"></button> <button class="btn buttonYes" data-bind="click: yesClick, text: yesButton" data-icon="✔"></button>
<button class="btn buttonNo" data-bind="click: noClick, text: noButton" data-icon="✖"></button> <button class="btn buttonNo" data-bind="click: noClick, text: noButton" data-icon="✖"></button>