Improve error handling and expose loadList in pagination components

- Added error handling with `Swal.showValidationMessage` across `add`, `set`, and `delete` operations in `ObjectsGlobal.vue`.
- Exposed `loadList` function to `buttons` slot in `TableLabeledPagination.vue` and `PaginationDisplayGeneralSearchReload.vue`.
This commit is contained in:
Jeppe Bundgaard
2026-01-08 13:17:31 +01:00
parent e338b3ced1
commit 17df279797
3 changed files with 25 additions and 7 deletions
@@ -21,7 +21,7 @@ import SessionUser from "@/components/session/token/SessionUser.vue";
/>
</div>
<div class="column is-narrow" v-if="$slots.buttons">
<slot name="buttons"></slot>
<slot name="buttons" :loadList="loadList"></slot>
</div>
<div class="column is-narrow">
<LoadButtonWhileAwait class="is-dark" :isLoading="isLoading" :loadFunction="loadList" icon="fas fa-sync-alt">{{SessionUser.objects.global.language.reload}}</LoadButtonWhileAwait>
@@ -33,8 +33,8 @@ const isSmall = ref(window.innerWidth < 1024);
<h2 class="title is-4 mb-4">{{ label }}</h2>
<!-- Search & reload -->
<PaginationDisplayGeneralSearchReload>
<template #buttons v-if="$slots.buttons">
<slot name="buttons"></slot>
<template #buttons="{ loadList }" v-if="$slots.buttons">
<slot name="buttons" :loadList="loadList"></slot>
</template>
</PaginationDisplayGeneralSearchReload>
<!-- Filters -->
@@ -471,10 +471,14 @@ export const ObjectsGlobal = {
}
}
// Call the add function with the arguments
object.add(...argument_array).then(() => {
return object.add(...argument_array).then(() => {
if (onAfterSubmit !== null) {
onAfterSubmit();
}
}).catch((error) => {
Swal.showValidationMessage(
`Fejl: ${error.message || error}`
);
});
}
});
@@ -650,10 +654,16 @@ export const ObjectsGlobal = {
preConfirm: () => {
try {
// Call the set function with the arguments
object.set[column](id, document.getElementById(column).value).then(() => {
return object.set[column](id, document.getElementById(column).value).then(() => {
if (onAfterSubmit !== null) {
onAfterSubmit();
}
}).catch((error) => {
console.error('Unable to edit object field', error);
// Show an error message
Swal.showValidationMessage(
`Fejl: ${error.message || error}`
);
});
} catch (error) {
console.error('Unable to edit object field', error);
@@ -751,10 +761,14 @@ export const ObjectsGlobal = {
cancelButtonText: ObjectsGlobal.language.cancel,
showLoaderOnConfirm: true,
preConfirm: () => {
object.delete(id).then(() => {
return object.delete(id).then(() => {
if (onAfterSubmit !== null) {
onAfterSubmit();
}
}).catch((error) => {
Swal.showValidationMessage(
`Fejl: ${error.message || error}`
);
});
}
});
@@ -769,10 +783,14 @@ export const ObjectsGlobal = {
cancelButtonText: ObjectsGlobal.language.cancel,
showLoaderOnConfirm: true,
preConfirm: () => {
object.delete.single(id).then(() => {
return object.delete.single(id).then(() => {
if (onAfterSubmit !== null) {
onAfterSubmit();
}
}).catch((error) => {
Swal.showValidationMessage(
`Fejl: ${error.message || error}`
);
});
}
})