Added Pictogram in Menu Navigation component dev-dc
authorDamien Correia
Fri, 05 Oct 2018 10:48:41 +0200
branchdev-dc
changeset 1000 02a2b18d0ff7
parent 999 f50be61c93a6
child 1001 ad63fa80bb49
child 1012 d77417cf9e67
Added Pictogram in Menu Navigation component
src/pyams_content/component/extfile/zmi/__init__.py
src/pyams_content/component/links/zmi/__init__.py
src/pyams_content/features/menu/__init__.py
src/pyams_content/features/menu/interfaces/__init__.py
src/pyams_content/features/menu/zmi/__init__.py
--- a/src/pyams_content/component/extfile/zmi/__init__.py	Fri Oct 05 10:44:32 2018 +0200
+++ b/src/pyams_content/component/extfile/zmi/__init__.py	Fri Oct 05 10:48:41 2018 +0200
@@ -138,9 +138,7 @@
     edit_permission = MANAGE_CONTENT_PERMISSION
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseExtFile, ())) or \
-           ('filename' in changes.get(IBaseExtFile, ())) or \
-           ('data' in changes.get(IExtFile, ())):
+        if changes:
             return self.get_associations_table()
         else:
             return super(self.__class__, self).get_ajax_output(changes)
@@ -231,9 +229,7 @@
             self.widgets['description'].description = None
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseExtFile, ())) or \
-           ('filename' in changes.get(IBaseExtFile, ())) or \
-           ('data' in changes.get(IExtFile, ())):
+        if changes:
             return self.get_associations_table()
         else:
             return super(self.__class__, self).get_ajax_output(changes)
@@ -310,9 +306,7 @@
     fields = field.Fields(IExtVideo).select('data', 'filename', 'title', 'description', 'author', 'language')
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseExtFile, ())) or \
-           ('filename' in changes.get(IBaseExtFile, ())) or \
-           ('data' in changes.get(IExtFile, ())):
+        if changes:
             return self.get_associations_table()
         else:
             return super(self.__class__, self).get_ajax_output(changes)
@@ -389,9 +383,7 @@
     fields = field.Fields(IExtAudio).select('data', 'filename', 'title', 'description', 'author', 'language')
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseExtFile, ())) or \
-           ('filename' in changes.get(IBaseExtFile, ())) or \
-           ('data' in changes.get(IExtFile, ())):
+        if changes:
             return self.get_associations_table()
         else:
             return super(self.__class__, self).get_ajax_output(changes)
--- a/src/pyams_content/component/links/zmi/__init__.py	Fri Oct 05 10:44:32 2018 +0200
+++ b/src/pyams_content/component/links/zmi/__init__.py	Fri Oct 05 10:48:41 2018 +0200
@@ -127,8 +127,7 @@
     edit_permission = None  # defined by IFormContextPermissionChecker adapter
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseLink, ())) or \
-           ('reference' in changes.get(IInternalLink, ())):
+        if changes:
             return self.get_associations_table()
         else:
             return super(self.__class__, self).get_ajax_output(changes)
@@ -216,8 +215,7 @@
     edit_permission = None  # defined by IFormContextPermissionChecker adapter
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseLink, ())) or \
-           ('url' in changes.get(IExternalLink, ())):
+        if changes:
             return self.get_associations_table()
         else:
             return super(self.__class__, self).get_ajax_output(changes)
@@ -304,7 +302,7 @@
     edit_permission = None  # defined by IFormContextPermissionChecker adapter
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseLink, ())) or changes.get(IMailtoLink, ()):
+        if changes:
             return self.get_associations_table()
         else:
             return super(self.__class__, self).get_ajax_output(changes)
--- a/src/pyams_content/features/menu/__init__.py	Fri Oct 05 10:44:32 2018 +0200
+++ b/src/pyams_content/features/menu/__init__.py	Fri Oct 05 10:48:41 2018 +0200
@@ -17,10 +17,12 @@
 
 # import interfaces
 from pyams_content.features.menu.interfaces import IMenu, IMenusContainer, IMenuLink
-
+from pyams_content.reference.pictograms import IPictogramTable
 # import packages
 from pyams_content.component.association.container import AssociationContainer
 from pyams_content.component.links import InternalReferenceMixin
+from pyams_utils.registry import query_utility
+from pyams_utils.zodb import volatile_property
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
 
@@ -36,6 +38,23 @@
     visible = FieldProperty(IMenu['visible'])
     title = FieldProperty(IMenu['title'])
     reference = FieldProperty(IMenu['reference'])
+    _pictogram_name = FieldProperty(IMenu['pictogram_name'])
+
+    @property
+    def pictogram_name(self):
+        return self._pictogram_name
+
+    @pictogram_name.setter
+    def pictogram_name(self, value):
+        if value != self._pictogram_name:
+            self._pictogram_name = value
+            del self.pictogram
+
+    @volatile_property
+    def pictogram(self):
+        table = query_utility(IPictogramTable)
+        if table is not None:
+            return table.get(self._pictogram_name)
 
 
 @implementer(IMenusContainer)
--- a/src/pyams_content/features/menu/interfaces/__init__.py	Fri Oct 05 10:44:32 2018 +0200
+++ b/src/pyams_content/features/menu/interfaces/__init__.py	Fri Oct 05 10:48:41 2018 +0200
@@ -21,10 +21,11 @@
 
 # import packages
 from pyams_i18n.schema import I18nTextLineField
+from pyams_content.reference.pictograms.interfaces import SELECTED_PICTOGRAM_VOCABULARY
 from pyams_sequence.schema import InternalReferenceField
 from zope.container.constraints import containers, contains
 from zope.interface import Interface
-from zope.schema import Bool
+from zope.schema import Bool, Choice
 
 from pyams_content import _
 
@@ -69,6 +70,10 @@
                                        description=_("Direct reference to menu target"),
                                        required=False)
 
+    pictogram_name = Choice(title=_("Pictogram"),
+                            description=_("Name of the pictogram associated with this menu"),
+                            required=False,
+                            vocabulary=SELECTED_PICTOGRAM_VOCABULARY)
 
 class IMenusContainer(IAssociationContainer):
     """Menus container interface"""
--- a/src/pyams_content/features/menu/zmi/__init__.py	Fri Oct 05 10:44:32 2018 +0200
+++ b/src/pyams_content/features/menu/zmi/__init__.py	Fri Oct 05 10:48:41 2018 +0200
@@ -9,6 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.reference.pictograms.zmi.widget import PictogramSelectFieldWidget
 
 __docformat__ = 'restructuredtext'
 
@@ -92,7 +93,8 @@
     legend = _("Add new menu")
     icon_css_class = 'fa fa-fw fa-bars'
 
-    fields = field.Fields(IMenu).select('title', 'reference')
+    fields = field.Fields(IMenu).select('title', 'reference', 'pictogram_name')
+    fields['pictogram_name'].widgetFactory = PictogramSelectFieldWidget
     edit_permission = MANAGE_TEMPLATE_PERMISSION
 
     def create(self, data):
@@ -125,7 +127,9 @@
 
     dialog_class = 'modal-large'
 
-    fields = field.Fields(IMenu).select('title', 'reference')
+    fields = field.Fields(IMenu).select('title', 'reference', 'pictogram_name')
+    fields['pictogram_name'].widgetFactory = PictogramSelectFieldWidget
+
     edit_permission = MANAGE_TEMPLATE_PERMISSION
 
     def get_ajax_output(self, changes):