Updated forms JSON output
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 14:49:41 +0200
changeset 135 e85b629864ee
parent 134 2ee56ec464d5
child 136 5d1a29312100
Updated forms JSON output
src/pyams_content/shared/common/zmi/properties.py
--- a/src/pyams_content/shared/common/zmi/properties.py	Mon Sep 11 14:49:06 2017 +0200
+++ b/src/pyams_content/shared/common/zmi/properties.py	Mon Sep 11 14:49:41 2017 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyramid.events import subscriber
 
 __docformat__ = 'restructuredtext'
 
@@ -17,15 +16,14 @@
 # import standard library
 
 # import interfaces
-from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
+from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION, IBaseContent
 from pyams_content.shared.common.interfaces import IWfSharedContent
 from pyams_form.interfaces.form import IWidgetForm, IInnerSubForm
 from pyams_skin.interfaces import IInnerPage, IPageHeader
 from pyams_skin.layer import IPyAMSLayer
-from pyams_workflow.interfaces import IWorkflowPublicationInfo, IWorkflowState, IWorkflow
+from pyams_workflow.interfaces import IWorkflowPublicationInfo
 from pyams_zmi.interfaces.menu import IContentManagementMenu, IPropertiesMenu
 from pyams_zmi.layer import IAdminLayer
-from z3c.form.interfaces import DISPLAY_MODE, IDataExtractedEvent
 
 # import packages
 from pyams_content.shared.common.zmi import WfSharedContentHeaderAdapter
@@ -93,6 +91,13 @@
 class SharedContentPropertiesAJAXEditForm(AJAXEditForm, SharedContentPropertiesEditForm):
     """Shared content properties edit form, JSON renderer"""
 
+    def get_ajax_output(self, changes):
+        wf_changes = changes.get(IBaseContent, ())
+        if 'title' in wf_changes:
+            return {'status': 'reload'}
+        else:
+            return super(SharedContentPropertiesAJAXEditForm, self).get_ajax_output(changes)
+
 
 @adapter_config(context=(IWfSharedContent, IAdminLayer, SharedContentPropertiesEditForm), provides=IPageHeader)
 class SharedContentPropertiesHeaderAdapter(WfSharedContentHeaderAdapter):
@@ -113,18 +118,11 @@
     fields = field.Fields(IWorkflowPublicationInfo).select('publication_effective_date', 'push_end_date',
                                                            'publication_expiration_date', 'displayed_publication_date')
 
-    def check_mode(self):
-        workflow = IWorkflow(self.context)
-        status = IWorkflowState(self.context)
-        if status.state not in workflow.update_states:
-            self.mode = DISPLAY_MODE
-        else:
-            super(SharedContentPublicationPropertiesEditForm, self).check_mode()
+    weight = 20
 
-
-@subscriber(IDataExtractedEvent, form_selector=SharedContentPublicationPropertiesEditForm)
-def handle_publication_properties_extraction(event):
-    """Handle publication form data extraction"""
-    data = event.data
-    if data.get('publication_expiration_date') and not data.get('push_end_date'):
-        data['push_end_date'] = data['publication_expiration_date']
+    def get_ajax_output(self, changes):
+        wf_changes = changes.get(IWorkflowPublicationInfo, ())
+        if ('publication_effective_date' in wf_changes) or ('displayed_publication_date' in wf_changes):
+            return {'status': 'reload'}
+        else:
+            return super(SharedContentPublicationPropertiesEditForm, self).get_ajax_output(changes)