Updated verbatim renderer interface
authorThierry Florac <tflorac@ulthar.net>
Wed, 09 Jan 2019 11:40:08 +0100
changeset 358 16bcd95b1e01
parent 357 91b2ec075f2b
child 359 2eb804d4ea34
Updated verbatim renderer interface
src/pyams_default_theme/component/paragraph/interfaces/verbatim.py
src/pyams_default_theme/component/paragraph/templates/verbatim-default.pt
src/pyams_default_theme/component/paragraph/templates/verbatim-left.pt
src/pyams_default_theme/component/paragraph/templates/verbatim-right.pt
src/pyams_default_theme/component/paragraph/verbatim.py
--- a/src/pyams_default_theme/component/paragraph/interfaces/verbatim.py	Wed Jan 09 10:24:17 2019 +0100
+++ b/src/pyams_default_theme/component/paragraph/interfaces/verbatim.py	Wed Jan 09 11:40:08 2019 +0100
@@ -13,11 +13,12 @@
 __docformat__ = 'restructuredtext'
 
 from zope.interface import Interface
-from zope.schema import Choice
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from zope.schema import Bool, Choice
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
 from pyams_default_theme import _
 
+
 FRAME_POSITIONS = (
     {'id': 'left', 'title': _("Left")},
     {'id': 'right', 'title': _("Right")},
@@ -28,7 +29,16 @@
                                                for item in FRAME_POSITIONS])
 
 
