From aa6f22e1b3b89effc3fd1c2881731b8b62b76353 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sat, 24 Jan 2026 21:40:26 +0100 Subject: [PATCH] feat: add confirm_modal_dynamic macro for dynamic confirmation messages Added a new macro that accepts an Alpine.js expression for the message, allowing runtime data to be included in confirmation dialogs. Updated admin-user-edit.html to use this macro for platform removal confirmation. Co-Authored-By: Claude Opus 4.5 --- app/templates/admin/admin-user-edit.html | 76 +++----------- app/templates/shared/macros/modals.html | 121 +++++++++++++++++++++++ 2 files changed, 132 insertions(+), 65 deletions(-) diff --git a/app/templates/admin/admin-user-edit.html b/app/templates/admin/admin-user-edit.html index 706e76e4..abe9f790 100644 --- a/app/templates/admin/admin-user-edit.html +++ b/app/templates/admin/admin-user-edit.html @@ -2,6 +2,7 @@ {% extends "admin/base.html" %} {% from 'shared/macros/alerts.html' import loading_state %} {% from 'shared/macros/headers.html' import edit_page_header %} +{% from 'shared/macros/modals.html' import confirm_modal_dynamic %} {% block title %}Edit Admin User{% endblock %} @@ -254,71 +255,16 @@ - +{{ confirm_modal_dynamic( + 'removePlatformModal', + 'Remove Platform', + "'Are you sure you want to remove \"' + (platformToRemove?.name || '') + '\" from this admin?'", + 'confirmRemovePlatform()', + 'showRemovePlatformModal', + 'Remove', + 'Cancel', + 'warning' +) }} {% endblock %} {% block extra_scripts %} diff --git a/app/templates/shared/macros/modals.html b/app/templates/shared/macros/modals.html index c8c40f49..dc697308 100644 --- a/app/templates/shared/macros/modals.html +++ b/app/templates/shared/macros/modals.html @@ -300,6 +300,127 @@ {% endmacro %} +{# + Confirm Modal Dynamic + ===================== + A confirmation dialog with dynamic message via Alpine.js variable. + Use this when the confirmation message needs to include runtime data. + + Parameters: + - id: Unique modal ID + - title: Modal title (static string) + - message_var: Alpine.js variable containing the message (e.g., 'confirmMessage') + - confirm_action: Alpine.js action to execute on confirm + - show_var: Alpine.js variable controlling visibility + - confirm_text: Confirm button text (default: 'Confirm') + - cancel_text: Cancel button text (default: 'Cancel') + - variant: 'danger' | 'warning' | 'info' (default: 'danger') + - icon: Icon name (optional, auto-selected based on variant) + + Example usage: + State: { showConfirm: false, itemToDelete: null } + Message var: `'Are you sure you want to delete "' + itemToDelete?.name + '"?'` + + {{ confirm_modal_dynamic( + 'deleteConfirm', + 'Delete Item', + "'Are you sure you want to delete \"' + itemToDelete?.name + '\"?'", + 'deleteItem()', + 'showConfirm' + ) }} +#} +{% macro confirm_modal_dynamic(id, title, message_var, confirm_action, show_var='isConfirmModalOpen', confirm_text='Confirm', cancel_text='Cancel', variant='danger', icon=none) %} +{% set variants = { + 'danger': { + 'icon_bg': 'bg-red-100 dark:bg-red-900/30', + 'icon_color': 'text-red-600 dark:text-red-400', + 'btn_class': 'bg-red-600 hover:bg-red-700 focus:ring-red-500' + }, + 'warning': { + 'icon_bg': 'bg-yellow-100 dark:bg-yellow-900/30', + 'icon_color': 'text-yellow-600 dark:text-yellow-400', + 'btn_class': 'bg-yellow-600 hover:bg-yellow-700 focus:ring-yellow-500' + }, + 'info': { + 'icon_bg': 'bg-blue-100 dark:bg-blue-900/30', + 'icon_color': 'text-blue-600 dark:text-blue-400', + 'btn_class': 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500' + } +} %} +{% set icons = { + 'danger': 'exclamation-triangle', + 'warning': 'exclamation', + 'info': 'information-circle' +} %} +{% set modal_icon = icon if icon else icons[variant] %} +{% set style = variants[variant] %} + + +{% endmacro %} + + {# Form Modal ==========