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