Add optional internal reference to menu
authorThierry Florac <thierry.florac@onf.fr>
Mon, 09 Jul 2018 11:59:06 +0200
changeset 810 7b5d910b2205
parent 809 efdeebb63567
child 811 7ead60a391c3
Add optional internal reference to menu
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/features/menu/__init__.py	Mon Jul 09 11:58:42 2018 +0200
+++ b/src/pyams_content/features/menu/__init__.py	Mon Jul 09 11:59:06 2018 +0200
@@ -20,6 +20,7 @@
 
 # import packages
 from pyams_content.component.association.container import AssociationContainer
+from pyams_sequence.utility import get_reference_target
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
 
@@ -34,6 +35,10 @@
 
     visible = FieldProperty(IMenu['visible'])
     title = FieldProperty(IMenu['title'])
+    reference = FieldProperty(IMenu['reference'])
+
+    def get_target(self):
+        return get_reference_target(self.reference)
 
 
 @implementer(IMenusContainer)
--- a/src/pyams_content/features/menu/interfaces/__init__.py	Mon Jul 09 11:58:42 2018 +0200
+++ b/src/pyams_content/features/menu/interfaces/__init__.py	Mon Jul 09 11:59:06 2018 +0200
@@ -17,10 +17,10 @@
 
 # import interfaces
 from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationContainerTarget
-from zope.annotation.interfaces import IAttributeAnnotatable
 
 # import packages
 from pyams_i18n.schema import I18nTextLineField
+from pyams_sequence.schema import InternalReference
 from zope.container.constraints import containers, contains
 from zope.interface import Interface
 from zope.schema import Bool
@@ -64,6 +64,13 @@
                               description=_("Displayed menu label"),
                               required=True)
 
+    reference = InternalReference(title=_("Internal reference"),
+                                  description=_("Direct reference to menu target"),
+                                  required=False)
+
+    def get_target(self):
+        """Get reference target"""
+
 
 class IMenusContainer(IAssociationContainer):
     """Menus container interface"""
--- a/src/pyams_content/features/menu/zmi/__init__.py	Mon Jul 09 11:58:42 2018 +0200
+++ b/src/pyams_content/features/menu/zmi/__init__.py	Mon Jul 09 11:59:06 2018 +0200
@@ -92,7 +92,7 @@
     legend = _("Add new menu")
     icon_css_class = 'fa fa-fw fa-bars'
 
-    fields = field.Fields(IMenu).select('title')
+    fields = field.Fields(IMenu).select('title', 'reference')
     edit_permission = MANAGE_TEMPLATE_PERMISSION
 
     def create(self, data):
@@ -125,7 +125,7 @@
 
     dialog_class = 'modal-large'
 
-    fields = field.Fields(IMenu).select('title')
+    fields = field.Fields(IMenu).select('title', 'reference')
     edit_permission = MANAGE_TEMPLATE_PERMISSION
 
     def get_ajax_output(self, changes):