From e975c72382d0d439417d15b1a05c19184b63a1f2 Mon Sep 17 00:00:00 2001
From: Rafael Monnerat <rafael@nexedi.com>
Date: Tue, 7 Feb 2012 11:41:43 -0200
Subject: [PATCH] Accept url for Slide image

This changes permit use URL instead local images all the time.
---
 .../TestPageModule_createChapter.xml          |  20 +++-
 .../TestPageModule_finishCreation.xml         |  46 +++-----
 ...stPageModule_viewChapterCreationWizard.xml |   1 +
 .../your_image_url.xml                        | 110 ++++++++++++++++++
 .../erp5_run_my_doc/TestPage_uploadImage.xml  |  18 ++-
 bt5/erp5_run_my_doc/bt/revision               |   2 +-
 6 files changed, 155 insertions(+), 42 deletions(-)
 create mode 100644 bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard/your_image_url.xml

diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_createChapter.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_createChapter.xml
index 891fa86690..4fb20108b4 100644
--- a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_createChapter.xml
+++ b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_createChapter.xml
@@ -69,16 +69,23 @@ else:\n
   listbox = []\n
   int_index = 1\n
 \n
-if slide_type == \'Screenshot\':\n
-  tested = True\n
+image_id = \'\'\n
 \n
 if slide_type in [\'Illustration\',\'Screenshot\']:\n
   test_page_path = session[\'test_page_path\']\n
   test_page = context.restrictedTraverse(test_page_path)\n
+\n
+if slide_type == \'Illustration\':\n
+  if image_url != "":\n
+    image_id = image_url\n
+  else:\n
+    image_id = test_page.TestPage_getNextImageID(chapter_title, slide_type)\n
+    image = test_page.TestPage_uploadImage(image_id, file, batch_mode = True)\n
+\n
+if slide_type == \'Screenshot\':\n
+  tested = True\n
   image_id = test_page.TestPage_getNextImageID(chapter_title, slide_type)\n
   image = test_page.TestPage_uploadImage(image_id, file, batch_mode = True)\n
-else:\n
-  image_id = \'\'\n
 \n
 listbox.append(newTempBase(context.getPortalObject(),\n
                    \'\',\n
@@ -94,14 +101,15 @@ listbox.append(newTempBase(context.getPortalObject(),\n
                  ))\n
 \n
 session[\'listbox\'] = listbox\n
-return context.Base_redirect(\'TestPageModule_viewChapterCreationWizard\', keep_items = dict(portal_status_message=portal_status_message))\n
+return context.Base_redirect(\'TestPageModule_viewChapterCreationWizard\', \n
+                             keep_items = dict(portal_status_message=portal_status_message))\n
 
 
 ]]></string> </value>
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>chapter_title, slide_type, file, text_content, slide_content, tested, **kw</string> </value>
+            <value> <string>chapter_title, slide_type, image_url, file, text_content, slide_content, tested, **kw</string> </value>
         </item>
         <item>
             <key> <string>id</string> </key>
diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_finishCreation.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_finishCreation.xml
index 11a33ba8b0..09eaefaacd 100644
--- a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_finishCreation.xml
+++ b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_finishCreation.xml
@@ -57,9 +57,9 @@
 """\n
 \n
 from Products.ERP5Type.Document import newTempBase\n
-\n
 # Add the last chapter to the listbox\n
-context.TestPageModule_createChapter(chapter_title, slide_type, file, text_content, slide_content, tested, **kw)\n
+context.TestPageModule_createChapter(chapter_title, slide_type, image_url, \n
+                                     file, text_content, slide_content, tested, **kw)\n
 \n
 translateString = context.Base_translateString\n
 portal_status_message = ""\n
@@ -72,17 +72,7 @@ author = session[\'author\']\n
 author_mail = session[\'author_mail\']\n
 \n
 # Headers and first chapter/slide\n
-text_content = """<!DOCTYPE html>\n
-<html>\n
-  <head>\n
-<base href="" />\n
-    <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n
-    <link href="http://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">\n
-    <meta charset="utf-8">\n
-    <title>""" + title + """</title>\n
-  </head>\n
-  <body>\n
-<section class="master">\n
+text_content = """<section class="master">\n
   <h1>""" + title + """</h1>\n
   """ + listbox[0].slide_content\n
 \n
@@ -128,20 +118,19 @@ for chapter in listbox[1:]:\n
 \n
   # let\'s add a template test to this chapter\n
   if chapter.tested:\n
-    text_content += """\n
-  <test>\n
-    <table class="test" cellpadding="1" cellspacing="1" border="1" style="display:none;">"""\n
+    text_content +="""\n
+  <test>"""\n
     if first:\n
-      text_content += """\n
-      <thead>\n
-        <tr><th rowspan="1" colspan="3">""" + session[\'title\'] + """</th></tr>\n
-      </thead>"""\n
+      text_content +="""\n
+    <span metal:use-macro="container/ERP5RunMyDocs_initTest/macros/init_test_environment" style="display:none;"> init</span>"""\n
       first = False\n
+\n
+    text_content +="""\n
+    <table class="test" cellpadding="1" cellspacing="1" border="1" style="display:none;">\n
+      <tbody>"""\n
+\n
+\n
     text_content += """\n
-      <tbody>\n
-        <tr>\n
-          <td colspan=3 >&lt;span metal:use-macro="container/ERP5RunMyDocs_initTest/macros/init_test_environment" style="display:none;"&gt;init&lt;/span&gt;</td>\n
-        </tr>\n
         <tr>\n
 \t  <td>selectAndWait</td>\n
 \t  <td>name=select_module</td>\n
@@ -167,20 +156,17 @@ for chapter in listbox[1:]:\n
 </section>\n
 """\n
 \n
-text_content +="""\n
-  </body>\n
-</html>"""\n
-\n
 test_page.setTextContent(text_content)\n
 \n
-return test_page.Base_redirect(\'view\', keep_items = dict(portal_status_message=portal_status_message))\n
+return test_page.Base_redirect(\'view\', \n
+                               keep_items = dict(portal_status_message=portal_status_message))\n
 
 
 ]]></string> </value>
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>chapter_title, slide_type, file, text_content, slide_content, tested, **kw</string> </value>
+            <value> <string>chapter_title, slide_type, image_url, file, text_content, slide_content, tested, **kw</string> </value>
         </item>
         <item>
             <key> <string>id</string> </key>
diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard.xml
index 5f0b3aa981..f3d7521c96 100644
--- a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard.xml
+++ b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard.xml
@@ -87,6 +87,7 @@
                         <string>your_title</string>
                         <string>your_chapter_title</string>
                         <string>your_slide_type</string>
+                        <string>your_image_url</string>
                         <string>your_file</string>
                         <string>your_slide_content</string>
                         <string>your_text_content</string>
diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard/your_image_url.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard/your_image_url.xml
new file mode 100644
index 0000000000..94978f51b9
--- /dev/null
+++ b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPageModule_viewChapterCreationWizard/your_image_url.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>delegated_list</string> </key>
+            <value>
+              <list>
+                <string>description</string>
+                <string>display_width</string>
+                <string>title</string>
+              </list>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>your_image_url</string> </value>
+        </item>
+        <item>
+            <key> <string>message_values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>external_validator_failed</string> </key>
+                    <value> <string>The input failed the external validator.</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>overrides</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>field_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>form_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>target</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>tales</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>field_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>form_id</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>target</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string>The URL to the image, you can use relative urls or image reference.</string> </value>
+                </item>
+                <item>
+                    <key> <string>display_width</string> </key>
+                    <value> <int>90</int> </value>
+                </item>
+                <item>
+                    <key> <string>field_id</string> </key>
+                    <value> <string>my_view_mode_title</string> </value>
+                </item>
+                <item>
+                    <key> <string>form_id</string> </key>
+                    <value> <string>Base_viewFieldLibrary</string> </value>
+                </item>
+                <item>
+                    <key> <string>target</string> </key>
+                    <value> <string>Click to edit the target</string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string>Image URL</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_uploadImage.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_uploadImage.xml
index b2eab134b1..cb1a410592 100644
--- a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_uploadImage.xml
+++ b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_uploadImage.xml
@@ -54,7 +54,13 @@
   Create an image object and upload the image if necessary\n
 """\n
 \n
+translateString = context.Base_translateString\n
+\n
 msg = \'Slide created.\'\n
+\n
+if edit_mode == 1:\n
+  msg = \'Slide updated.\'\n
+\n
 def createImage(image_id):\n
   return context.newContent(portal_type = \'Embedded File\',\n
                                 title = image_id,\n
@@ -80,16 +86,18 @@ if slide_type in [\'Screenshot\', \'Illustration\']:\n
     msg += \' Image \' + image_id + \' created.\'\n
 \n
   if not(file is None or not file):\n
-    image.edit(file=file, data=file.read(), filename=file.filename)\n
+    image.edit(file=file, \n
+               data=file.read(), \n
+               filename=file.filename)\n
+\n
     msg += \' Image uploaded.\'\n
 \n
   if batch_mode:\n
     return image\n
 \n
-translateString = context.Base_translateString\n
-portal_status_message = translateString(msg)\n
-context.Base_redirect(\'TestPage_viewSlideCreator\', \n
-                      keep_items = dict(portal_status_message=portal_status_message))\n
+form_id = context.REQUEST.get(\'dialog_id\', None)\n
+context.Base_redirect(form_id,\n
+                      keep_items = dict(portal_status_message=translateString(msg)))\n
 </string> </value>
         </item>
         <item>
diff --git a/bt5/erp5_run_my_doc/bt/revision b/bt5/erp5_run_my_doc/bt/revision
index 597975b413..dce6588ca1 100644
--- a/bt5/erp5_run_my_doc/bt/revision
+++ b/bt5/erp5_run_my_doc/bt/revision
@@ -1 +1 @@
-35
\ No newline at end of file
+36
\ No newline at end of file
-- 
2.30.9