-class ILateralVerbatimParagraphRendererSettings(Interface):
+class IVerbatimParagraphRendererSettings(Interface):
+    """Verbatim paragraph renderer settings"""
+
+    zoom_on_click = Bool(title=_("Zoom on image click?"),
+                         description=_("If 'yes', a click on illustration thumbnail is required to zoom"),
+                         required=True,
+                         default=True)
+
+
+class ILateralVerbatimParagraphRendererSettings(IVerbatimParagraphRendererSettings):
     """Verbatim paragraph lateral renderer settings interface"""
 
     relative_width = Choice(title=_("Relative width"),
--- a/src/pyams_default_theme/component/paragraph/templates/verbatim-default.pt	Wed Jan 09 10:24:17 2019 +0100
+++ b/src/pyams_default_theme/component/paragraph/templates/verbatim-default.pt	Wed Jan 09 11:40:08 2019 +0100
@@ -14,8 +14,17 @@
 					 tal:define="photo i18n:illustration.data;
 								 alt i18n:illustration.alt_title;"
 					 tal:condition="photo">
-					${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
-													 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
+					<a tal:define="thumbnails tales:thumbnails(photo);
+								   target thumbnails.get_thumbnail('800x600');"
+					   tal:omit-tag="not:settings.zoom_on_click"
+					   href="${tales:absolute_url(target)}"
+					   data-toggle="${'lightbox' if settings.zoom_on_click else None}"
+					   data-type="image"
+					   data-title="${i18n:illustration.title}"
+					   data-footer="${illustration.author}">
+						${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
+														 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
+					</a>
 				</div>
 			</tal:if>
 			<div class="col-md-10 col-sm-9 col-xs-12"
@@ -30,4 +39,4 @@
 			</div>
 		</div>
 	</div>
-</div>
+</div>
\ No newline at end of file
--- a/src/pyams_default_theme/component/paragraph/templates/verbatim-left.pt	Wed Jan 09 10:24:17 2019 +0100
+++ b/src/pyams_default_theme/component/paragraph/templates/verbatim-left.pt	Wed Jan 09 11:40:08 2019 +0100
@@ -1,31 +1,41 @@
-<div class="bordered verbatim padding-20 pull-left"
-	 tal:define="settings view.settings;
+<div tal:define="settings view.settings;
 				 illustration tales:pyams_illustration(context);
 				 display_illustration view.can_display_illustration()"
-	 tal:attributes="class string:${default} col-md-${settings.relative_width}">
-	<h3 tal:condition="view.title">${view.title}</h3>
-	<tal:if condition="display_illustration and illustration">
-		<div class="illustration col-md-2"
-			 tal:define="photo i18n:illustration.data;
-						 alt i18n:illustration.alt_title;"
-			 tal:condition="photo">
-			${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
-											 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
-		</div>
-		<div class="author col-md-4">
-			<span tal:content="view.author">Author</span><br />
-			<span tal:content="view.charge">Charge</span>
+	 class="bordered verbatim padding-20 pull-left col-md-${settings.relative_width}">
+	<div class="panel panel-default">
+		<div class="panel-heading"
+			 tal:define="title view.title"
+			 tal:condition="title">
+			<h3 class="panel-title">${title}</h3>
 		</div>
-		<div class="quote col-md-5"
-			 tal:content="tales:html(view.quote)">Quote</div>
-	</tal:if>
-	<tal:if condition="not:display_illustration">
-		<div class="quote"
-			 tal:content="structure tales:html(view.quote)">Quote</div>
-		<div class="author">
-			${view.author}<tal:if
-				condition="view.author and view.charge">, </tal:if>
-			${view.charge}
+		<div class="panel-body">
+			<tal:if condition="display_illustration and illustration">
+				<div class="illustration col-md-3 hidden-sm hidden-xs"
+					 tal:define="photo i18n:illustration.data;
+								 alt i18n:illustration.alt_title;"
+					 tal:condition="photo">
+					<a tal:define="thumbnails tales:thumbnails(photo);
+								   target thumbnails.get_thumbnail('800x600');"
+					   tal:omit-tag="not:settings.zoom_on_click"
+					   href="${tales:absolute_url(target)}"
+					   data-toggle="${'lightbox' if settings.zoom_on_click else None}"
+					   data-type="image"
+					   data-title="${i18n:illustration.title}"
+					   data-footer="${illustration.author}">
+						${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
+														 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
+					</a>
+				</div>
+			</tal:if>
+			<div class="col-md-9 col-sm-12"
+				 tal:omit-tag="not:display_illustration">
+				<div class="quote">${structure:tales:html(view.quote)}</div>
+				<div class="author">
+					<strong>${view.author}</strong><tal:if
+						condition="view.author and view.charge">, </tal:if>
+					${view.charge}
+				</div>
+			</div>
 		</div>
-	</tal:if>
+	</div>
 </div>
--- a/src/pyams_default_theme/component/paragraph/templates/verbatim-right.pt	Wed Jan 09 10:24:17 2019 +0100
+++ b/src/pyams_default_theme/component/paragraph/templates/verbatim-right.pt	Wed Jan 09 11:40:08 2019 +0100
@@ -1,31 +1,41 @@
-<div class="bordered verbatim padding-20 pull-right"
-	 tal:define="settings view.settings;
+<div tal:define="settings view.settings;
 				 illustration tales:pyams_illustration(context);
 				 display_illustration view.can_display_illustration()"
-	 tal:attributes="class string:${default} col-md-${settings.relative_width}">
-	<h3 tal:condition="view.title">${view.title}</h3>
-	<tal:if condition="display_illustration and illustration">
-		<div class="illustration col-md-2"
-			 tal:define="photo i18n:illustration.data;
-						 alt i18n:illustration.alt_title;"
-			 tal:condition="photo">
-			${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
-											 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
-		</div>
-		<div class="author col-md-4">
-			<span tal:content="view.author">Author</span><br />
-			<span tal:content="view.charge">Charge</span>
+	 class="bordered verbatim padding-20 pull-right col-md-${settings.relative_width}">
+	<div class="panel panel-default">
+		<div class="panel-heading"
+			 tal:define="title view.title"
+			 tal:condition="title">
+			<h3 class="panel-title">${title}</h3>
 		</div>
-		<div class="quote col-md-5"
-			 tal:content="tales:html(view.quote)">Quote</div>
-	</tal:if>
-	<tal:if condition="not:display_illustration">
-		<div class="quote"
-			 tal:content="structure tales:html(view.quote)">Quote</div>
-		<div class="author">
-			${view.author}<tal:if
-				condition="view.author and view.charge">, </tal:if>
-			${view.charge}
+		<div class="panel-body">
+			<tal:if condition="display_illustration and illustration">
+				<div class="illustration col-md-3 hidden-sm hidden-xs"
+					 tal:define="photo i18n:illustration.data;
+								 alt i18n:illustration.alt_title;"
+					 tal:condition="photo">
+					<a tal:define="thumbnails tales:thumbnails(photo);
+								   target thumbnails.get_thumbnail('800x600');"
+					   tal:omit-tag="not:settings.zoom_on_click"
+					   href="${tales:absolute_url(target)}"
+					   data-toggle="${'lightbox' if settings.zoom_on_click else None}"
+					   data-type="image"
+					   data-title="${i18n:illustration.title}"
+					   data-footer="${illustration.author}">
+						${structure:tales:picture(photo, lg_thumb='portrait', md_thumb='portrait',
+														 sm_thumb='portrait', xs_thumb='portrait', alt=alt)}
+					</a>
+				</div>
+			</tal:if>
+			<div class="col-md-9 col-sm-12"
+				 tal:omit-tag="not:display_illustration">
+				<div class="quote">${structure:tales:html(view.quote)}</div>
+				<div class="author">
+					<strong>${view.author}</strong><tal:if
+						condition="view.author and view.charge">, </tal:if>
+					${view.charge}
+				</div>
+			</div>
 		</div>
-	</tal:if>
+	</div>
 </div>
--- a/src/pyams_default_theme/component/paragraph/verbatim.py	Wed Jan 09 10:24:17 2019 +0100
+++ b/src/pyams_default_theme/component/paragraph/verbatim.py	Wed Jan 09 11:40:08 2019 +0100
@@ -20,30 +20,51 @@
 from pyams_content.component.illustration.interfaces import IIllustration
 from pyams_content.component.paragraph.interfaces.verbatim import IVerbatimParagraph
 from pyams_content.features.renderer.interfaces import IContentRenderer
-from pyams_default_theme.component.paragraph.interfaces.verbatim import ILateralVerbatimParagraphRendererSettings
+from pyams_default_theme import _
+from pyams_default_theme.component.paragraph.interfaces.verbatim import ILateralVerbatimParagraphRendererSettings, \
+    IVerbatimParagraphRendererSettings
 from pyams_default_theme.features.renderer import BaseContentRenderer
 from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config, get_annotation_adapter
 
-from pyams_default_theme import _
+
+#
+# Verbatim paragraph renderer settings
+#
+
+VERBATIM_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.verbatim.renderer'
+
+
+@implementer(IVerbatimParagraphRendererSettings)
+class VerbatimParagraphRendererSettings(Persistent, Location):
+    """Verbatim paragraph renderer settings"""
+
+    zoom_on_click = FieldProperty(IVerbatimParagraphRendererSettings['zoom_on_click'])
+
+
+@adapter_config(context=IVerbatimParagraph, provides=IVerbatimParagraphRendererSettings)
+def verbatim_paragraph_renderer_settings_factory(context):
+    """Frame text paragraph renderer settings factory"""
+    return get_annotation_adapter(context, VERBATIM_PARAGRAPH_RENDERER_SETTINGS_KEY,
+                                  VerbatimParagraphRendererSettings)
 
 
 #
 # Verbatim paragraph lateral renderer settings
 #
 
+LATERAL_VERBATIM_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.verbatim.renderer:lateral'
+
+
 @implementer(ILateralVerbatimParagraphRendererSettings)
-class LateralVerbatimParagraphRendererSettings(Persistent, Location):
+class LateralVerbatimParagraphRendererSettings(VerbatimParagraphRendererSettings):
     """Verbatim paragraph lateral renderer settings"""
 
     relative_width = FieldProperty(ILateralVerbatimParagraphRendererSettings['relative_width'])
 
 
-LATERAL_VERBATIM_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.verbatim.renderer:lateral'
-
-
 @adapter_config(context=IVerbatimParagraph, provides=ILateralVerbatimParagraphRendererSettings)
 def lateral_verbatim_paragraph_renderer_settings_factory(context):
     """Frame text paragraph lateral renderer settings factory"""
@@ -75,6 +96,8 @@
     label = _("Default verbatim renderer")
     weight = 1
 
+    settings_interface = IVerbatimParagraphRendererSettings
+
 
 @adapter_config(name='left', context=(IVerbatimParagraph, IPyAMSLayer), provides=IContentRenderer)
 @template_config(template='templates/verbatim-left.pt', layer=IPyAMSLayer)