changeset 391:6747c16172a2

action SVG-editor: save on pagename and target. uri parameter target added. default is example.svg.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 23 Aug 2009 20:23:48 +0200
parents 8b7ec5e404c2
children d858f942a1f6
files data/plugin/action/SVG-editor.py htdocs/svg-edit/editor/svg-editor.js
diffstat 2 files changed, 37 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/SVG-editor.py	Sun Aug 23 12:04:28 2009 +0200
+++ b/data/plugin/action/SVG-editor.py	Sun Aug 23 20:23:48 2009 +0200
@@ -1,14 +1,34 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin - mathtran
+    MoinMoin - SVG-editor
 
-    This macro is used to call the mathtran parser,
+    This action is used to call svg-edit, (http://code.google.com/p/svg-edit/) 
     it is just a thin wrapper around it.
+    svg-edit pre alpha is called (this is currently a mockup for an implementation in moin-2.0)
 
-    @copyright: 2008-2009 by MoinMoin:ReimarBauer
+    @copyright: 2009 by MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
+import base64
+from MoinMoin import config
+from MoinMoin.action import AttachFile
+
+
 def execute(pagename, request):
+    target = request.values.get('target', 'example.svg')
+    do = request.values.get('do', '')
+    if do == 'save':
+        filecontent = request.values.get('svg_data', '')
+        target = request.values.get('target', 'example.svg')
+        if filecontent:
+            # get directory, and possibly create it
+            attach_dir = AttachFile.getAttachDir(request, pagename, create=1)
+            # save file
+            fpath = AttachFile.getFilename(request, pagename, target).encode(config.charset)
+            file(fpath, 'w').write(filecontent.decode('base_64'))
+            return None, None
+
+            
     url = request.getQualifiedURL()
     htdocs = "%s%s" % (request.cfg.url_prefix_static, '/svg-edit/editor')
     
@@ -277,9 +297,10 @@
 $(document).ready(svg_edit_setup);
 </script>
 
-""" % {"htdocs": htdocs}
+""" % {"htdocs": htdocs,
+       }
 
-    title = "SVG Editor"
+    title = "%s:%s" % (pagename, target)
     request.theme.send_title(title, page=request.page, pagename=pagename)
     request.write(request.formatter.startContent("content"))
     request.write(request.formatter.rawHTML(meta))
--- a/htdocs/svg-edit/editor/svg-editor.js	Sun Aug 23 12:04:28 2009 +0200
+++ b/htdocs/svg-edit/editor/svg-editor.js	Sun Aug 23 20:23:48 2009 +0200
@@ -61,8 +61,17 @@
 		}
 		else
 		{
-			window.open("data:image/svg+xml;base64," + Utils.encode64(svg));
-		}
+          var titlename = window.content.parent.document.title.split('-')[0];
+          titlename = titlename.replace(' ', '');
+          var svg_data = Utils.encode64(svg);
+          var pagename = titlename.split(':')[0];
+          var svg_target = titlename.split(':')[1];
+          $.post(
+                pagename,
+                {'action': "SVG-editor", 'do': "save", 'target': svg_target, 'svg_data': svg_data}
+           );
+        }
+		
 	};
 
 	// called when we've selected a different element