Commit 206d56ce authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add 'Export' functionality.

parent c9ef076d
......@@ -37,11 +37,18 @@ app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
def front_page():
return redirect(url_for('static', filename='index.html'))
@app.route("/postJSONData", methods=["POST", "OPTIONS"])
def postJSONData():
"""Returns posted JSON data as it is for Export button"""
data = json.loads(request.form.get('data'))
response = jsonify(data)
response.headers['Content-Disposition'] = 'attachment; filename=dream.json'
return response
@app.route("/postJSONFile", methods=["POST", "OPTIONS"])
def postJSONFile():
"""Returns posted JSON file as it is for Import button"""
data = json.load(request.files['file'])
app.logger.debug("postJSONFile:%r" % data)
return jsonify(data)
@app.route("/positionGraph", methods=["POST", "OPTIONS"])
......
......@@ -27,6 +27,7 @@
<a id="zoom_in">Zoom +</a>
<a id="zoom_out">Zoom -</a>
<a id="export">Export</a>
<form id="export_form" style="display:none" method="post" action="/postJSONData"><textarea id="export_json" name="data"></textarea></form>
<a id="import">Import</a>
<form id="import_form" style="display:none"><input id="import_file" name="file" type="file"></input></form>
</div>
......
......@@ -442,7 +442,9 @@
// Enable "Export" button
$("#export").button().click(
function (e) {
alert('not yet implemented');
$('#export_json').val(JSON.stringify(dream_instance.getData()));
$('#export_form').submit();
return false;
});
// Enable "Import" button
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment