From f5e12409a3ee22f770144f2ab8fa95fa7957b3ea Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@nexedi.com>
Date: Fri, 15 Jan 2016 10:02:22 -0500
Subject: [PATCH] erp5_svg_editor: lint svg-editor.erp5.js + enable async ajax

---
 .../erp5_svg_editor/svg-editor.erp5.js.xml    | 43 +++++++++++--------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/bt5/erp5_svg_editor/SkinTemplateItem/portal_skins/erp5_svg_editor/svg-editor.erp5.js.xml b/bt5/erp5_svg_editor/SkinTemplateItem/portal_skins/erp5_svg_editor/svg-editor.erp5.js.xml
index 2717a4bc7a..6b6ddaec31 100644
--- a/bt5/erp5_svg_editor/SkinTemplateItem/portal_skins/erp5_svg_editor/svg-editor.erp5.js.xml
+++ b/bt5/erp5_svg_editor/SkinTemplateItem/portal_skins/erp5_svg_editor/svg-editor.erp5.js.xml
@@ -38,30 +38,37 @@
         </item>
         <item>
             <key> <string>_text</string> </key>
-            <value> <unicode>window.onload = function() {\n
-  var svg_canvas = window.frames["svgframe"].svgCanvas;\n
-  var text_content = $.ajax({\n
-                             url: "Base_getSVGTextContent",\n
-                             async: false\n
-                            }).responseText;\n
-  text_content != "" ? svg_canvas.setSvgString(text_content) : null;\n
-}\n
+            <value> <unicode>window.onload = function () {\n
+  $.ajax({\n
+    url: "Base_getSVGTextContent",\n
+    async: true,\n
+    success: function (text_content) {\n
+      var svg_canvas, frame = window.frames.svgframe;\n
+      if (text_content !== "") {\n
+        svg_canvas = frame.svgCanvas;\n
+        svg_canvas.ready(function () {\n
+          svg_canvas.setSvgString(text_content);\n
+        });\n
+      }\n
+    }\n
+  });\n
+};\n
 \n
-$(document).ready(function(){\n
-  $("button.save").click(function(event){\n
+$(document).ready(function () {\n
+  $("button.save").click(function (event) {\n
     event.preventDefault();\n
-    var svg_canvas = window.frames["svgframe"].svgCanvas;\n
+    var svg_canvas = window.frames.svgframe.svgCanvas;\n
     $.ajax({\n
-       type: "POST",\n
-       url: "Base_setSVGTextContent",\n
-       data: "text=" + encodeURIComponent(svg_canvas.getSvgString()),\n
-       success: function(){\n
-         window.location.reload();\n
-       }\n
+      type: "POST",\n
+      url: "Base_setSVGTextContent",\n
+      data: "text=" + encodeURIComponent(svg_canvas.getSvgString()),\n
+      success: function () {\n
+        window.location.reload();\n
+      }\n
     });\n
   });\n
   $("iframe#svgframe").css("border", "0px");\n
-})</unicode> </value>
+});</unicode> </value>
         </item>
         <item>
             <key> <string>content_type</string> </key>
-- 
2.30.9