1 | /*
|
---|
2 | * ext-server_moinsave.js
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2
|
---|
5 | *
|
---|
6 | * Copyright(c) 2010 Alexis Deveria
|
---|
7 | * 2011 MoinMoin:ReimarBauer
|
---|
8 | * adopted for moinmoins item storage. it sends in one post png and svg data
|
---|
9 | * (I agree to dual license my work to additional GPLv2 or later)
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 | methodDraw.addExtension("server_opensave", {
|
---|
14 | callback: function() {
|
---|
15 |
|
---|
16 | var save_svg_action = '/+modify';
|
---|
17 |
|
---|
18 | // Create upload target (hidden iframe)
|
---|
19 | var target = $('<iframe name="output_frame" src="#"/>').hide().appendTo('body');
|
---|
20 |
|
---|
21 | methodDraw.setCustomHandlers({
|
---|
22 | save: function(win, data) {
|
---|
23 | var svg = "<?xml version=\"1.0\"?>\n" + data;
|
---|
24 | var qstr = $.param.querystring();
|
---|
25 | var name = qstr.substr(9).split('/+get/')[1];
|
---|
26 | var svg_data = svgedit.utilities.encode64(svg);
|
---|
27 | if(!$('#export_canvas').length) {
|
---|
28 | $('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');
|
---|
29 | }
|
---|
30 | var c = $('#export_canvas')[0];
|
---|
31 | c.width = svgCanvas.contentW;
|
---|
32 | c.height = svgCanvas.contentH;
|
---|
33 | $.getScript('canvg/canvg.js', function() {
|
---|
34 | canvg(c, svg, {renderCallback: function() {
|
---|
35 | var datauri = c.toDataURL('image/png');
|
---|
36 | var uiStrings = methodDraw.uiStrings;
|
---|
37 | var png_data = svgedit.utilities.encode64(datauri);
|
---|
38 | var form = $('<form>').attr({
|
---|
39 | method: 'post',
|
---|
40 | action: save_svg_action + '/' + name,
|
---|
41 | target: 'output_frame'
|
---|
42 | }) .append('<input type="hidden" name="png_data" value="' + png_data + '">')
|
---|
43 | .append('<input type="hidden" name="filepath" value="' + svg_data + '">')
|
---|
44 | .append('<input type="hidden" name="filename" value="' + 'drawing.svg">')
|
---|
45 | .append('<input type="hidden" name="contenttype" value="application/x-svgdraw">')
|
---|
46 | .appendTo('body')
|
---|
47 | .submit().remove();
|
---|
48 | }})});
|
---|
49 | alert("Saved! Return to Item View!");
|
---|
50 | top.window.location = '/'+name;
|
---|
51 | },
|
---|
52 | });
|
---|
53 |
|
---|
54 | }
|
---|
55 | });
|
---|
56 |
|
---|