Updated pictogram selection widget header
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Jun 2018 14:43:21 +0200
changeset 609 375ab52043d6
parent 608 03a373d91db5
child 610 0e082a47ccd3
Updated pictogram selection widget header
src/pyams_content/component/paragraph/zmi/pictogram.py
src/pyams_content/reference/pictograms/zmi/__init__.py
src/pyams_content/reference/pictograms/zmi/templates/pictogram-header.pt
--- a/src/pyams_content/component/paragraph/zmi/pictogram.py	Mon Jun 11 14:42:50 2018 +0200
+++ b/src/pyams_content/component/paragraph/zmi/pictogram.py	Mon Jun 11 14:43:21 2018 +0200
@@ -9,6 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.reference.pictograms.zmi import get_pictogram_header
 
 __docformat__ = 'restructuredtext'
 
@@ -387,12 +388,11 @@
                 widget = self.widgets['pictogram_name']
                 widget.required = True
                 if pictogram is None:
-                    widget.after_widget_notice = '<span id="{0}" class="text-info">{1}</span>'.format(label_id, '--')
+                    widget.after_widget_notice = '<span id="{0}" class="text-info">--</span>'.format(label_id)
                 else:
                     widget.after_widget_notice = '<span id="{0}" class="text-info">{1}</span>'.format(
                         label_id,
-                        self.request.localizer.translate(_("Default header: {0}")).format(
-                            II18n(pictogram).query_attribute('header', request=self.request) or '--'))
+                        get_pictogram_header(pictogram, self.request))
                 widget.object_data = {
                     'ams-change-handler': 'MyAMS.helpers.select2ChangeHelper',
                     'ams-stop-propagation': 'true',
--- a/src/pyams_content/reference/pictograms/zmi/__init__.py	Mon Jun 11 14:42:50 2018 +0200
+++ b/src/pyams_content/reference/pictograms/zmi/__init__.py	Mon Jun 11 14:43:21 2018 +0200
@@ -44,6 +44,7 @@
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
 from pyramid.httpexceptions import HTTPNotFound, HTTPBadRequest
+from pyramid.renderers import render, render_to_response
 from pyramid.response import Response
 from pyramid.view import view_config
 from z3c.form import field
@@ -163,8 +164,8 @@
 
 @view_config(name='get-pictogram-header.html', context=IPictogramTable, request_type=IPyAMSLayer,
              permission=VIEW_SYSTEM_PERMISSION)
-def get_pictogram_label(request):
-    """Get alternate label associated with a given pictogram"""
+def get_pictogram_header_view(request):
+    """View used to get thumbnail and alternate label associated with a given pictogram"""
     name = request.params.get('value')
     if not name:
         raise HTTPBadRequest()
@@ -174,5 +175,13 @@
     pictogram = request.context.get(name)
     if pictogram is None:
         raise HTTPNotFound()
-    return Response(translate(_("Default header: {0}")).format(
-        II18n(pictogram).query_attribute('header', request=request) or '--'))
+    return render_to_response('templates/pictogram-header.pt', {
+        'context': pictogram
+    }, request=request)
+
+
+def get_pictogram_header(pictogram, request=None):
+    """Get thumbnail and alternate label associated with a given pictogram"""
+    return render('templates/pictogram-header.pt', {
+        'context': pictogram
+    }, request=request)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/reference/pictograms/zmi/templates/pictogram-header.pt	Mon Jun 11 14:43:21 2018 +0200
@@ -0,0 +1,9 @@
+<div i18n:domain="pyams_content">
+	<img class="padding-5"
+		 tal:define="image i18n:context.image"
+		 tal:attributes="src extension:absolute_url(image, '++thumb++32x32')" />
+	<span tal:define="header i18n:context.header"
+		  i18n:translate="">Default header:
+		<strong i18n:name="header" tal:content="header or '--'" />
+	</span>
+</div>