snappymail/dev/View/Popup/Ask.js

112 lines
2.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { KeyState } from 'Common/Enums';
import { i18n } from 'Common/Translator';
2019-07-05 03:19:24 +08:00
import { popup } from 'Knoin/Knoin';
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
2016-09-10 06:38:16 +08:00
@popup({
name: 'View/Popup/Ask',
templateID: 'PopupsAsk'
})
2019-07-05 03:19:24 +08:00
class AskPopupView extends AbstractViewNext {
constructor() {
super();
2014-08-25 15:10:51 +08:00
this.askDesc = ko.observable('');
this.yesButton = ko.observable('');
this.noButton = ko.observable('');
2014-08-21 23:08:34 +08:00
this.yesFocus = ko.observable(false);
this.noFocus = ko.observable(false);
this.fYesAction = null;
this.fNoAction = null;
this.bFocusYesOnShow = true;
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.PopupAsk;
}
clearPopup() {
this.askDesc('');
this.yesButton(i18n('POPUPS_ASK/BUTTON_YES'));
this.noButton(i18n('POPUPS_ASK/BUTTON_NO'));
this.yesFocus(false);
this.noFocus(false);
this.fYesAction = null;
this.fNoAction = null;
}
yesClick() {
this.cancelCommand();
if (typeof this.fYesAction === 'function') {
this.fYesAction.call(null);
}
2016-06-30 08:02:45 +08:00
}
noClick() {
this.cancelCommand();
if (typeof this.fNoAction === 'function') {
this.fNoAction.call(null);
}
2016-06-30 08:02:45 +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.clearPopup();
this.fYesAction = fYesFunc || null;
this.fNoAction = fNoFunc || null;
this.askDesc(askDesc || '');
2019-07-05 03:19:24 +08:00
if (yesButton) {
this.yesButton(yesButton);
}
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
if (noButton) {
this.noButton(noButton);
}
this.bFocusYesOnShow = !!isFocusYesOnShow;
}
onShowWithDelay() {
2019-07-05 03:19:24 +08:00
if (this.bFocusYesOnShow) {
2014-12-28 03:48:55 +08:00
this.yesFocus(true);
}
}
onBuild() {
key('tab, shift+tab, right, left', KeyState.PopupAsk, () => {
2019-07-05 03:19:24 +08:00
if (this.yesFocus()) {
this.noFocus(true);
2019-07-05 03:19:24 +08:00
} else {
this.yesFocus(true);
}
return false;
});
key('esc', KeyState.PopupAsk, () => {
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 };