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: '',
|
2022-08-04 20:58:13 +08:00
|
|
|
username: '',
|
|
|
|
askUsername: false,
|
2022-02-08 02:35:24 +08:00
|
|
|
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-08-04 20:58:13 +08:00
|
|
|
onShow(sAskDesc, fYesFunc = null, fNoFunc = null, focusOnShow = true, ask = 0, btnText = '') {
|
2022-02-08 00:30:41 +08:00
|
|
|
this.askDesc(sAskDesc || '');
|
2022-08-04 20:58:13 +08:00
|
|
|
this.askUsername(ask & 2);
|
|
|
|
this.askPass(ask & 1);
|
|
|
|
this.username('');
|
2022-02-08 02:35:24 +08:00
|
|
|
this.passphrase('');
|
2022-08-04 20:08:58 +08:00
|
|
|
this.yesButton(i18n(btnText || 'GLOBAL/YES'));
|
2022-08-04 20:58:13 +08:00
|
|
|
this.noButton(i18n(ask ? 'GLOBAL/CANCEL' : 'GLOBAL/NO'));
|
2021-11-03 21:58:34 +08:00
|
|
|
this.fYesAction = fYesFunc;
|
|
|
|
this.fNoAction = fNoFunc;
|
2022-08-04 20:58:13 +08:00
|
|
|
this.focusOnShow = focusOnShow
|
|
|
|
? (ask ? 'input[type="'+(ask&2?'text':'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', () => {
|
2022-08-04 21:27:26 +08:00
|
|
|
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;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
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-08-04 20:58:13 +08:00
|
|
|
1,
|
|
|
|
btnText
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
AskPopupView.credentials = function(sAskDesc, btnText) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.showModal([
|
|
|
|
sAskDesc,
|
|
|
|
() => resolve({username:this.__vm.username(), password:this.__vm.passphrase()}),
|
|
|
|
() => resolve(null),
|
2022-02-08 06:00:51 +08:00
|
|
|
true,
|
2022-08-04 20:58:13 +08:00
|
|
|
3,
|
2022-02-08 06:00:51 +08:00
|
|
|
btnText
|
2022-02-08 00:30:41 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|