mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 04:04:50 +08:00
109 lines
2.3 KiB
JavaScript
109 lines
2.3 KiB
JavaScript
import { i18n } from 'Common/Translator';
|
|
import { isFunction } from 'Common/Utils';
|
|
import { addObservablesTo } from 'External/ko';
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
export class AskPopupView extends AbstractViewPopup {
|
|
constructor() {
|
|
super('Ask');
|
|
|
|
addObservablesTo(this, {
|
|
askDesc: '',
|
|
yesButton: '',
|
|
noButton: '',
|
|
username: '',
|
|
askUsername: false,
|
|
passphrase: '',
|
|
askPass: false
|
|
});
|
|
|
|
this.fYesAction = null;
|
|
this.fNoAction = null;
|
|
|
|
this.focusOnShow = true;
|
|
}
|
|
|
|
yesClick() {
|
|
this.close();
|
|
|
|
isFunction(this.fYesAction) && this.fYesAction(this);
|
|
}
|
|
|
|
noClick() {
|
|
this.close();
|
|
|
|
isFunction(this.fNoAction) && this.fNoAction(this);
|
|
}
|
|
|
|
/**
|
|
* @param {string} sAskDesc
|
|
* @param {Function=} fYesFunc
|
|
* @param {Function=} fNoFunc
|
|
* @param {boolean=} focusOnShow = true
|
|
* @returns {void}
|
|
*/
|
|
onShow(sAskDesc, fYesFunc = null, fNoFunc = null, focusOnShow = true, ask = 0, btnText = '') {
|
|
this.askDesc(sAskDesc || '');
|
|
this.askUsername(ask & 2);
|
|
this.askPass(ask & 1);
|
|
this.username('');
|
|
this.passphrase('');
|
|
this.yesButton(i18n(btnText || 'GLOBAL/YES'));
|
|
this.noButton(i18n(ask ? 'GLOBAL/CANCEL' : 'GLOBAL/NO'));
|
|
this.fYesAction = fYesFunc;
|
|
this.fNoAction = fNoFunc;
|
|
this.focusOnShow = focusOnShow
|
|
? (ask ? 'input[type="'+(ask&2?'text':'password')+'"]' : '.buttonYes')
|
|
: '';
|
|
}
|
|
|
|
afterShow() {
|
|
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 yes = this.querySelector('.buttonYes'),
|
|
no = this.querySelector('.buttonNo');
|
|
if (yes.matches(':focus')) {
|
|
no.focus();
|
|
return false;
|
|
} else if (no.matches(':focus')) {
|
|
yes.focus();
|
|
return false;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
AskPopupView.password = function(sAskDesc, btnText) {
|
|
return new Promise(resolve => {
|
|
this.showModal([
|
|
sAskDesc,
|
|
view => resolve(view.passphrase()),
|
|
() => resolve(null),
|
|
true,
|
|
1,
|
|
btnText
|
|
]);
|
|
});
|
|
}
|
|
|
|
AskPopupView.credentials = function(sAskDesc, btnText) {
|
|
return new Promise(resolve => {
|
|
this.showModal([
|
|
sAskDesc,
|
|
view => resolve({username:view.username(), password:view.passphrase()}),
|
|
() => resolve(null),
|
|
true,
|
|
3,
|
|
btnText
|
|
]);
|
|
});
|
|
}
|