Updated Paragraph doc doc-dc
authorDamien Correia
Mon, 04 Jun 2018 14:14:41 +0200
branchdoc-dc
changeset 77 ae0e104800aa
parent 76 ca63b1a69cbb
child 78 88a65b19d07d
Updated Paragraph doc
src/source/howto-paragraph.rst
--- a/src/source/howto-paragraph.rst	Mon Jun 04 12:23:38 2018 +0200
+++ b/src/source/howto-paragraph.rst	Mon Jun 04 14:14:41 2018 +0200
@@ -34,12 +34,6 @@
     phone = TextLine(title=_("Phone Number"),
                      description=_("Name of the contact", required=False))
 
-    address = Text(title=_("Address"), required=False)
-
-    contact_email = MailAddressField(title=_("Email address"),
-                                     description=_("Contact email address"),
-                                     required=False)
-
     renderer = Choice(title=_("Contact template"),
                       description=_("Presentation template used for this contact"),
                       vocabulary=CONTACT_PHONE_PARAGRAPH_RENDERERS,
@@ -64,8 +58,9 @@
         icon_class = 'fa-phone'
         icon_hint = _("Phone number card")
 
-        address = FieldProperty(IContactParagraph['address'])
-        contact_email = FieldProperty(IContactParagraph['contact_email'])
+        name = FieldProperty(IContactPhoneParagraph['name'])
+        _photo = FileProperty(IContactPhoneParagraph['photo'])
+
         renderer = FieldProperty(IContactParagraph['renderer'])
 
         @property
@@ -79,7 +74,7 @@
                 alsoProvides(self._photo, IResponsiveImage)
 
 
-3) renderer Vocabulary
+3) renderers Vocabulary
 ----------------------
 
 The list of rendered available for a paragraph is build automatically and is based on adapters that provide this interface
@@ -88,9 +83,9 @@
 
     @vocabulary_config(name=CONTACT_PARAGRAPH_RENDERERS)
     class ContactParagraphRendererVocabulary(RenderersVocabulary):
-        """Contact paragraph renderers vocabulary"""
+        """Contact Phone paragraph renderers vocabulary"""
 
-        content_interface = IContactParagraph
+        content_interface = IContactPhoneParagraph
 
 
 .. seealso::
@@ -103,7 +98,7 @@
 
 To display and manage the new paragraph in the ZMI, you should create this associated forms
 
-1) paragraph factory
+1) Paragraph factory
 --------------------
 
 To create a new element inside the zodb, we need a container to this element. PyAMS provide
@@ -116,26 +111,21 @@
 
 .. code-block:: python
 
-    @pagelet_config(name='add-contact-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+    @pagelet_config(name='add-contact-phone-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
                     permission=MANAGE_CONTENT_PERMISSION)
-    class ContactParagraphAddForm(AdminDialogAddForm):
-        """Contact paragraph add form"""
+    class ContactPhoneParagraphAddForm(AdminDialogAddForm):
+        """Contact phone paragraph add form"""
 
-        legend = _("Add new contact card")
+        legend = _("Add new contact phone card")
         dialog_class = 'modal-large'
-        icon_css_class = 'fa fa-fw fa-id-card-o'
+        icon_css_class = 'fa fa-fw fa-phone'
 
-        fields = field.Fields(IContactParagraph).omit('__parent__', '__name__', 'visible')
-        ajax_handler = 'add-contact-paragraph.json'
+        fields = field.Fields(IContactPhoneParagraph).omit('__parent__', '__name__', 'visible')
+        ajax_handler = 'add-contact-phone-paragraph.json' #(*)
         edit_permission = MANAGE_CONTENT_PERMISSION
 
-        def updateWidgets(self, prefix=None):
-            super(ContactParagraphAddForm, self).updateWidgets(prefix)
-            if 'address' in self.widgets:
-                self.widgets['address'].widget_css_class = 'textarea'
-
-        def create(self, data):
-            return ContactParagraph()
+         def create(self, data):
+            return ContactPhoneParagraph()
 
         def add(self, object):
             IParagraphContainer(self.context).append(object)
