diff --git a/src/components/displays/buttons/ActionSettingsWheelButton.vue b/src/components/displays/buttons/ActionSettingsWheelButton.vue index be39586b..7dbeeb0b 100644 --- a/src/components/displays/buttons/ActionSettingsWheelButton.vue +++ b/src/components/displays/buttons/ActionSettingsWheelButton.vue @@ -7,6 +7,7 @@ import Swal from "sweetalert2"; import { ref } from "vue"; import CustomerModal from "@/components/displays/modals/CustomerModal.vue"; import ActionSettingsWheelItemLabel from "@/components/displays/buttons/ActionSettingsWheelItemLabel.vue"; +import ShowErrorField from "@/components/global/ShowErrorField.vue"; const emit = defineEmits(['deleted']); const emitDeleted = () => { emit('deleted'); @@ -61,6 +62,10 @@ const props = defineProps({ attachments: { type: Array, default: () => [] + }, + displayActionsDirectly: { + type: Boolean, + default: false } }); @@ -155,6 +160,7 @@ const hasUser = () => { } const attachmentsFromOrder = ref([]); +const attachmentsFromOrderError = ref(null); onMounted(() => { if (props.order_id) { SessionUser.objects.orders.functions.fetchAttachments(props.order_id).then((response) => { @@ -181,220 +187,495 @@ onMounted(() => { response = []; } attachmentsFromOrder.value = response; - }).catch((error) => {}); + }).catch((error) => { + const parsedErrorMessage = SessionUser.functions.parseErrorMessage(error); + console.warn('Error fetching attachments from order:', error, parsedErrorMessage); + // Check if there's an error message in the response + attachmentsFromOrderError.value = `ERROR: ${parsedErrorMessage || 'Failed to fetch attachments'}`; + }); } }); + +const defaultActions = computed(() => { + return [ + /** + * Example action + { + icon: 'fas fa-eye', + label: 'View Order', + clickAction: () => { + console.warn('View Order clicked'); + }, + showFunction: () => { + return true; // Logic to determine if action should be shown + }, + disabled: false, + template: 'success' // Optional: Set the template to 'success' or 'danger' + isLabel: false // Optional: Set to true to render the label as a button + } + */ + /** Bookings actions */ + { + label: 'Booking', + isLabel: true, + showFunction: () => { + return !!props.order_booking_id; + } + }, + { + icon: 'fas fa-check-circle', + label: 'Marker som gennemført', + template: 'success', + clickAction: () => { + return SessionUser.objects.order_bookings.functions.showCompleteConfirmationModal(props.order_booking_id, () => { + props.refreshFunction(); + }); + }, + showFunction: () => { + return !!props.order_booking_id && SessionUser.canAccessAdmin() && !props.order_id; + }, + disabled: false, + }, + { + icon: 'fas fa-external-link-alt', + label: 'Se booking i ny fane', + clickAction: () => { + return SessionUser.functions.redirectTo.department(props.department_id, 'modules/bookings/order/' + props.order_booking_id, true); + }, + showFunction: () => { + return !!props.order_booking_id; + }, + }, + { + icon: 'fas fa-edit', + label: 'Ændr tilknytning', + clickAction: () => { + return SessionUser.objects.order_bookings.showEditObjectFieldForm(props.order_booking_id, 'order_id', props.order_id, () => { + props.refreshFunction(); + }, { + filters: { + ...(props.customer_number ? {customer_id: props.customer_number} : {}), + ...(props.department_id ? {department_id: props.department_id} : {}) + }, + pagination: { + page: 1, + limit: 100 + } + }); + }, + showFunction: () => { + return !!props.order_booking_id && SessionUser.canAccessAdmin(); + }, + disabled: false, + }, + { + icon: 'fas fa-trash-alt', + label: 'Slet booking', + clickAction: () => { + return SessionUser.objects.order_bookings.functions.showDeleteConfirmationModal(props.order_booking_id, () => { + props.refreshFunction(); + }); + }, + showFunction: () => { + return !!props.order_booking_id && SessionUser.canAccessAdmin() && !props.order_id; + }, + disabled: false, + template: 'danger' + }, + /** Orders actions */ + { + label: SessionUser.functions.ucFirst(SessionUser.objects.orders.meta.labels.single), + isLabel: true, + showFunction: () => { + return !!props.order_id; + } + }, + { + icon: 'fas fa-external-link-alt', + label: 'Se ordre i ny fane', + clickAction: async () => { + return redirectDepartmentOrderPage(props.order_id, true); + }, + showFunction: () => { + return !!props.order_id && (SessionUser.canAccessAdmin() || SessionUser.canAccessSuperUser()); + }, + }, + { + icon: 'fas fa-user-edit', + label: 'Skift kunde', + clickAction: () => { + return SessionUser.objects.orders.functions.showChangeCustomerForm(props.order_id); + }, + showFunction: () => { + return !!props.order_id && SessionUser.canAccessSuperUser(); + }, + disabled: false, + }, + { + icon: 'fas fa-file-invoice-dollar', + label: 'Skift faktura samling', + clickAction: () => { + return SessionUser.objects.orders.functions.showChangeInvoiceCollectionForm(props.order_id); + }, + showFunction: () => { + return !!props.order_id && SessionUser.canAccessSuperUser(); + }, + disabled: false, + }, + { + icon: 'fas fa-trash-alt', + label: 'Slet ordre', + clickAction: () => { + return SessionUser.objects.orders.functions.showDeleteConfirmationModal(props.order_id, () => { + emitDeleted(); + }); + }, + showFunction: () => { + return !!props.order_id && (SessionUser.canAccessAdmin() || SessionUser.canAccessSuperUser()); + }, + disabled: false, + template: 'danger' + }, + { + icon: 'fas fa-file-invoice-dollar', + label: 'Vis faktura samling i ny fane', + clickAction: () => { + return redirectSuperUserInvoiceCollectionPage(props.invoice_collection_id); + }, + showFunction: () => { + return !!props.invoice_collection_id && SessionUser.canAccessSuperUser(); + }, + }, + /** Vehicle actions */ + { + label: props.reg_1 && props.reg_2 ? `${SessionUser.objects.vehicles.meta.labels.multiple}` : `${SessionUser.objects.vehicles.meta.labels.single}`, + isLabel: true, + }, + { + icon: 'fas fa-car', + label: `Se køretøj i ny fane`, + clickAction: () => { + return SessionUser.functions.redirectTo.superUser('/vehicles/' + props.reg_1, true); + }, + showFunction: () => { + return !!props.reg_1 && SessionUser.canAccessSuperUser(); + }, + }, + { + icon: 'fas fa-car', + label: `Se køretøj i ny fane`, + clickAction: () => { + return SessionUser.functions.redirectTo.superUser('/vehicles/' + props.reg_2, true); + }, + showFunction: () => { + return !!props.reg_2 && SessionUser.canAccessSuperUser(); + }, + }, + /** User actions */ + { label: SessionUser.objects.global.language.customer, + isLabel: true, + showFunction: () => { + return hasUser() && SessionUser.canAccessSuperUser(); + } + }, + { + icon: 'fas fa-user-edit', + label: 'Se kunde i ny fane', + clickAction: () => { + return SessionUser.functions.redirectTo.superUser('/users/' + userIdFromCustomerNumber.value, true); + }, + showFunction: () => { + return hasUser() && SessionUser.canAccessSuperUser() && userIdFromCustomerNumber.value; + }, + }, + { + icon: 'fas fa-user-shield', + label: 'Log ind som kunde', + clickAction: () => { + return SessionUser.superUser.intimidate.intimidateUser(userIdFromCustomerNumber.value); + }, + showFunction: () => { + return hasUser() && SessionUser.canAccessSuperUser(); + }, + }, + { + icon: 'fas fa-key', + label: 'Skift kodeord', + clickAction: () => { + return showSetCustomerPassword(userIdFromCustomerNumber.value); + }, + showFunction: () => { + return hasUser() && SessionUser.canAccessSuperUser(); + }, + }, + { + icon: 'fas fa-user', + label: 'Vis kunde', + clickAction: () => { + customerModalVisible.value = true; + }, + showFunction: () => { + return hasUser() && SessionUser.canAccessSuperUser(); + }, + }, + ]; +});