diff --git a/README.rst b/README.rst index ff929a91..942076f9 100644 --- a/README.rst +++ b/README.rst @@ -136,6 +136,7 @@ For a manual install: 'djangocms_frontend.contrib.link', 'djangocms_frontend.contrib.listgroup', 'djangocms_frontend.contrib.media', + 'djangocms_frontend.contrib.modal', 'djangocms_frontend.contrib.tabs', 'djangocms_frontend.contrib.utilities', 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..a82e2652 --- /dev/null +++ b/djangocms_frontend/contrib/modal/cms_plugins.py @@ -0,0 +1,120 @@ +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 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", + ] + + 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 = [ + "ModalPlugin" + ] + + 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 + parent_classes = [ + "ModalPlugin" + ] + child_classes = [ + "ModalInnerPlugin", + + ] + fieldsets = [ + ( + None, + { + "fields": ( + "container_identifier", + ("modal_centered"), + ("modal_static", "modal_scrollable"), + ("modal_size", "modal_fullscreen"), + ("modal_footer"), + ) + } + ), + ] + + +@plugin_pool.register_plugin +class ModalInnerPlugin( + mixin_factory("ModalInner"), + CMSUIPlugin, +): + """ + Component > "Modal Container Content" 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..601eccd9 --- /dev/null +++ b/djangocms_frontend/contrib/modal/constants.py @@ -0,0 +1,26 @@ +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")), +) diff --git a/djangocms_frontend/contrib/modal/forms.py b/djangocms_frontend/contrib/modal/forms.py new file mode 100644 index 00000000..bb7b01af --- /dev/null +++ b/djangocms_frontend/contrib/modal/forms.py @@ -0,0 +1,174 @@ +from django import forms +from django.utils.translation import gettext_lazy as _ +from entangled.forms import EntangledModelForm + +from ... import settings +from ...fields import AttributesFormField, ButtonGroup, TagTypeFormField +from ...helpers import first_choice +from ...models import FrontendUIItem +from .. import modal +from .constants import ( + MODAL_CENTERED_CHOICES, + MODAL_FULLSCREEN_CHOICES, + MODAL_INNER_TYPE_CHOICES, + MODAL_SIZE_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 +#