From f198475921c62b9fc7f975f8551d592deedc9456 Mon Sep 17 00:00:00 2001
From: Rafael Monnerat <rafael@nexedi.com>
Date: Tue, 22 Jul 2008 16:31:12 +0000
Subject: [PATCH] Unify clone behaviour between usual clone and clone in
 erp5_web.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22619 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../Base_createCloneDocument.xml              | 47 ++++++++++++++++---
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_createCloneDocument.xml b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_createCloneDocument.xml
index 020a90f379..2f25af201a 100644
--- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_createCloneDocument.xml
+++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_createCloneDocument.xml
@@ -71,12 +71,9 @@
 \n
   Pretty messages are provided to the user.\n
 """\n
-\n
 translateString =  context.Base_translateString\n
 form_data = context.REQUEST.form\n
 \n
-# First make sure that no document already exists with the\n
-# same portal_type, reference, language and version.\n
 if clone:\n
   portal_type = context.getPortalType()\n
 else:\n
@@ -94,6 +91,15 @@ if portal_type not in allowed_type_list:\n
 # prepare query params\n
 kw = {\'portal_type\' : translateString(portal_type)}\n
 \n
+if web_mode:\n
+  script = getattr(context, "Base_checkCloneConsistency", None)\n
+  if script is not None:\n
+    msg = script(**form_data)\n
+    if msg is not None:\n
+      return context.Base_redirect(form_id, \n
+                          editable_mode=editable_mode,\n
+                          keep_items={\'portal_status_message\': msg})\n
+\n
 # Standard cloning method\n
 if clone:\n
   # We copy contents in place if possible\n
@@ -106,10 +112,25 @@ if clone:\n
   new_object = directory[paste_result[0][\'new_id\']]\n
   message_kind = \'Clone\'\n
 \n
+if web_mode:\n
+  # Edit the objects with some properties\n
+  # Define a list of field name to take into account in the cloning process\n
+  ACCEPTABLE_FORM_ID_LIST = [ \'clone_reference\' , \'clone_language\'\n
+                             , \'clone_version\' , \'clone_revision\'\n
+                             , \'clone_title\' , \'clone_short_title\' ] \n
+\n
+  # Set properties to the new object\n
+  edit_kw = {}\n
+  property_id_list = new_object.propertyIds()\n
+  for (key, val) in form_data.items():\n
+    if key in ACCEPTABLE_FORM_ID_LIST and key[len(\'clone_\'):] in property_id_list:\n
+      edit_kw[key[len(\'clone_\'):]] = val\n
+  new_object.edit(**edit_kw)\n
+\n
 if batch_mode:\n
   return new_object\n
 else:\n
-  if not editable_mode: \n
+  if web_mode and not editable_mode: \n
     form_id = \'view\'\n
   msg = translateString("Created %s ${portal_type}." % message_kind, mapping = kw)\n
   return new_object.Base_redirect(form_id, \n
@@ -131,7 +152,7 @@ else:\n
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>clone=1, form_id, editable_mode=0, batch_mode=0</string> </value>
+            <value> <string>clone=1, form_id, web_mode=0, editable_mode=0, batch_mode=0</string> </value>
         </item>
         <item>
             <key> <string>_proxy_roles</string> </key>
@@ -157,7 +178,7 @@ else:\n
                   <dictionary>
                     <item>
                         <key> <string>co_argcount</string> </key>
-                        <value> <int>4</int> </value>
+                        <value> <int>5</int> </value>
                     </item>
                     <item>
                         <key> <string>co_varnames</string> </key>
@@ -165,6 +186,7 @@ else:\n
                           <tuple>
                             <string>clone</string>
                             <string>form_id</string>
+                            <string>web_mode</string>
                             <string>editable_mode</string>
                             <string>batch_mode</string>
                             <string>_getattr_</string>
@@ -178,13 +200,23 @@ else:\n
                             <string>None</string>
                             <string>kw</string>
                             <string>getattr</string>
+                            <string>script</string>
+                            <string>_apply_</string>
+                            <string>msg</string>
                             <string>directory</string>
                             <string>original_id</string>
                             <string>clipboard</string>
                             <string>paste_result</string>
                             <string>new_object</string>
                             <string>message_kind</string>
-                            <string>msg</string>
+                            <string>ACCEPTABLE_FORM_ID_LIST</string>
+                            <string>edit_kw</string>
+                            <string>property_id_list</string>
+                            <string>_getiter_</string>
+                            <string>key</string>
+                            <string>val</string>
+                            <string>len</string>
+                            <string>_write_</string>
                           </tuple>
                         </value>
                     </item>
@@ -201,6 +233,7 @@ else:\n
                 <none/>
                 <int>0</int>
                 <int>0</int>
+                <int>0</int>
               </tuple>
             </value>
         </item>
-- 
2.30.9