2018-11-13 03:17:48 +08:00
|
|
|
const $dialog = $("#prompt-dialog");
|
|
|
|
const $question = $("#prompt-dialog-question");
|
|
|
|
const $answer = $("#prompt-dialog-answer");
|
|
|
|
const $form = $("#prompt-dialog-form");
|
|
|
|
|
|
|
|
let resolve;
|
2018-11-13 17:42:55 +08:00
|
|
|
let shownCb;
|
2018-11-13 03:17:48 +08:00
|
|
|
|
2018-11-13 17:42:55 +08:00
|
|
|
function ask({ message, defaultValue, shown }) {
|
2018-11-13 03:17:48 +08:00
|
|
|
glob.activeDialog = $dialog;
|
|
|
|
|
2018-11-13 17:42:55 +08:00
|
|
|
shownCb = shown;
|
|
|
|
|
2018-11-13 03:17:48 +08:00
|
|
|
$question.text(message);
|
2018-11-13 17:42:55 +08:00
|
|
|
$answer.val(defaultValue || "");
|
2018-11-13 03:17:48 +08:00
|
|
|
|
|
|
|
$dialog.modal();
|
|
|
|
|
2018-11-13 04:18:22 +08:00
|
|
|
return new Promise((res, rej) => { resolve = res; });
|
2018-11-13 03:17:48 +08:00
|
|
|
}
|
|
|
|
|
2018-11-13 17:42:55 +08:00
|
|
|
$dialog.on('shown.bs.modal', () => {
|
|
|
|
if (shownCb) {
|
|
|
|
shownCb({ $dialog, $question, $answer, $form });
|
|
|
|
}
|
|
|
|
|
|
|
|
$answer.focus().select();
|
|
|
|
});
|
2018-11-13 03:17:48 +08:00
|
|
|
|
|
|
|
$dialog.on("hidden.bs.modal", () => {
|
|
|
|
if (resolve) {
|
|
|
|
resolve(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$form.submit(() => {
|
|
|
|
resolve($answer.val());
|
|
|
|
|
|
|
|
$dialog.modal('hide');
|
|
|
|
});
|
|
|
|
|
|
|
|
export default {
|
|
|
|
ask
|
|
|
|
}
|