mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-19 02:10:04 +08:00
chore(client/ts): port widgets/dialogs/confirm
This commit is contained in:
parent
e54e8fdef8
commit
1656acdb49
@ -27,7 +27,32 @@ const TPL = `
|
|||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
|
export type ConfirmDialogCallback = (val: false | {
|
||||||
|
confirmed: boolean;
|
||||||
|
isDeleteNoteChecked: boolean
|
||||||
|
}) => void;
|
||||||
|
|
||||||
|
interface ConfirmWithMessageOptions {
|
||||||
|
message: string | HTMLElement | JQuery<HTMLElement>;
|
||||||
|
callback: ConfirmDialogCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConfirmWithTitleOptions {
|
||||||
|
title: string;
|
||||||
|
callback: ConfirmDialogCallback;
|
||||||
|
}
|
||||||
|
|
||||||
export default class ConfirmDialog extends BasicWidget {
|
export default class ConfirmDialog extends BasicWidget {
|
||||||
|
|
||||||
|
private resolve: ConfirmDialogCallback | null;
|
||||||
|
|
||||||
|
private modal!: bootstrap.Modal;
|
||||||
|
private $originallyFocused!: JQuery<HTMLElement> | null;
|
||||||
|
private $confirmContent!: JQuery<HTMLElement>;
|
||||||
|
private $okButton!: JQuery<HTMLElement>;
|
||||||
|
private $cancelButton!: JQuery<HTMLElement>;
|
||||||
|
private $custom!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -37,6 +62,8 @@ export default class ConfirmDialog extends BasicWidget {
|
|||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
|
// TODO: Fix once we use proper ES imports.
|
||||||
|
//@ts-ignore
|
||||||
this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget);
|
this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget);
|
||||||
this.$confirmContent = this.$widget.find(".confirm-dialog-content");
|
this.$confirmContent = this.$widget.find(".confirm-dialog-content");
|
||||||
this.$okButton = this.$widget.find(".confirm-dialog-ok-button");
|
this.$okButton = this.$widget.find(".confirm-dialog-ok-button");
|
||||||
@ -60,7 +87,7 @@ export default class ConfirmDialog extends BasicWidget {
|
|||||||
this.$okButton.on('click', () => this.doResolve(true));
|
this.$okButton.on('click', () => this.doResolve(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
showConfirmDialogEvent({ message, callback }) {
|
showConfirmDialogEvent({ message, callback }: ConfirmWithMessageOptions) {
|
||||||
this.$originallyFocused = $(':focus');
|
this.$originallyFocused = $(':focus');
|
||||||
|
|
||||||
this.$custom.hide();
|
this.$custom.hide();
|
||||||
@ -77,8 +104,8 @@ export default class ConfirmDialog extends BasicWidget {
|
|||||||
|
|
||||||
this.resolve = callback;
|
this.resolve = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
showConfirmDeleteNoteBoxWithNoteDialogEvent({ title, callback }) {
|
showConfirmDeleteNoteBoxWithNoteDialogEvent({ title, callback }: ConfirmWithTitleOptions) {
|
||||||
glob.activeDialog = this.$widget;
|
glob.activeDialog = this.$widget;
|
||||||
|
|
||||||
this.$confirmContent.text(`${t('confirm.are_you_sure_remove_note', { title: title })}`);
|
this.$confirmContent.text(`${t('confirm.are_you_sure_remove_note', { title: title })}`);
|
||||||
@ -107,11 +134,13 @@ export default class ConfirmDialog extends BasicWidget {
|
|||||||
this.resolve = callback;
|
this.resolve = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
doResolve(ret) {
|
doResolve(ret: boolean) {
|
||||||
this.resolve({
|
if (this.resolve) {
|
||||||
confirmed: ret,
|
this.resolve({
|
||||||
isDeleteNoteChecked: this.$widget.find(`.${DELETE_NOTE_BUTTON_CLASS}:checked`).length > 0
|
confirmed: ret,
|
||||||
});
|
isDeleteNoteChecked: this.$widget.find(`.${DELETE_NOTE_BUTTON_CLASS}:checked`).length > 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.resolve = null;
|
this.resolve = null;
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user