Added "mailto:" links into menus and navigation components
authorThierry Florac <tflorac@ulthar.net>
Fri, 08 Feb 2019 14:06:37 +0100
changeset 1273 e03e6f60a7e4
parent 1272 5f9fbc917df0
child 1274 a3ea045fdd06
Added "mailto:" links into menus and navigation components
src/pyams_content/features/menu/interfaces.py
src/pyams_content/features/menu/zmi/__init__.py
--- a/src/pyams_content/features/menu/interfaces.py	Fri Feb 08 14:06:10 2019 +0100
+++ b/src/pyams_content/features/menu/interfaces.py	Fri Feb 08 14:06:37 2019 +0100
@@ -16,14 +16,13 @@
 from zope.interface import Attribute, Interface
 from zope.schema import Bool, Choice
 
+from pyams_content import _
 from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationContainerTarget
 from pyams_content.reference.pictograms.interfaces import SELECTED_PICTOGRAM_VOCABULARY
 from pyams_i18n.schema import I18nTextLineField
 from pyams_sequence.interfaces import IInternalReference
 from pyams_sequence.schema import InternalReferenceField
 
-from pyams_content import _
-
 
 class IMenuLink(Interface):
     """Menu link marker interface"""
@@ -37,6 +36,10 @@
     """Menu external link marker interface"""
 
 
+class IMenuMailtoLink(IMenuLink):
+    """Menu mailto link marker interface"""
+
+
 class IDynamicMenu(Interface):
     """Dynamic menu interface"""
 
--- a/src/pyams_content/features/menu/zmi/__init__.py	Fri Feb 08 14:06:10 2019 +0100
+++ b/src/pyams_content/features/menu/zmi/__init__.py	Fri Feb 08 14:06:37 2019 +0100
@@ -23,12 +23,14 @@
 from z3c.table.interfaces import IColumn, IValues
 from zope.interface import Interface, alsoProvides, implementer
 
+from pyams_content import _
 from pyams_content.component.association.zmi import AssociationsTable, AssociationsTablePublicNameColumn
 from pyams_content.component.links.zmi import ExternalLinkAddForm, ExternalLinkAddMenu, ExternalLinkPropertiesEditForm, \
-    InternalLinkAddForm, InternalLinkAddMenu, InternalLinkPropertiesEditForm
+    InternalLinkAddForm, InternalLinkAddMenu, InternalLinkPropertiesEditForm, MailtoLinkAddForm, MailtoLinkAddMenu, \
+    MailtoLinkPropertiesEditForm
 from pyams_content.features.menu import IMenu, IMenuLink, IMenusContainer, Menu
 from pyams_content.features.menu.interfaces import IMenuExternalLink, IMenuInternalLink, IMenuLinksContainer, \
-    IMenuLinksContainerTarget, IMenusContainerTarget
+    IMenuLinksContainerTarget, IMenuMailtoLink, IMenusContainerTarget
 from pyams_content.reference.pictograms.zmi.widget import PictogramSelectFieldWidget
 from pyams_form.form import AJAXAddForm, AJAXEditForm, ajax_config
 from pyams_form.interfaces.form import IFormContextPermissionChecker
@@ -53,8 +55,6 @@
 from pyams_zmi.interfaces import IPropertiesEditForm
 from pyams_zmi.zmi.table import InnerTableView
 
-from pyams_content import _
-
 
 #
 # Custom marker interfaces
@@ -520,3 +520,46 @@
 
     def get_ajax_output(self, changes):
         return LinkPropertiesAJAXEditForm.get_ajax_output(self, changes)
+
+
+#
+# Mailto links
+#
+
+@viewlet_config(name='add-mailto-link.menu', context=IMenuLinksContainerTarget, view=IMenuLinksView,
+                layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=51)
+@viewlet_config(name='add-mailto-link.menu', context=IMenu, layer=IPyAMSLayer,
+                view=MenuLinksTable, manager=IToolbarAddingMenu, permission=MANAGE_TEMPLATE_PERMISSION, weight=51)
+class MenuMailtoLinkAddMenu(MailtoLinkAddMenu):
+    """Menu mailto link add menu"""
+
+
+@pagelet_config(name='add-mailto-link.html', context=IMenuLinksContainer, layer=IPyAMSLayer,
+                permission=MANAGE_TEMPLATE_PERMISSION)
+@ajax_config(name='add-mailto-link.json', context=IMenuLinksContainer, layer=IPyAMSLayer,
+             base=LinkAJAXAddForm)
+class MenuMailtoLinkAddForm(MailtoLinkAddForm):
+    """Menu mailto link add form"""
+
+    edit_permission = MANAGE_TEMPLATE_PERMISSION
+
+    def create(self, data):
+        result = super(MenuMailtoLinkAddForm, self).create(data)
+        alsoProvides(result, IMenuMailtoLink)
+        return result
+
+    def add(self, object):
+        self.context.append(object)
+
+
+@pagelet_config(name='properties.html', context=IMenuMailtoLink, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+@ajax_config(name='properties.json', context=IMenuMailtoLink, layer=IPyAMSLayer,
+             base=LinkPropertiesAJAXEditForm)
+class MenuMailtoLinkPropertiesEditForm(MailtoLinkPropertiesEditForm):
+    """Menu mailto link properties edit form"""
+
+    edit_permission = None  # managed by IFormContextPermissionChecker adapter
+
+    def get_ajax_output(self, changes):
+        return LinkPropertiesAJAXEditForm.get_ajax_output(self, changes)