From 01e4bf931670e6ead77cacfc70ca89735e9d82fd Mon Sep 17 00:00:00 2001
From: Gabriel Monnerat <gabriel@tiolive.com>
Date: Tue, 30 Apr 2013 13:01:36 +0200
Subject: [PATCH] Fix the base_category field on Campaign_viewEventPath to set
 the relation correctly and refactor
 Ticket_countDefaultEventPathDestinationList and
 Ticket_createEventFromDefaultEventPath to not display exception when the
 Domain is not set

---
 ...y_default_event_path_destination_title.xml |  2 +-
 .../my_default_event_path_source_title.xml    |  5 +++++
 ...t_countDefaultEventPathDestinationList.xml |  3 +++
 ...Ticket_createEventFromDefaultEventPath.xml | 19 +++++++++++--------
 bt5/erp5_crm/bt/revision                      |  2 +-
 5 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_destination_title.xml b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_destination_title.xml
index 52be6b82aa..7c013204e3 100644
--- a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_destination_title.xml
+++ b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_destination_title.xml
@@ -79,7 +79,7 @@
               <dictionary>
                 <item>
                     <key> <string>base_category</string> </key>
-                    <value> <string>destination</string> </value>
+                    <value> <string>default_event_path_destination</string> </value>
                 </item>
                 <item>
                     <key> <string>field_id</string> </key>
diff --git a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_source_title.xml b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_source_title.xml
index d35b145087..fce368f622 100644
--- a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_source_title.xml
+++ b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Campaign_viewEventPath/my_default_event_path_source_title.xml
@@ -10,6 +10,7 @@
             <key> <string>delegated_list</string> </key>
             <value>
               <list>
+                <string>base_category</string>
                 <string>editable</string>
               </list>
             </value>
@@ -71,6 +72,10 @@
             <key> <string>values</string> </key>
             <value>
               <dictionary>
+                <item>
+                    <key> <string>base_category</string> </key>
+                    <value> <string>default_event_path_source</string> </value>
+                </item>
                 <item>
                     <key> <string>editable</string> </key>
                     <value> <int>1</int> </value>
diff --git a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_countDefaultEventPathDestinationList.xml b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_countDefaultEventPathDestinationList.xml
index dc39a1916e..442d020b99 100644
--- a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_countDefaultEventPathDestinationList.xml
+++ b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_countDefaultEventPathDestinationList.xml
@@ -52,6 +52,9 @@
             <key> <string>_body</string> </key>
             <value> <string>portal_catalog = context.getPortalObject().portal_catalog\n
 domain = context.getDefaultEventPathDestinationValue()\n
+if domain is None:\n
+  return [[0]]\n
+\n
 return portal_catalog.countResults(\n
   selection_domain={domain.getParentId(): (\'portal_domains\', domain.getRelativeUrl(),)})\n
 </string> </value>
diff --git a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_createEventFromDefaultEventPath.xml b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_createEventFromDefaultEventPath.xml
index eb85575a33..d75b4ccfbd 100644
--- a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_createEventFromDefaultEventPath.xml
+++ b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Ticket_createEventFromDefaultEventPath.xml
@@ -52,16 +52,19 @@
             <key> <string>_body</string> </key>
             <value> <string>portal = context.getPortalObject()\n
 domain = context.getDefaultEventPathDestinationValue()\n
-event_path = context.getDefaultEventPathValue(portal_type="Event Path")\n
 \n
-method_kw = {\'event_path\': event_path.getRelativeUrl(),\n
- \'keep_draft\': keep_draft}\n
-portal.portal_catalog.searchAndActivate("Entity_createEventFromDefaultEventPath",\n
-  selection_domain={domain.getParentId(): (\'portal_domains\', domain.getRelativeUrl())},\n
-  method_kw=method_kw)\n
+if domain is None:\n
+  message = \'Recipients must be defined\'\n
+else:\n
+  event_path = context.getDefaultEventPathValue(portal_type="Event Path")\n
+  method_kw = {\'event_path\': event_path.getRelativeUrl(),\n
+   \'keep_draft\': keep_draft}\n
+  portal.portal_catalog.searchAndActivate("Entity_createEventFromDefaultEventPath",\n
+    selection_domain={domain.getParentId(): (\'portal_domains\', domain.getRelativeUrl())},\n
+    method_kw=method_kw)\n
+  message = \'Events are being created in background\'\n
 \n
-return context.Base_redirect(\n
-  keep_items={\'portal_status_message\': context.Base_translateString(\'Events are being created in background\')})\n
+return context.Base_redirect(keep_items={\'portal_status_message\': context.Base_translateString(message)})\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_crm/bt/revision b/bt5/erp5_crm/bt/revision
index e78e423d29..b0c703c41a 100644
--- a/bt5/erp5_crm/bt/revision
+++ b/bt5/erp5_crm/bt/revision
@@ -1 +1 @@
-627
\ No newline at end of file
+628
\ No newline at end of file
-- 
2.30.9