@@ -145,10 +135,11 @@
 
 .. code-block:: python
 
-    @view_config(name='add-contact-paragraph.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
+    #(*)
+    @view_config(name='add-contact-phone-1paragraph.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
                  permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-    class ContactParagraphAJAXAddForm(BaseParagraphAJAXAddForm, ContactParagraphAddForm):
-        """Contact paragraph add form, JSON renderer"""
+    class ContactPhoneParagraphAJAXAddForm(BaseParagraphAJAXAddForm, ContactPhoneParagraphAddForm):
+        """Contact phone paragraph add form, JSON renderer"""
 
 
 2) Append the paragraph addform button in the menu
@@ -158,9 +149,9 @@
 
 .. code-block:: python
 
-    @viewlet_config(name='add-contact-paragraph.menu', context=IParagraphContainerTarget, view=IParagraphContainerView,
+    @viewlet_config(name='add-contact-phone-paragraph.menu', context=IParagraphContainerTarget, view=IParagraphContainerView,
                     layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=600)
-    class ContactParagraphAddMenu(BaseParagraphAddMenu):
+    class ContactPhoneParagraphAddMenu(BaseParagraphAddMenu):
         """Contact paragraph add menu"""
 
         label = _("Contact card...")
@@ -169,8 +160,8 @@
         paragraph_type = CONTACT_PARAGRAPH_TYPE
 
 
-3)Edit form
------------
+3) Create Edit form
+-------------------
 
 - *HTML*
 
@@ -178,8 +169,8 @@
 
     @pagelet_config(name='properties.html', context=IContactParagraph, layer=IPyAMSLayer,
                     permission=MANAGE_CONTENT_PERMISSION)
-    class ContactParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm):
-        """Contact paragraph properties edit form"""
+    class ContactPhoneParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm):
+        """Contact phone paragraph properties edit form"""
 
         prefix = 'contact_properties.'
 
@@ -192,24 +183,24 @@
         ajax_handler = 'properties.json'
         edit_permission = MANAGE_CONTENT_PERMISSION
 
-        def updateWidgets(self, prefix=None):
-            super(ContactParagraphPropertiesEditForm, self).updateWidgets(prefix)
-            if 'address' in self.widgets:
-                self.widgets['address'].widget_css_class = 'textarea'
 
 - *JSON*
 
 .. code-block:: python
 
-    @view_config(name='properties.json', context=IContactParagraph, request_type=IPyAMSLayer,
+    @view_config(name='properties.json', context=IContactPhoneParagraph, request_type=IPyAMSLayer,
                  permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-    class ContactParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, ContactParagraphPropertiesEditForm):
-        """Contact paragraph properties edit form, JSON renderer"""
+    class ContactPhoneParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, ContactParagraphPropertiesEditForm):
+        """Contact phone paragraph properties edit form, JSON renderer"""
 
 
-    @adapter_config(context=(IContactParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
+4) Create ZMI Edit form inner tab
+---------------------------------
+
+.. code-block:: python
+    @adapter_config(context=(IContactPhoneParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
     @implementer(IInnerForm)
-    class ContactParagraphInnerEditForm(ContactParagraphPropertiesEditForm):
+    class ContactPhoneParagraphInnerEditForm(ContactPhoneParagraphPropertiesEditForm):
         """Contact paragraph inner edit form"""
 
         legend = None
@@ -223,9 +214,12 @@
                 return button.Buttons()
 
 
-    @view_config(name='inner-properties.json', context=IContactParagraph, request_type=IPyAMSLayer,
+
+.. code-block:: python
+
+    @view_config(name='inner-properties.json', context=IContactPhoneParagraph, request_type=IPyAMSLayer,
                  permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-    class ContactParagraphInnerAJAXEditForm(BaseParagraphAJAXEditForm, ContactParagraphInnerEditForm):
+    class ContactPhoneParagraphInnerAJAXEditForm(BaseParagraphAJAXEditForm, ContactParagraphInnerEditForm):
         """Contact paragraph inner edit form, JSON renderer"""
 
         def get_ajax_output(self, changes):