2021-03-16 23:06:16 +08:00
|
|
|
import { Scope } from 'Common/Enums';
|
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';
|
|
|
|
|
|
|
|
class AskPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('Ask');
|
2021-11-08 00:06:08 +08:00
|
|
|
this.viewNoUserSelect = true;
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
askDesc: '',
|
|
|
|
yesButton: '',
|
|
|
|
noButton: ''
|
|
|
|
});
|
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
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.bFocusYesOnShow = true;
|
|
|
|
this.bDisabeCloseOnEsc = true;
|
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
yesClick() {
|
|
|
|
this.cancelCommand();
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2021-03-24 21:22:25 +08:00
|
|
|
isFunction(this.fYesAction) && this.fYesAction.call(null);
|
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() {
|
|
|
|
this.cancelCommand();
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2021-03-24 21:22:25 +08:00
|
|
|
isFunction(this.fNoAction) && this.fNoAction.call(null);
|
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
|
|
|
|
* @param {string=} sYesButton
|
|
|
|
* @param {string=} sNoButton
|
|
|
|
* @param {boolean=} bFocusYesOnShow = true
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
onShow(askDesc, fYesFunc = null, fNoFunc = null, yesButton = '', noButton = '', isFocusYesOnShow = true) {
|
|
|
|
this.askDesc(askDesc || '');
|
2021-11-03 21:58:34 +08:00
|
|
|
this.yesButton(yesButton || i18n('POPUPS_ASK/BUTTON_YES'));
|
|
|
|
this.noButton(noButton || i18n('POPUPS_ASK/BUTTON_NO'));
|
|
|
|
this.fYesAction = fYesFunc;
|
|
|
|
this.fNoAction = fNoFunc;
|
2016-08-17 06:01:20 +08:00
|
|
|
this.bFocusYesOnShow = !!isFocusYesOnShow;
|
|
|
|
}
|
|
|
|
|
|
|
|
onShowWithDelay() {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.bFocusYesOnShow) {
|
2020-08-22 07:03:03 +08:00
|
|
|
this.querySelector('.buttonYes').focus();
|
2014-12-28 03:48:55 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onBuild() {
|
2021-03-16 23:06:16 +08:00
|
|
|
// shortcuts.add('tab', 'shift', Scope.Ask, () => {
|
|
|
|
shortcuts.add('tab,arrowright,arrowleft', '', Scope.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;
|
|
|
|
});
|
|
|
|
|
2021-03-16 23:06:16 +08:00
|
|
|
shortcuts.add('escape', '', Scope.Ask, () => {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.noClick();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { AskPopupView, AskPopupView as default };
|