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';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
|
2022-02-24 21:01:41 +08:00
|
|
|
export class AskPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('Ask');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
askDesc: '',
|
|
|
|
yesButton: '',
|
2022-02-08 02:35:24 +08:00
|
|
|
noButton: '',
|
|
|
|
passphrase: '',
|
|
|
|
askPass: false
|
2020-10-26 19:54:03 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.fYesAction = null;
|
|
|
|
this.fNoAction = null;
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2022-02-08 02:35:24 +08:00
|
|
|
this.focusOnShow = true;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
yesClick() {
|
2022-03-04 16:21:24 +08:00
|
|
|
this.close();
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2022-02-08 02:35:24 +08:00
|
|
|
isFunction(this.fYesAction) && this.fYesAction();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
noClick() {
|
2022-03-04 16:21:24 +08:00
|
|
|
this.close();
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2022-02-08 02:35:24 +08:00
|
|
|
isFunction(this.fNoAction) && this.fNoAction();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {string} sAskDesc
|
|
|
|
* @param {Function=} fYesFunc
|
|
|
|
* @param {Function=} fNoFunc
|
2022-02-08 02:35:24 +08:00
|
|
|
* @param {boolean=} focusOnShow = true
|
2016-08-17 06:01:20 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-02-08 06:00:51 +08:00
|
|
|
onShow(sAskDesc, fYesFunc = null, fNoFunc = null, focusOnShow = true, askPass = false, btnText = '') {
|
2022-02-08 00:30:41 +08:00
|
|
|
this.askDesc(sAskDesc || '');
|
2022-02-08 02:35:24 +08:00
|
|
|
this.askPass(askPass);
|
|
|
|
this.passphrase('');
|
2022-02-08 06:00:51 +08:00
|
|
|
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') : '';
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
2022-02-25 05:40:17 +08:00
|
|
|
afterShow() {
|
2022-02-08 02:35:24 +08:00
|
|
|
this.focusOnShow && this.querySelector(this.focusOnShow).focus();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
2022-02-25 05:40:17 +08:00
|
|
|
onClose() {
|
|
|
|
this.noClick();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onBuild() {
|
2022-02-24 18:19:19 +08:00
|
|
|
// shortcuts.add('tab', 'shift', 'Ask', () => {
|
|
|
|
shortcuts.add('tab,arrowright,arrowleft', '', 'Ask', () => {
|
2020-08-22 07:03:03 +08:00
|
|
|
let btn = this.querySelector('.buttonYes');
|
|
|
|
if (btn.matches(':focus')) {
|
|
|
|
btn = this.querySelector('.buttonNo');
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2020-08-22 07:03:03 +08:00
|
|
|
btn.focus();
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-02-08 06:00:51 +08:00
|
|
|
AskPopupView.password = function(sAskDesc, btnText) {
|
2022-02-08 00:30:41 +08:00
|
|
|
return new Promise(resolve => {
|
|
|
|
this.showModal([
|
2022-02-08 02:35:24 +08:00
|
|
|
sAskDesc,
|
|
|
|
() => resolve(this.__vm.passphrase()),
|
2022-02-08 00:30:41 +08:00
|
|
|
() => resolve(null),
|
2022-02-08 02:35:24 +08:00
|
|
|
true,
|
2022-02-08 06:00:51 +08:00
|
|
|
true,
|
|
|
|
btnText
|
2022-02-08 00:30:41 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|