Skip to content

Commit be43d92

Browse files
authored
Merge pull request #625 from devforth/feature/AdminForth/1629/search-bulk-ai-pluggin-problem
fix: fix close dialog logic
2 parents feaf273 + 50b3a06 commit be43d92

2 files changed

Lines changed: 56 additions & 57 deletions

File tree

adminforth/spa/src/afcl/Dialog.vue

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,56 @@ interface DialogButton {
7777
options?: Record<string, any>
7878
}
7979
80+
const modalRef = ref();
81+
82+
const props = withDefaults(defineProps<DialogProps>(), {
83+
header: '',
84+
headerCloseButton: true,
85+
buttons: () => [],
86+
clickToCloseOutside: false,
87+
closeByEsc: true,
88+
closeByClickOutside: true,
89+
beforeCloseFunction: null,
90+
beforeOpenFunction: null,
91+
closable: false,
92+
askForCloseConfirmation: false,
93+
closeConfirmationText: 'Are you sure you want to close this dialog?',
94+
removeFromDomOnClose: false,
95+
})
96+
97+
const buttons = computed<DialogButton[]>(() => {
98+
if (props.buttons && props.buttons.length > 0) {
99+
return props.buttons;
100+
}
101+
return [
102+
{
103+
label: 'Close',
104+
onclick: (dialog: any) => {
105+
tryToHideModal();
106+
},
107+
options: {}
108+
}
109+
];
110+
});
111+
112+
113+
function open() {
114+
modalRef.value.open();
115+
}
116+
117+
function close() {
118+
modalRef.value.close();
119+
}
120+
121+
defineExpose({
122+
open: open,
123+
close: close,
124+
tryToHideModal: tryToHideModal,
125+
})
126+
127+
function tryToHideModal() {
128+
modalRef.value?.tryToHideModal();
129+
}
80130
81131
interface DialogProps {
82132
/**
@@ -114,7 +164,7 @@ interface DialogProps {
114164
/**
115165
* Function that will be called before the dialog is closed.
116166
*/
117-
beforeCloseFunction?: (() => void | Promise<void>) | null
167+
beforeCloseFunction?: (() => void | Promise<void | boolean>) | null
118168
119169
/**
120170
* Function that will be called before the dialog is opened.
@@ -167,58 +217,4 @@ const dialog: Ref<Dialog> = ref(
167217
);
168218
/*************************************************************/
169219
170-
171-
172-
const modalRef = ref();
173-
174-
const props = withDefaults(defineProps<DialogProps>(), {
175-
header: '',
176-
headerCloseButton: true,
177-
buttons: () => [],
178-
clickToCloseOutside: false,
179-
closeByEsc: true,
180-
closeByClickOutside: true,
181-
beforeCloseFunction: null,
182-
beforeOpenFunction: null,
183-
closable: false,
184-
askForCloseConfirmation: false,
185-
closeConfirmationText: 'Are you sure you want to close this dialog?',
186-
removeFromDomOnClose: false,
187-
})
188-
189-
const buttons = computed<DialogButton[]>(() => {
190-
if (props.buttons && props.buttons.length > 0) {
191-
return props.buttons;
192-
}
193-
return [
194-
{
195-
label: 'Close',
196-
onclick: (dialog: any) => {
197-
tryToHideModal();
198-
},
199-
options: {}
200-
}
201-
];
202-
});
203-
204-
205-
function open() {
206-
modalRef.value.open();
207-
}
208-
209-
function close() {
210-
modalRef.value.close();
211-
}
212-
213-
defineExpose({
214-
open: open,
215-
close: close,
216-
tryToHideModal: tryToHideModal,
217-
})
218-
219-
function tryToHideModal() {
220-
modalRef.value?.tryToHideModal();
221-
}
222-
223-
224220
</script>

adminforth/spa/src/afcl/Modal.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const removeFromDom = computed(() => {
6868
interface DialogProps {
6969
closeByClickOutside?: boolean
7070
closeByEsc?: boolean
71-
beforeCloseFunction?: (() => void | Promise<void>) | null
71+
beforeCloseFunction?: (() => void | Promise<void | boolean>) | null
7272
beforeOpenFunction?: (() => void | Promise<void>) | null
7373
askForCloseConfirmation?: boolean
7474
closeConfirmationText?: string
@@ -101,7 +101,10 @@ async function open() {
101101
102102
async function close() {
103103
if (props.beforeCloseFunction) {
104-
await props.beforeCloseFunction?.();
104+
const shouldClose = await props.beforeCloseFunction?.();
105+
if (shouldClose === false) {
106+
return;
107+
}
105108
}
106109
isModalOpen.value = false;
107110
}

0 commit comments

Comments
 (0)