")
- .addClass("form-group")
- .append($question)
- .append($answer));
-
- utils.openDialog($dialog, false);
-
- return new Promise((res, rej) => { resolve = res; });
-}
-
-$dialog.on('shown.bs.modal', () => {
- if (shownCb) {
- shownCb({ $dialog, $question, $answer, $form });
- }
-
- $answer.trigger('focus').select();
-});
-
-$dialog.on("hidden.bs.modal", () => {
- if (resolve) {
- resolve(null);
- }
-});
-
-$form.on('submit', e => {
- e.preventDefault();
- resolve($answer.val());
-
- $dialog.modal('hide');
-});
diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js
index 71d1378f5..a33f7dd3f 100644
--- a/src/public/app/layouts/desktop_layout.js
+++ b/src/public/app/layouts/desktop_layout.js
@@ -73,6 +73,7 @@ import NoteRevisionsDialog from "../widgets/dialogs/note_revisions.js";
import DeleteNotesDialog from "../widgets/dialogs/delete_notes.js";
import InfoDialog from "../widgets/dialogs/info.js";
import ConfirmDialog from "../widgets/dialogs/confirm.js";
+import PromptDialog from "../widgets/dialogs/prompt.js";
export default class DesktopLayout {
constructor(customWidgets) {
@@ -220,6 +221,7 @@ export default class DesktopLayout {
.child(new NoteRevisionsDialog())
.child(new DeleteNotesDialog())
.child(new InfoDialog())
- .child(new ConfirmDialog());
+ .child(new ConfirmDialog())
+ .child(new PromptDialog());
}
}
diff --git a/src/public/app/widgets/dialog.js b/src/public/app/widgets/dialog.js
index b73b20c8c..ef259e748 100644
--- a/src/public/app/widgets/dialog.js
+++ b/src/public/app/widgets/dialog.js
@@ -10,7 +10,13 @@ async function confirm(message) {
appContext.triggerCommand("showConfirmDialog", {message, callback: res}));
}
+async function prompt(props) {
+ return new Promise(res =>
+ appContext.triggerCommand("showPromptDialog", {...props, callback: res}));
+}
+
export default {
info,
- confirm
+ confirm,
+ prompt
};
diff --git a/src/public/app/widgets/dialogs/prompt.js b/src/public/app/widgets/dialogs/prompt.js
new file mode 100644
index 000000000..65f538b03
--- /dev/null
+++ b/src/public/app/widgets/dialogs/prompt.js
@@ -0,0 +1,92 @@
+import utils from "../../services/utils.js";
+import BasicWidget from "../basic_widget.js";
+
+const TPL = `
+
`;
+
+export default class PromptDialog extends BasicWidget {
+ constructor() {
+ super();
+
+ this.resolve = null;
+ this.shownCb = null;
+ }
+
+ doRender() {
+ this.$widget = $(TPL);
+ this.$dialogBody = this.$widget.find(".modal-body");
+ this.$form = this.$widget.find("#prompt-dialog-form");
+ this.$question = null;
+ this.$answer = null;
+
+ this.$widget.on('shown.bs.modal', () => {
+ if (this.shownCb) {
+ this.shownCb({
+ $dialog: this.$widget,
+ $question: this.$question,
+ $answer: this.$answer,
+ $form: this.$form
+ });
+ }
+
+ this.$answer.trigger('focus').select();
+ });
+
+ this.$widget.on("hidden.bs.modal", () => {
+ if (this.resolve) {
+ this.resolve(null);
+ }
+ });
+
+ this.$form.on('submit', e => {
+ e.preventDefault();
+ this.resolve(this.$answer.val());
+
+ this.$widget.modal('hide');
+ });
+ }
+
+ showPromptDialogEvent({ title, message, defaultValue, shown, callback }) {
+ this.shownCb = shown;
+ this.resolve = callback;
+
+ this.$widget.find(".prompt-title").text(title || "Prompt");
+
+ this.$question = $("