# HG changeset patch # User Thierry Florac # Date 1497446378 -7200 # Node ID f6474843036ee2a59036abf0813baa16277b497e # Parent 7214a95eaa9b73dc375c0ea3403ea3082761cb5c Use dynamic dialog class based on image width in adding and editing forms diff -r 7214a95eaa9b -r f6474843036e src/pyams_content/shared/imagemap/zmi/area.py --- a/src/pyams_content/shared/imagemap/zmi/area.py Wed Jun 14 15:19:03 2017 +0200 +++ b/src/pyams_content/shared/imagemap/zmi/area.py Wed Jun 14 15:19:38 2017 +0200 @@ -9,6 +9,7 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # +from pyams_i18n.interfaces import II18n __docformat__ = 'restructuredtext' @@ -62,7 +63,20 @@ """Imagemap area add form""" legend = _("Add new image area") - dialog_class = 'modal-large' + + @property + def dialog_class(self): + image = II18n(self.context).query_attribute('image', request=self.request) + if image is not None: + width = image.get_image_size()[0] + if width > 1000: + return 'modal-max' + elif width > 800: + return 'modal-xlarge' + else: + return 'modal-large' + else: + return 'modal-large' fields = field.Fields(IImageMapArea) fields['link'].widgetFactory = SingleLinkLinkSelectFieldWidget @@ -92,7 +106,20 @@ """Image map area properties edit form""" legend = _("Edit image map properties") - dialog_class = 'modal-large' + + @property + def dialog_class(self): + image = II18n(self.context.__parent__).query_attribute('image', request=self.request) + if image is not None: + width = image.get_image_size()[0] + if width > 1000: + return 'modal-max' + elif width > 800: + return 'modal-xlarge' + else: + return 'modal-large' + else: + return 'modal-large' fields = field.Fields(IImageMapArea) fields['link'].widgetFactory = SingleLinkLinkSelectFieldWidget