Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 51 additions & 55 deletions adminforth/spa/src/afcl/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,56 @@ interface DialogButton {
options?: Record<string, any>
}

const modalRef = ref();

const props = withDefaults(defineProps<DialogProps>(), {
header: '',
headerCloseButton: true,
buttons: () => [],
clickToCloseOutside: false,
closeByEsc: true,
closeByClickOutside: true,
beforeCloseFunction: null,
beforeOpenFunction: null,
closable: false,
askForCloseConfirmation: false,
closeConfirmationText: 'Are you sure you want to close this dialog?',
removeFromDomOnClose: false,
})

const buttons = computed<DialogButton[]>(() => {
if (props.buttons && props.buttons.length > 0) {
return props.buttons;
}
return [
{
label: 'Close',
onclick: (dialog: any) => {
tryToHideModal();
},
options: {}
}
];
});


function open() {
modalRef.value.open();
}

function close() {
modalRef.value.close();
}

defineExpose({
open: open,
close: close,
tryToHideModal: tryToHideModal,
})

function tryToHideModal() {
modalRef.value?.tryToHideModal();
}

interface DialogProps {
/**
Expand Down Expand Up @@ -114,7 +164,7 @@ interface DialogProps {
/**
* Function that will be called before the dialog is closed.
*/
beforeCloseFunction?: (() => void | Promise<void>) | null
beforeCloseFunction?: (() => void | Promise<void | boolean>) | null

/**
* Function that will be called before the dialog is opened.
Expand Down Expand Up @@ -167,58 +217,4 @@ const dialog: Ref<Dialog> = ref(
);
/*************************************************************/



const modalRef = ref();

const props = withDefaults(defineProps<DialogProps>(), {
header: '',
headerCloseButton: true,
buttons: () => [],
clickToCloseOutside: false,
closeByEsc: true,
closeByClickOutside: true,
beforeCloseFunction: null,
beforeOpenFunction: null,
closable: false,
askForCloseConfirmation: false,
closeConfirmationText: 'Are you sure you want to close this dialog?',
removeFromDomOnClose: false,
})

const buttons = computed<DialogButton[]>(() => {
if (props.buttons && props.buttons.length > 0) {
return props.buttons;
}
return [
{
label: 'Close',
onclick: (dialog: any) => {
tryToHideModal();
},
options: {}
}
];
});


function open() {
modalRef.value.open();
}

function close() {
modalRef.value.close();
}

defineExpose({
open: open,
close: close,
tryToHideModal: tryToHideModal,
})

function tryToHideModal() {
modalRef.value?.tryToHideModal();
}


</script>
7 changes: 5 additions & 2 deletions adminforth/spa/src/afcl/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const removeFromDom = computed(() => {
interface DialogProps {
closeByClickOutside?: boolean
closeByEsc?: boolean
beforeCloseFunction?: (() => void | Promise<void>) | null
beforeCloseFunction?: (() => void | Promise<void | boolean>) | null
beforeOpenFunction?: (() => void | Promise<void>) | null
askForCloseConfirmation?: boolean
closeConfirmationText?: string
Expand Down Expand Up @@ -101,7 +101,10 @@ async function open() {

async function close() {
if (props.beforeCloseFunction) {
await props.beforeCloseFunction?.();
const shouldClose = await props.beforeCloseFunction?.();
if (shouldClose === false) {
return;
}
}
isModalOpen.value = false;
}
Expand Down