snappymail/dev/View/Popup/Ask.js

88 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { i18n } from 'Common/Translator';
2021-03-24 21:22:25 +08:00
import { isFunction } from 'Common/Utils';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
2022-02-24 21:01:41 +08:00
export class AskPopupView extends AbstractViewPopup {
constructor() {
super('Ask');
2014-08-25 15:10:51 +08:00
this.addObservables({
askDesc: '',
yesButton: '',
2022-02-08 02:35:24 +08:00
noButton: '',
passphrase: '',
askPass: false
});
2014-08-21 23:08:34 +08:00
this.fYesAction = null;
this.fNoAction = null;
2022-02-08 02:35:24 +08:00
this.focusOnShow = true;
}
yesClick() {
this.close();
2022-02-08 02:35:24 +08:00
isFunction(this.fYesAction) && this.fYesAction();
2016-06-30 08:02:45 +08:00
}
noClick() {
this.close();
2022-02-08 02:35:24 +08:00
isFunction(this.fNoAction) && this.fNoAction();
2016-06-30 08:02:45 +08:00
}
/**
* @param {string} sAskDesc
* @param {Function=} fYesFunc
* @param {Function=} fNoFunc
2022-02-08 02:35:24 +08:00
* @param {boolean=} focusOnShow = true
* @returns {void}
*/
onShow(sAskDesc, fYesFunc = null, fNoFunc = null, focusOnShow = true, askPass = false, btnText = '') {
this.askDesc(sAskDesc || '');
2022-02-08 02:35:24 +08:00
this.askPass(askPass);
this.passphrase('');
this.yesButton(i18n(btnText || 'POPUPS_ASK/BUTTON_YES'));
2022-02-08 02:35:24 +08:00
this.noButton(i18n(askPass ? 'GLOBAL/CANCEL' : 'POPUPS_ASK/BUTTON_NO'));
2021-11-03 21:58:34 +08:00
this.fYesAction = fYesFunc;
this.fNoAction = fNoFunc;
2022-02-08 02:35:24 +08:00
this.focusOnShow = focusOnShow ? (askPass ? 'input[type="password"]' : '.buttonYes') : '';
}
afterShow() {
2022-02-08 02:35:24 +08:00
this.focusOnShow && this.querySelector(this.focusOnShow).focus();
}
onClose() {
this.noClick();
return false;
}
onBuild() {
// shortcuts.add('tab', 'shift', 'Ask', () => {
shortcuts.add('tab,arrowright,arrowleft', '', 'Ask', () => {
let btn = this.querySelector('.buttonYes');
if (btn.matches(':focus')) {
btn = this.querySelector('.buttonNo');
}
btn.focus();
return false;
});
}
}
2016-06-30 08:02:45 +08:00
AskPopupView.password = function(sAskDesc, btnText) {
return new Promise(resolve => {
this.showModal([
2022-02-08 02:35:24 +08:00
sAskDesc,
() => resolve(this.__vm.passphrase()),
() => resolve(null),
2022-02-08 02:35:24 +08:00
true,
true,
btnText
]);
});
}