From 000d62ec89c9e9c94ccacf9440058b99a3e489b1 Mon Sep 17 00:00:00 2001 From: Maximilian Vogel Date: Fri, 30 Aug 2024 15:26:45 +0200 Subject: [PATCH 01/17] Add djangocms_frontend.contrib.modal --- djangocms_frontend/contrib/modal/__init__.py | 0 .../contrib/modal/cms_plugins.py | 122 +++++++++++++ djangocms_frontend/contrib/modal/constants.py | 27 +++ djangocms_frontend/contrib/modal/forms.py | 172 ++++++++++++++++++ .../contrib/modal/frameworks/__init__.py | 0 .../contrib/modal/frameworks/bootstrap5.py | 20 ++ djangocms_frontend/contrib/modal/models.py | 65 +++++++ .../djangocms_frontend/admin/modal.html | 9 + .../bootstrap5/modal-container.html | 16 ++ .../bootstrap5/modal-inner.html | 11 ++ .../bootstrap5/modal-trigger.html | 12 ++ .../djangocms_frontend/bootstrap5/modal.html | 12 ++ 12 files changed, 466 insertions(+) create mode 100644 djangocms_frontend/contrib/modal/__init__.py create mode 100644 djangocms_frontend/contrib/modal/cms_plugins.py create mode 100644 djangocms_frontend/contrib/modal/constants.py create mode 100644 djangocms_frontend/contrib/modal/forms.py create mode 100644 djangocms_frontend/contrib/modal/frameworks/__init__.py create mode 100644 djangocms_frontend/contrib/modal/frameworks/bootstrap5.py create mode 100644 djangocms_frontend/contrib/modal/models.py create mode 100644 djangocms_frontend/contrib/modal/templates/djangocms_frontend/admin/modal.html create mode 100644 djangocms_frontend/contrib/modal/templates/djangocms_frontend/bootstrap5/modal-container.html create mode 100644 djangocms_frontend/contrib/modal/templates/djangocms_frontend/bootstrap5/modal-inner.html create mode 100644 djangocms_frontend/contrib/modal/templates/djangocms_frontend/bootstrap5/modal-trigger.html create mode 100644 djangocms_frontend/contrib/modal/templates/djangocms_frontend/bootstrap5/modal.html diff --git a/djangocms_frontend/contrib/modal/__init__.py b/djangocms_frontend/contrib/modal/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/djangocms_frontend/contrib/modal/cms_plugins.py b/djangocms_frontend/contrib/modal/cms_plugins.py new file mode 100644 index 00000000..7660c0be --- /dev/null +++ b/djangocms_frontend/contrib/modal/cms_plugins.py @@ -0,0 +1,122 @@ +from cms.plugin_pool import plugin_pool +from django.utils.translation import gettext_lazy as _ + +from ... import settings +from ...cms_plugins import CMSUIPlugin +from ...common.attributes import AttributesMixin +from .. import modal +from . import forms, models + +mixin_factory = settings.get_renderer(modal) + + +@plugin_pool.register_plugin +class ModalPlugin(mixin_factory("Modal"), AttributesMixin, CMSUIPlugin): + """ + Component > "Modal" Plugin + https://getbootstrap.com/docs/5.0/components/modal/ + """ + + name = _("Modal") + module = _("Frontend") + model = models.Modal + form = forms.ModalForm + change_form_template = "djangocms_frontend/admin/modal.html" + allow_children = True + child_classes = [ + "ModalTriggerPlugin", + "ModalContainerPlugin", + "LinkPlugin", + "CardPlugin", + "SpacingPlugin", + "GridRowPlugin", + ] + + fieldsets = [ + (None, {"fields": ("modal_siblings",)}), + ] + + +@plugin_pool.register_plugin +class ModalTriggerPlugin(mixin_factory("ModalTrigger"), AttributesMixin, CMSUIPlugin): + """ + Component > "Modal" Plugin + https://getbootstrap.com/docs/5.0/components/modal/ + """ + + name = _("Modal trigger") + module = _("Frontend") + model = models.ModalTrigger + form = forms.ModalTriggerForm + allow_children = True + parent_classes = [ + "CardPlugin", + "CardInnerPlugin", + "ModalPlugin", + "GridColumnPlugin", + ] + + fieldsets = [ + (None, {"fields": ("trigger_identifier",)}), + ] + + +@plugin_pool.register_plugin +class ModalContainerPlugin(mixin_factory("ModalContainer"), CMSUIPlugin): + """ + Component > "Modal Container" Plugin + https://getbootstrap.com/docs/5.0/components/modal/ + """ + + name = _("Modal container") + module = _("Frontend") + model = models.ModalContainer + form = forms.ModalContainerForm + allow_children = True + child_classes = [ + "ModalInnerPlugin", + + ] + fieldsets = [ + ( + None, + { + "fields": ( + "container_identifier", + ("modal_centered"), + ("modal_static", "modal_scrollable"), + ("modal_size", "modal_fullscreen"), + ) + } + ), + ] + +@plugin_pool.register_plugin +class ModalInnerPlugin( + mixin_factory("ModalInner"), + CMSUIPlugin, +): + """ + Component > "Modal Container" Plugin + https://getbootstrap.com/docs/5.0/components/modal/ + """ + name = _("Modal inner") + module = _("Frontend") + model = models.ModalInner + form = forms.ModalInnerForm + allow_children = True + parent_classes = [ + "ModalContainerPlugin", + ] + + fieldsets = [ + ( + None, + { + "fields": ( + "inner_type", + "attributes", + ) + }, + ), + ] diff --git a/djangocms_frontend/contrib/modal/constants.py b/djangocms_frontend/contrib/modal/constants.py new file mode 100644 index 00000000..1117ac02 --- /dev/null +++ b/djangocms_frontend/contrib/modal/constants.py @@ -0,0 +1,27 @@ +from django.conf import settings +from django.utils.translation import gettext_lazy as _ + +MODAL_CENTERED_CHOICES = ( + ("modal-dialog-centered", _("Vertically centered")), + ("modal-dialog-centered modal-dialog-scrollable", _("Vertically centered scrollable")), +) + +MODAL_SIZE_CHOICES = ( + ("modal-sm", _("Small")), + ("modal-lg", _("Large")), + ("modal-xl", _("Extra Large")), +) + +MODAL_FULLSCREEN_CHOICES = ( + ("modal-fullscreen", _("Allways")), + ("modal-fullscreen-sm-down", _("Fullscreen below sm")), + ("modal-fullscreen-md-down", _("Fullscreen below md")), + ("modal-fullscreen-lg-down", _("Fullscreen below lg")), + ("modal-fullscreen-xl-down", _("Fullscreen below xl")), + ("modal-fullscreen-xxl-down", _("Fullscreen below xxl")), +) + +MODAL_INNER_TYPE_CHOICES = ( + ("modal-body", _("Body")), + ("modal-header", _("Header")), +) \ No newline at end of file diff --git a/djangocms_frontend/contrib/modal/forms.py b/djangocms_frontend/contrib/modal/forms.py new file mode 100644 index 00000000..985d9ef4 --- /dev/null +++ b/djangocms_frontend/contrib/modal/forms.py @@ -0,0 +1,172 @@ +from django import forms +from django.utils.translation import gettext_lazy as _ +from entangled.forms import EntangledModelForm + +from ... import settings +from ...fields import AttributesFormField, TagTypeFormField, ButtonGroup +from ...helpers import first_choice +from ...models import FrontendUIItem +from .. import modal + +from .constants import ( + MODAL_CENTERED_CHOICES, + MODAL_SIZE_CHOICES, + MODAL_FULLSCREEN_CHOICES, + MODAL_INNER_TYPE_CHOICES, +) + + +# TODO leaving this comment for now +# data-bs-toggle="modal" data-bs-target="#modalExample" +# aria-expanded="false" aria-controls="modalExample"> +# data-bs-target can also be classes +# data-bs-parent links to the wrapper modal +# From 5aaf335fdb48f67c6864c226612518e8783607dc Mon Sep 17 00:00:00 2001 From: Maximilian Vogel Date: Fri, 15 Nov 2024 16:13:30 +0100 Subject: [PATCH 17/17] adds an option for an additional footer --- djangocms_frontend/contrib/modal/cms_plugins.py | 1 + djangocms_frontend/contrib/modal/forms.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/djangocms_frontend/contrib/modal/cms_plugins.py b/djangocms_frontend/contrib/modal/cms_plugins.py index 7de6b0dd..a82e2652 100644 --- a/djangocms_frontend/contrib/modal/cms_plugins.py +++ b/djangocms_frontend/contrib/modal/cms_plugins.py @@ -82,6 +82,7 @@ class ModalContainerPlugin(mixin_factory("ModalContainer"), CMSUIPlugin): ("modal_centered"), ("modal_static", "modal_scrollable"), ("modal_size", "modal_fullscreen"), + ("modal_footer"), ) } ), diff --git a/djangocms_frontend/contrib/modal/forms.py b/djangocms_frontend/contrib/modal/forms.py index d91fb46a..bb7b01af 100644 --- a/djangocms_frontend/contrib/modal/forms.py +++ b/djangocms_frontend/contrib/modal/forms.py @@ -115,10 +115,10 @@ class Meta: help_text=_("If selected, the modal will not close when clicking outside of it."), ) - modal_footer = forms.BooleanField( - label=_("Footer"), + modal_footer = forms.BooleanField( + label=_("Footer and close button"), required=False, - help_text=_("If selected, the modal will display a footer with a close button."), + help_text=_("If selected, the modal will show a modal footer with a close button."), ) modal_scrollable = forms.BooleanField(